[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Finding the following sibling of same type
Hi Kenneth, > Actually, the real problem is for me to write an XPath expression > that will select all children of "main" from the first "first" upto > (but exluding) the next "first". Hence my desire to locate the > position of the next "first". The easiest way to do this is to create a key that indexes all the non-<first> children of the <main> element by their nearest preceding <first> element: <xsl:key name="first-group" match="main/*[not(self::first)]" use="generate-id(preceding-sibling::first[1])" /> Then you can get all the elements that 'belong to' the first <first> element using: key('first-group', generate-id(/main/first[1])) I'm using generate-id() here, but your actual XML might have an id attribute or something similar that you could use to uniquely identify the <first> elements instead. If you're trying to transform into: <main> <first> <second> <third>...</third> </second> <second> <third>...</third> </second> </first> <first> <second>...</second> </first> </main> and you're using XSLT 2.0, then you want to use the <xsl:for-each-group> with group-starting-with. In XSLT 1.0 using keys like the one above is probably the simplest approach. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|