[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
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|