xsl-list
[Top] [All Lists]

RE: Number of times apply-templates gets executed.

2003-01-07 09:36:27
From: Patel, Viral [mailto:viral(_dot_)patel(_at_)countryfinancial(_dot_)com]
Sent: Tuesday, January 07, 2003 8:55 AM
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?

Correct.

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

Not in a procedural sense (incrementing a loop counter, for instance), but
there's other ways you could determine this.

Output the count of nodes matching your template rule:

<xsl:value-of select="count(/document/book/pages)"/>

Or output the position of the node being processed by a matching template:

<current-node><xsl:value-of select="position()"/></current-node>

Note that this will be the position of the *output* nodes--after any sorting
is done--not the order of nodes in the source document.  But it will still
tell you how many times the template was invoked.

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

Not for a loop counter, but you're also looking at your problem from a
procedural rather than a functional perspective.  When you build a result
tree from your input, there should be no need for a loop counter--you simply
provide templates that match the nodes you want to process, and output them
in the format you want.

As far as booleans go, they exist in XSLT--but they're not needed to control
loops or for other procedural logic.  Your processing can be controlled
entirely by iteration using xsl:for-each or by rules-based templates.

cheers,
b.

| brian martinez                              
brian(_dot_)martinez(_at_)trip(_dot_)com |
| senior gui programmer                                  303.708.7248 |
| trip network, inc.                                 fax 303.790.9350 |
| 6436 s. racine cir.                             englewood, co 80111 |
| http://www.cheaptickets.com/                   http://www.trip.com/ |

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