Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL position funktion

Status
Not open for further replies.

Kohnert

Programmer
Apr 8, 2004
2
DE
hi!
I m looking for a way to use position() in a way that it returns not only the context position of one node. I would like it to return the position of the whole dukument.
like, if I had:
<Test>
<one>
<name>name1</name>
<name>name2</name>
</one>
<two>
<name>name1</name>
</two>
</Test>

If I let my XSLT stylsheet procces it I get something like that. The number is the value the position funktion returns. the X field is how I would like it to be:

NAME Nr X
name1 1 1
name2 2 2
name1 1 3

currently I m doing it like this:
<xsl:value-of select=&quot;position()&quot;/>

but the idea behind it is to get a different color for each row.
Currently I m doing it like this:

<xsl:variable name=&quot;color&quot;>
<xsl:choose>
<xsl:when test=&quot;(position() mod 2 ) = 0&quot;>
<xsl:value-of select=&quot;$white&quot;/>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select=&quot;$red&quot;/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>

Do u know a correct way of doing this?
thx!!
 
If you're looking for position in realtion to all elements of the same name, all <name> in order, the select=&quot;//name&quot; and position() will give you what you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top