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

Re: determine node position

Subject: Re: determine node position
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 10 Apr 2001 00:52:08 +0100
find node position
Hi Kristof,

> with the value of an attribute i'm trying to determine the node
> position number of the one element that contains that specific
> attribute value.

The position() of a node gives you the position of the node in the
current node list - the nodes that are currently being processed in
the order that they're being processed in. So one method is to make
the current node list be the list of nodes that you might be
interested in, and then test each of the nodes as they're processed to
see if they're the single node that you are interested in.  That
node's position() is the number that you're after.

In other words, do an xsl:for-each over each of the item elements.  If
the ID is the one that you want, then output the value of the
position() of that item element:

  <xsl:for-each select="item">
     <xsl:if test="@ID = 'thursday'">
        <xsl:value-of select="position()" />
     </xsl:if>
  </xsl:for-each>

That's not a particularly good way of doing it, though, because you
have to go over every single item element each time.  Better is to
find the node that you want, and then count how many preceding
siblings it has:

  <xsl:value-of
     select="count(item[@ID = 'thursday']/preceding-sibling::item)" />

Depending on how many elements you have, you may find it more
efficient to put attributes on the source to indicate the position of
each element. If there are lots of item elements, then collecting up
all the preceding siblings and counting them might take a bit of time.

I hope that helps,

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.