Subject: RE: [xsl] getting position of tag From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx> Date: Wed, 15 Sep 2004 15:46:23 +0100 |
> 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] getting position of tag, Wendell Piez | Thread | [xsl] Accessing embedded XSL island, Maria Amuchastegui |
[xsl] Accessing embedded XSL island, Maria Amuchastegui | Date | [xsl] [ANN] Altsoft releases Xml2PD, Altsoft Xml2PDF |
Month |