• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

count of how many times a particular template is being called

 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I get a count of how many times a particular
template is being called?
Im thinking of something like -
<xsl:variable name="globalVar" select"1" />
<xsl:template match="Node1">
<xsl:for-each select="$Values">
<xsl:call-template name="T1"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="T1">
<xsl:if test="ValueIsValid">
<xsl:call-template name="T2"/>
</xsl:if>
</xsl:template>
<xsl:template match="T2">
Called for <xsl:value-of select="$globalVar" />
<!-- Increament the var??? -->
</xsl:template>
The final template creates the output.
I showed this for what I want. I know we cannot
reassign variables
in xsl. As I am iterating over $Values, that is a
variable, I am getting
undesired result by using xsl:number or position().
Can anyone give any hints?
Thanks
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tina, you can use position() function inside for-each element even if you iterate over a variable. This is probably the easiest way to do what you want. I do not think any trick with counting inside called template will work... Templates are functions, and functions in XSLT are free from side-effects, they do not keep state. You could accumulate this number in calling template and pass it as a parameter, using
<xsl:variable name="someVar" select="$someVar + 1"/>
trick, but here you aren't update a variable, you create a new one using old value. It won't work with if element, because of scope limitations.
To make position() function work looks more prominent.
 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic