xsl-list
[Top] [All Lists]

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

2003-10-18 01:46:21
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:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=03dd01c2d839%240e3699b0%248ef82ecf%40TK2MSFTNGXA04&rnum=1

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
   http://lists.w3.org/Archives/Public/public-qt-comments

See the thread "XQuery" started at:
    http://lists.w3.org/Archives/Public/public-qt-comments/2003Oct/0077.html


=====
Cheers,

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



"Eric Promislow" <ericp(_at_)ActiveState(_dot_)com> wrote in message
news:20031017122804(_dot_)F17953(_at_)ActiveState(_dot_)com(_dot_)(_dot_)(_dot_)
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";
version="1.0">
<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
match='x2'>]]
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(_at_)ActiveState(_dot_)com
--


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






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