[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Reference to variable cannot be resolved.

Subject: RE: Reference to variable cannot be resolved.
From: "Martinez, Brian" <brian.martinez@xxxxxxxx>
Date: Fri, 14 Feb 2003 10:18:21 -0700
x cannot be resolved
> From: Jeni Tennison [mailto:jeni@xxxxxxxxxxxxxxxx]
> Sent: Friday, February 14, 2003 9:43 AM
> Subject: Re:  Reference to variable cannot be resolved.
> 
> Hi Brian,
> 
> > 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"/>
> > </xsl:template>
> 
> Um, I think that's legal in XSLT 2.0. What makes you think that it
> isn't?

Uh . . . because I didn't read the following paragraph in Section 9.7 very
closely?  ;-)

"It is also not an error if a binding established by a local xsl:variable or
xsl:param element shadows another binding established by another local
xsl:variable or xsl:param. However, such shadowing is discouraged and
implementations may output a warning when it occurs."

However, this illustrates why I think the code example given is misleading,
because it doesn't really illustrate the concept of shadowing a local
variable, but rather the restrictions placed on its scope: the variable
declaration inside the for-each will never override the outer variable with
the same name.

Still, I'm very surprised that my above example would be legal, and it makes
Dimitre's objection that much clearer: if the value of $x can't be changed
by a subsequent binding within the same scope, then why allow the practice
at all?

> I think that the argument for allowing shadowing of local variables
> was that it allows those unimaginative programmers who can only think
> of the one variable name (you know who I'm talking about, David C.) to
> reuse that variable name while carrying out several steps of
> processing on the same value, precisely as you have above.
> 
> Note that both XSLT 1.0 and XSLT 2.0 allow you to do:
> 
> <xsl:template match="/">
>   <xsl:variable name="x">
>     <xsl:variable name="x" select="1" />
>     <xsl:value-of select="$x + 1" />
>   </xsl:variable>
>   <xsl:value-of select="$x" />
> </xsl:template>

True . . . but it does makes sense, since the inner $x is not in the same
scope as the outer $x.  What I'm struggling to understand is why the spec
would allow a programmer even to attempt to assign a new value to $x.

cheers,
b.

| 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 |
| http://www.cheaptickets.com/                   http://www.trip.com/ |

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.