RE: [xsl] Reference to variable cannot be resolved.

Subject: RE: [xsl] Reference to variable cannot be resolved.
From: "Martinez, Brian" <brian.martinez@xxxxxxxx>
Date: Fri, 14 Feb 2003 09:19:36 -0700
> From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx]
> Sent: Friday, February 14, 2003 8:13 AM
> Subject: Re: [xsl] Reference to variable cannot be resolved.
> > Note that XSLT 2.0 (per the November 15 WD) changes this so that
> > shadowing a local variable is not an error, though it is 
> discouraged:
> > 
> >
> This is really horrible.
> Why should a language support a practice that must be discouraged?

The example given in the spec seems a bit misleading, because it really
illustrates the restrictions of scope and not the practice of shadowing.
The following is illegal in either spec:

<xsl:template match="/">
  <xsl:variable name="x" select="1"/>
  <xsl:variable name="x" select="$x+1"/>
  <xsl:value-of select="$x"/>

But in XSLT 1.0, you can do the following, which isn't much different from
what 2.0 would allow, other than the initial binding is global instead of

<xsl:variable name="x" select="1"/>
<xsl:template match="/">
  <xsl:if test="$x = 1">
    <xsl:variable name="x" select="$x + 1"/>
  <result><xsl:value-of select="$x"/></result>

Obviously it's complete nonsense.  Perhaps the prevailing attitude is that
implementations shouldn't have to prevent people from becoming victims of
their own bad code.  ;-)


| brian martinez                              brian.martinez@xxxxxxxx |
| senior gui programmer                                  303.708.7248 |
| trip network, inc.                                 fax 303.790.9350 |
| 6436 s. racine cir.                             englewood, co 80111 |
|          |

 XSL-List info and archive:

Current Thread