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]
Other format: [Raw text]

Re: For Loop in XSLT


Bagchi Ratul wrote:
> 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.

To supplement what Jeni and Michael said, the use cases where people think
they need a for loop with an arbitrary counter variable are, at least half the
time (an estimate based on FAQs on this list), not really needing one at all;
the problem can sometimes be redefined in terms of careful selection of nodes
to process, through the use of xsl:for-each or xsl:apply-templates.

The most common case is when you want to divide a data set into pages,
producing a series of tables with a maximum number of rows per table. The FAQ
offers several examples in
http://www.dpawson.co.uk/xsl/sect2/N4486.html (grouping) and
http://www.dpawson.co.uk/xsl/sect2/N7450.html (tables)

In general, only when you have a case like the one demonstrated in
http://www.dpawson.co.uk/xsl/sect2/N4806.html (iteration) 
or when you're needing to walk through a string do you need recursion.

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

 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]