[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

counting the number of time i call a template

Subject: counting the number of time i call a template
From: Floch "Jean-Sébastien" <jsfloch@xxxxxxxxx>
Date: Fri, 19 Jan 2001 01:49:25 -0800 (PST)
jean 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.