[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: Re: [xsl] Number of times apply-templates gets executed.
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 07 Jan 2003 11:07:58 -0500

At 2003-01-07 09:54 -0600, Patel, Viral wrote:
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. Values are bound to variables and once bound cannot be changed within the scope of the variable.


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

By counting how many nodes in your selection are going to be triggering the use of the template.


For example, if you had:

<xsl:template match="para">...

... and you were in a chapter with para children and you planned in your chapter to do:

<xsl:apply-templates/>

Then the number of times the template would be called is:

<xsl:value-of select="count(para)"/>

3. Is there an easy to implement a counter or a boolean in xsl?

No ... thinking of counters is a programmer's approach to the problem. XSLT is functional and side effect free, so instead of the stylesheet implementing counters, the stylesheet asks the processor to do the counting.


If you cannot easily address the items being counted by an XPath expression to the count() function, then consider the use of <xsl:number> to identify and count nodes based on your identification criteria.

I hope this helps.

........................ Ken


-- Upcoming hands-on in-depth North America: February 3- 7,2003 XSLT/XPath and XSL-FO Europe: February 17-21,2003

G. Ken Holman                mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.         http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                      Definitive XSLT and XPath
ISBN 0-13-140374-5                              Definitive XSL-FO
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1              Practical Formatting Using XSL-FO
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc


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




Current Thread
Keywords