This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: !!!counters in XSL!!!


Rosa I-Ting Cheng wrote:
> 
> can anyone please tell me whether you can have counters in XSL? I mean I
> want to increment a variable each time I go into a certain for-each loop.
> 
> or how can I counter the number of nodes with the "node" attribute equaling
> to say "here"?
> 

Hello, Rosa

Unfortunately, there are no counters in XSLT. Even worse, the ortodox
XSLT tradition considers counters incompatible with the very phylosophy
of XSLT.

This makes life of programmers which migrate from the commonly used
tools to XSLT quite difficult. Usually, people who need counters in
their XSLT stylesheets get an advice from XSLT gurus to use some awful
methods which require calling XSLT templates recursively. But, if you
want to be 100% XSLT conforming, you have to use such methods.

However, if 100% conformance is not that important for you, you may
check documentation of the particular XSLT processor you are using. Many
XSLT implementations provide extensions which can be used to emulate
counters.

For example, if you are using SAXON, you can try the <saxon:assign>
extension element. If you are using MSXML3, you can code counters in
JScript using <msxml:script> extension element. And so on.

But be careful: once you started using extensions, your stylesheets
become processor-dependent. You might have difficulties porting those
stylesheets between different XSLT implementations.

Kind regards,

Alexey Gokhberg
Unicorn Enterprises SA
http://www.unicorn-enterprises.com

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]