• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Position() ?

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
Can anyone explain what is the result of
position()?
Thanks in advance
Shakthy
 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jaysakthy Muthuvelu
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic