[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Number of times apply-templates gets executed.

Subject: RE: Number of times apply-templates gets executed.
From: "Martinez, Brian" <brian.martinez@xxxxxxxx>
Date: Tue, 7 Jan 2003 09:36:27 -0700
apply templates with loop counter
> From: Patel, Viral [mailto:viral.patel@xxxxxxxxxxxxxxxxxxxx]
> Sent: Tuesday, January 07, 2003 8:55 AM
> Subject:  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.martinez@xxxxxxxx |
| 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.