OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] XSLT For-Loop technique

[ Lists Home | Date Index | Thread Index ]

> What is the best way (if there is one) to implement the
> equivalent of a for-loop in xslt?

There isn't one, there are several, depending on the problem you want to
solve. For iterating over a node-set, use xsl:apply-templates or
xsl:for-each. For iterating over anything else (e.g. words in a sentence),
use a recursive call on a named template. For iterating a fixed (small)
number of times, a useful trick is:

<xsl:for-each select="//*[position() <= $n]">
  <td/>
</xsl:for-each>

In the XSLT 2.0 / XPath 2.0 working drafts there are much more powerful
facilities for manipulating sequences.

Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS