Derek Fountain wrote:
This is a FFFAQ ...
My apologies. :o} Is there a FAQ for this NG?
XSLT is a functional (side-effects free) language and it is not possible
to change the value of an xsl:variable once initially defined.
You must use not xsl:for-each, but a named template that calls itself
recursively.
This is a concept I'm not familiar with. Is there anything out there I can
read to understand it?
There are a few examples at
http://www.dpawson.co.uk/xsl/sect2/recursion.html.
Below is an example that works with any source document. This example
uses a named template to implement a kind of 'for' loop. As you can see
from the result, the $from parameter value is incremented until the
"$from < $to" test returns 'false' and the template is not called again.
-- begin stylesheet --
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:call-template name="for">
<!-- use the default value for $from -->
<xsl:with-param name="to" select="10"/>
<!-- use the default value for $step-->
</xsl:call-template>
</xsl:template>
<xsl:template name="for">
<xsl:param name="from" select="0"/>
<xsl:param name="to" select="0"/>
<xsl:param name="step" select="1"/>
<xsl:if test="$from < $to">
<!-- Do something. Here, just output parameter values -->
<xsl:text>

$from = </xsl:text>
<xsl:value-of select="$from"/>
<xsl:text>
$to = </xsl:text>
<xsl:value-of select="$to"/>
<xsl:text>
$to = </xsl:text>
<xsl:value-of select="$to"/>
<!-- Call itself with new parameter values -->
<xsl:call-template name="for">
<xsl:with-param name="from" select="$from + $step"/>
<xsl:with-param name="to" select="$to"/>
<xsl:with-param name="step" select="$step"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
-- end stylesheet --
-- begin result --
$from = 0
$to = 10
$to = 10
$from = 1
$to = 10
$to = 10
$from = 2
$to = 10
$to = 10
$from = 3
$to = 10
$to = 10
$from = 4
$to = 10
$to = 10
$from = 5
$to = 10
$to = 10
$from = 6
$to = 10
$to = 10
$from = 7
$to = 10
$to = 10
$from = 8
$to = 10
$to = 10
$from = 9
$to = 10
$to = 10
-- end result --
// Magnus