How Do I Implement a for Loop?
The simple answer: you don’t. What XSLT calls variables are
variables in the mathematical sense of the term. An
<xsl:variable>
can be assigned an initial
value, but it can’t be changed. The upshot of this situation is
that you can’t implement a for
loop as you
typically do in most procedural programming languages. However,
earlier in the book we did implement a stylesheet that emulates a
for
loop. See Section 4.7 in Chapter 4 for a complete discussion of this example.
It’s much more likely that you need to iterate across a group of nodes in an XML document. If that’s the case, see Section 4.2.3 in Chapter 4 for more information.
Get XSLT now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.