[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Finding the following sibling of same type

Subject: Re: Finding the following sibling of same type
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sun, 29 Aug 2004 21:47:20 +0100
same sibling xml
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/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.