Position () function--return node position
Syntax: Position ()
Parameters: None
return value: Integer
Purpose: This function is used to return the position of the context node in the collection of nodes being processed.
The following sample program demonstrates the use of the position () function.
The XML source document is shown below.
[XHTML] View plain copy <?xml version= "1.0"?> <root> <e pos= "1" >001</e> <e pos= "2" >002</e> <e pos= "3" >003</e> <e pos= "4" >004</e> <e pos= "5" >005</e& Gt </root>
The XSLT document is shown below.
[XHTML] View plain copy <?xml version= ' 1.0 '?> <xsl:stylesheet ' version= ' 1.0 ' xmlns:xsl= ' http://www.w3.org/1999 /xsl/transform "> <xsl:template match="/"> <xsl:for-each select=" root/e "> section <xsl:value-of select= "position ()"/> e element: <xsl:value-of select= "." /> </xsl:for-each> </xsl:template> </xsl:stylesheet>
The output is shown below.
1th e element: 001
2nd e element: 002
3rd e element: 003
4th e element: 004
5th e element: 005