When we loop on a set of nodes, the current context keeps changing and the position returns the number of the current context node in the loop. Please look at the following example - ================================================ XML file- <source> <child>one</child> <child>Two</child> <child>Three</child> </source> ================================================ stylesheet - <xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <!-- These are comments --> <xsl:template match="/source"> <xsl:apply-templates select="child"/> </xsl:template> <xsl:template match="child"> <!-- position of the current context node --> <xsl:value-of select="position()"/> <xsl:text>.</xsl:text> <!-- value of the current context node --> <xsl:value-of select="."/> <!-- This stuff is just for creating newline --> <xsl:text> </xsl:text> </xsl:template> </xsl:stylesheet> ================================================ Output - <?xml version="1.0" encoding="UTF-8"?> 1.one 2.Two 3.Three The numbers 1,2,3 above are generated by the position() function as the current context node kept changing by the call <xsl:apply-templates...> Hope that this is clear.
Thanks Jaydev, Now iam clear. I have to ask u for one more clarification. U guys discussed *[@*] in this post b4,but i couldnt understand the conclusion.I lost somewhere. Could u plz explain me with an example like position(). Another request for everyone in this post is : whenever u guys r discussing something plz post a conclusion at the end of that post.So that freshers like me can understand well. After reading all those debates i actually forget what i read so far. I would really appreciate ur reply. Shakthy
We would definitely post a conclusion if we endup with one BTW, in the *[@*] discussion, if i remember it correctly, i was wrong. You can see guys giving the explanation of stuff there.
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
Gift giving made easy with the permaculture playing cards