This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
counting the number of time i call a template
- To: xsl-list at lists dot mulberrytech dot com
- Subject: [xsl] counting the number of time i call a template
- From: Floch "Jean-Sébastien" <jsfloch at yahoo dot com>
- Date: Fri, 19 Jan 2001 01:49:25 -0800 (PST)
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi all.
My problem is that we can't modify global variables in
xsl. But i need that functionality.
I have to count the number of time i call a template
Some of you will say "you can use count select="//elt"
in the root template", but in real life, my xml is not
as simple, and i can't predict the number of element
elt, and even where they are located in my tree.
And i need to count the number of time i use my
template because i want it to have different actions
for different values.
Thanks in advance,
Jean-Sebastien
--xml--
<?xml version="1.0" encoding="UTF-8"?>
<root>
<elt name="1111"/>
<elt name="2222"/>
<elt name="3333"/>
<elt name="4444"/>
<elt name="5555"/>
<elt name="6666"/>
<elt name="7777"/>
</root>
--/xml--
--xsl--
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:variable name="tabnum" select="'0'"/>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="root">
<xsl:apply-templates/>
</xsl:template>
<xsl:template name="mycounter">
<xsl:variable name="tabnum" select="$tabnum + 1"/>
<xsl:if test="$tabnum < 2">
i ve been hit <xsl:value-of select="$tabnum"/> time
</xsl:if>
<xsl:if test="$tabnum > 1">
i ve been hit <xsl:value-of select="$tabnum"/>
times
</xsl:if>
</xsl:template>
<xsl:template match="elt">
<msg><xsl:call-template name="mycounter"/></msg>
<name><xsl:value-of select="@name"/></name>
</xsl:template>
</xsl:stylesheet>--/xsl--
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list