This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: For Loop in XSLT
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: Bagchi Ratul <bratul at baan dot com>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Fri, 3 May 2002 12:12:46 +0100
- Subject: Re: [xsl] For Loop in XSLT
- Organization: Jeni Tennison Consulting Ltd
- References: <8987824ED22DD2118E3D00805F15192805E8A349@ex-ind-hu1.baan.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Ratul,
> I was just wondering if there is something like the for loop we have
> in other languages. I simulated it by recursively calling a template
> from itself. But I was not sure whether it is the only/best method.
It depends on what you want to loop over and what you want to do with
the loop. If you want to iterate over a set of nodes, and create part
of the result tree for each, you can use xsl:for-each or
xsl:apply-templates. Certain "aggregator" functions are built in, such
as sum() (to get the sum of a set of nodes) or count() (to count how
many nodes there are in a set). (There are more aggregator functions
in XPath 2.0.) Otherwise, you're right that you have to use a
recursive template.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list