RE: [xsl] Number of times apply-templates gets executed.

Subject: RE: [xsl] Number of times apply-templates gets executed.
From: "Corey Snow" <Corey.Snow@xxxxxxxxxxxxxx>
Date: Tue, 7 Jan 2003 11:25:36 -0600

> -----Original Message-----
> From: Patel, Viral [mailto:viral.patel@xxxxxxxxxxxxxxxxxxxx] 
> Sent: Tuesday, January 07, 2003 7:55 AM
> To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'
> Subject: [xsl] Number of times apply-templates gets executed.
> 
> 
> Hi,
> 
> I am new to XSL and I have several questions - some of them 
> might be really easy ones but I just want to confirm. 1. I 
> believe its not possible to change the value of 
> <xsl:variable> once its set - correct?

Yes, this is true- within the scope of the variable. Every time an
<xsl:template/> that contains an <xsl:variable/> element is executed,
that <xsl:variable/> element will be reinitialized. However, XSLT can
never change the value of the variable once it is created; it can only
let it go out of scope and restart.

> 
> 2. Is there a way to figure out how many times a template was 
> applied when using <xsl:apply-templates>?
> 

Not in the sense of incrementing a variable or passing a parameter back
to the caller; these things would introduce side effects, which is not
allowed in XSL. You could output a node for every time the template is
executed, but that may not be what you're looking for.

> 3. Is there an easy to implement a counter or a boolean in 
> xsl? If yes then how? Implementing either one would be fine.
> 

I can't think of any convenient ways, except to point out that the
boolean() function and the idea of boolean values already exists in XSL.
So does the concept of a counter; see the position() and number()
functions. But if you're trying to keep a running total and use that in
other areas like a traditional variable in a functional language, I'm
not sure how you'd do it. Possibly someone who knows more than I do can
help there.

Regards,

Corey M. Snow, Delivery Consultant
Logical- http://www.us.logical.com
Phone: (360) 491-7774
Cell: (360) 481-2563
"We are the music makers, and we are the dreamers of dreams."

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread