Subject: Re: update value of variable in for-each loop
From: davep <davep@xxxxxxxxxxxxx>
Date: Wed, 9 Apr 2014 09:30:30 +0100
|
On Wed, 9 Apr 2014 08:46:20 +0100
Michael Kay <mike@xxxxxxxxxxxx> wrote:
> >
> > (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.
I can hear it now. "Oh yes you can 'update' a variable", Mike Kay
showed us how!
Shame you didn't get your way Mike.
regards
>
> Michael Kay
> Saxonica
>
--
regards
--
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk
|