Re: [xsl] counting the number of time i call a template

Subject: Re: [xsl] counting the number of time i call a template
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 19 Jan 2001 11:40:18 GMT
> 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


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:template match="y">
  some code to show how many times this template has been called.

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

But you can force the order by going

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

</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"/>

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.


This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit

 XSL-List info and archive:

Current Thread