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

Re: counting the number of time i call a template

Subject: Re: counting the number of time i call a template
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 19 Jan 2001 11:40:18 GMT
count number templates
> The only way i found is
> to call a template, and (try to) count the number of
> time it's called.

well you can do that by passing the count as a parameter, but you also
need to make sure that your templates are called in the correct order.

For example suppose you have

<x>
  <y/>
  <y/>
  <y/>
  <y/>
  <y/>
  <y/>
</x>

and you wanted to get 1, 2, 3, 4, 5, 6 from the template for y
it wouldn't work to go

<xsl:template match="x">
 <xsl:apply-templates/>
</xsl:template>

</xsl:template match="y">
  some code to show how many times this template has been called.
</xsl:template>

as that could generate the numbers 1 to 6 in any order: you can't rely
on the system to apply the templates to the y elements in the natural
order.

But you can force the order by going


<xsl:template match="x">
 <xsl:apply-templates select="y[1]"/>
</xsl:template>


</xsl:template match="y">
 <xsl:param name="ycount" select="1"/>
 y: <xsl:value-of select="$ycount"/>
 <xsl:apply-templates select="following-sibling:y[1]">
  <xsl:with-param name="ycount" select="$ycount+1"/>
 </xsl:apply-templates/>
 </xsl:template>


But I'd still expect that using xsl:number would be easier than doing
the above and making sure the ycount parameter was appropriately passed
to all templates.

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp

 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.