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

Re: Problem using preceding-sibling

Subject: Re: Problem using preceding-sibling
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 14 May 2002 16:15:57 +0100
preceding sibling position
Hi Faroukh,

> I try to get the immediate sibling by checking the position, however
> I get always the first node.
>
> <xsl:variable name="cpo" select="position()"/>
> <xsl:element name="Preceding_GID">
>   <xsl:value-of select="generate-id(preceding-sibling::node()[position()=
> $cpo - 1])"/>
> </xsl:element>

You're a bit confused about the interaction between axes and the
position() function. The position() function gives you the position of
the context node amongst the other nodes you're looking at. If you did:

  child::Level2[position() = 1]

or the equivalent:

  Level2[1]

then you'd get the first Level1 child of the context node. If you did:

  descendant::Level2[5]

then you'd get the fifth Level2 descendant of the context node. If you
did:

  following-sibling::Level2[2]

then you'd get the second following sibling of the context node.

Similarly, if you did:

  preceding-sibling::node()[1]

then you get the immediately preceding sibling of the node
(preceding-sibling is a reverse axis, which means that positional
predicates, like the one hear, count in reverse document order, so you
get the nearest sibling node).

What you need, then, is simply:

  <Preceding_GID>
    <xsl:value-of select="generate-id(preceding-sibling::node()[1])"/>
  </Preceding_GID>

Although you could use:

  <Preceding_GID>
    <xsl:value-of select="generate-id(../node()[position() = $cpo - 1])"/>
  </Preceding_GID>

if you really wanted (it's likely to be a lot less efficient).

Note that there's no need to use xsl:element to create your elements
if you know what their names are.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.