This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

counting the number of time i call a template


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 &lt; 2">
			i ve been hit <xsl:value-of select="$tabnum"/> time
		</xsl:if>
		<xsl:if test="$tabnum &gt; 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]