[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] update value of variable in for-each loop


Subject: Re: [xsl] update value of variable in for-each loop
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Wed, 9 Apr 2014 08:46:20 +0100

> (Indeed, I'm surprised your processor did not raise a warning when you
> defined $foo twice in the same scope.)
>

This was disallowed in XSLT 1.0, and became allowed in XSLT 2.0. There were
strong arguments on both sides.

Now that it's permitted, I sometimes take advantage of it in constructs like

<xsl:variable name="seq" select="//x"/>
<xsl:variable name="seq" select="for $x in $seq return f($x)"/>
<xsl:variable name="seq" select="for $x in $seq return g($x)"/>

etc; using the same variable name for each stage in a sequence of
computations. But I still think it was a mistake to permit it, because
beginners (and some long-standing users like henry...) persist in trying to
write XSLT the way they write in procedural languages, and the restriction on
shadowing variables was a good way of catching their mistake.

Michael Kay
Saxonica


Current Thread
Keywords