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

RE: getting position of tag

Subject: RE: getting position of tag
From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx>
Date: Wed, 15 Sep 2004 15:46:23 +0100
xsl tag position
> Hi.
>
> I have this problem:
>
> XML:
> <columns>
> 	<column>
> 		<source>A</source>
> 	</column>
> 	<column>
> 		<source>B</source>
> 	</column>
> </xolumns>
>
> I want to get position() of tag column, where source='B'.
>
> I have tried
> xsl:value-of select="/columns/column[source='B']/position()"
> but it is bad.

The position() function will give you the position of the node within
the current selection of nodes that are being iterated over.  So to use
the position function you must first select the nodes, then get the
position() of the node that matches your critera:

  <xsl:for-each select="/columns/column">
    <xsl:if test="source = 'B'">
      <xsl:value-of select="position()"/>
    </xsl:if>
  </xsl:for-each>

Alternatively, if you haven't selected any nodes, you will need to use
the count() function to count how many preceding <column> elements there
are from the current node:

  <xsl:template match="column">
    <xsl:if test="source = 'B'">
      <xsl:value-of select="count(preceding-sibling::column|.)" />
    </xsl:if>
  </xsl:template>

cheers
andrew

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.