Subject: Re: [xsl] Select elements between others From: "George Cristian Bina" <george@xxxxxxx> Date: Tue, 20 Jan 2004 12:21:07 +0200 |
Something like below will do it. You can count the items following the current selected block and substract the items following the next block to determine how many items the current block should contain. Then just copy the corresponding number of items inside the current block. <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <data> <xsl:apply-templates/> </data> </xsl:template> <xsl:template match="block"> <block> <xsl:variable name="items" select="count(following-sibling::item) - count(following-sibling::block/following-sibling::item)"/> <xsl:copy-of select="following-sibling::item[position() <= $items]"/> </block> </xsl:template> </xsl:stylesheet> Best Regards, George ------------------------------------------------------------- George Cristian Bina mailto:george@xxxxxxxxxxxxx <oXygen/> XML Editor - http://www.oxygenxml.com/ ----- Original Message ----- From: "Joe Fawcett" <joefawcett@xxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Tuesday, January 20, 2004 11:28 AM Subject: [xsl] Select elements between others > I have received, what I consider to be, a badly designed xml file: > <data> > <block/> > <item>One</item> > <item>Two</item> > <block/> > <item>One</item> > <item>Two</item> > <item>Three</item> > <block/> > <item>One</item> > </data> > > I want to turn this into a more normal form to make it easier to manage: > > <data> > <block> > <item>One</item> > <item>Two</item> > </block> > <block> > <item>One</item> > <item>Two</item> > <item>Three</item> > </block> > <block> > <item>One</item> > </block> > </data> > > Thanks > > Joe > > _________________________________________________________________ > Sign-up for a FREE BT Broadband connection today! > http://www.msn.co.uk/specials/btbroadband > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Select elements between other, Joe Fawcett | Thread | RE: [xsl] Select elements between o, Michael Kay |
RE: [xsl] Get path of xsl template, Jarno . Elovirta | Date | RE: [xsl] Select elements between o, Joe Fawcett |
Month |