|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: getting position of tag
> 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
|
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
|

Cart








