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, "A Stylesheet That Emulates a for Loop" in Chapter 4, "Branching and Control Elements" 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, "The <xsl:for-each> Element" in Chapter 4, "Branching and Control Elements" for more information.
Copyright © 2002 O'Reilly & Associates. All rights reserved.