• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Position() ?

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic