[xsl] Re: Should variable resolution be done at compile-time or run-time?

Subject: [xsl] Re: Should variable resolution be done at compile-time or run-time?
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sat, 18 Oct 2003 10:46:21 +0200
A processor for a functional language may decide (and there are many cases
when this happens) to perform lazy evaluation.

Among other things lazy evaluation means not to report an error, which does
not actually affect the evaluation.

For example:

   f(x, y) = x * x

   f(3, 1/0)

The last expression will be evaluated to 9 and no error will be reported.

It is not surprizing that some XSLT processors evaluate lazily and have the
above behaviour in dealing with expressions, which would raise an error if
evaluated (but are never evaluated).

Such example for MSXML4 was given in the newsgroups in February:


Here, a global xsl:variable in an included stylesheet is defined as the
value returned from non-existent extension function.

As there is no reference to this variable in the code, no error is raised
and the transformation is successful.

This whole topic resembles the topic of "non-determinism" recently discussed
at the W3 forum

See the thread "XQuery" started at:


Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Eric Promislow" <ericp@xxxxxxxxxxxxxxx> wrote in message
> I ran into this problem while comparing results over
> Xalan 1.0, Saxon 6.1, and .Net 1.0 System.Xml.Xsl
> Here's the instance:
> ?xml version="1.0" encoding="UTF-8"?>
> <x>special contents</x>
> Here's the code, which tries to reference a variable
> bound in an outer dynamic scope, but foreign static scope:
> ?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> <xsl:output method="xml" />
> <xsl:template match="/">
>     <xsl:variable name="v1">bupkis</xsl:variable>
>     <xsl:apply-templates />
> </xsl:template>
> <xsl:template match='x'>
>   <output>
>     First, var v1 = <xsl:value-of select="$v1"/>.
>     Text = <xsl:value-of select='.' />
>   </output>
> </xsl:template>
> </xsl:stylesheet>
> Saxon and .Net give error messages and terminate; Xalan gives a
> warning message and replaces '$v1' with the empty string.
> I then changed [[<xsl:template match='x'>]] to [[<xsl:template
> so that the check could only be made at compile-time.
> Saxon complains, but Xalan and .Net carry out the full transform.
> The XSLT 1.0 spec says how the scope of variables is determined,
> but not when.  Is this a known gray area?  I just had a brief look,
> but XSLT 2.0:9.7 "Scope of Variables" doesn't specify this either.
> I know I would prefer this to be checked at compile-time, particularly
> with complex stylesheets with large numbers of rules and cases.
> - Eric
> ------------------------------------------------
> Eric Promislow
> Visual Studio .NET Plugins Development Lead
> EricP@xxxxxxxxxxxxxxx
> --
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

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

Current Thread