[Home] [By Thread] [By Date] [Recent Entries]


> 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@n...
work: Michael.Kay@s...


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member