xsl-list
[Top] [All Lists]

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

2003-10-17 12:28:04
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