After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 58444 - Bug in local variable scoping?
Bug in local variable scoping?
Status: VERIFIED FIXED
Product: libxslt
Classification: Platform
Component: general
unspecified
Other All
: Normal major
: ---
Assigned To: Daniel Veillard
Daniel Veillard
Depends on:
Blocks:
 
 
Reported: 2001-08-02 15:35 UTC by Heiko W.Rupp
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Heiko W.Rupp 2001-08-02 15:35:07 UTC
In the following stylesheet, I expect the two
<xsl:value-of> calls to result different results, but it doesn't.
Checking with the local guru and against Saxon and Xalan, we
think libxslt is wong here.

The stylesheet:

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">

<xsl:output method="xml"/>

<xsl:template match="message">
<ROOT>
        <ELEMENT1>
                <xsl:variable name="test-var">
                        <xsl:call-template name="test1"/>
                </xsl:variable>
                <xsl:value-of select="$test-var"/>
        </ELEMENT1>
        <ELEMENT2>
                <xsl:variable name="test-var">
                        <xsl:call-template name="test2"/>
                </xsl:variable>
                <xsl:value-of select="$test-var"/>
        </ELEMENT2>
</ROOT>
</xsl:template>

<xsl:template name="test1">
Some result
</xsl:template>

<xsl:template name="test2">
other one
</xsl:template>

</xsl:stylesheet>


The XML-Input:

<?xml version="1.0" encoding="iso-8859-1"?>

<message/>

Results from running various XSLT-Processors

bash-2.05$ !xs
xsltproc foo.xsl foo.xml
xsl:variable : redefining test-var
<?xml version="1.0"?>
<ROOT><ELEMENT1>
Some result
</ELEMENT1><ELEMENT2>
Some result
</ELEMENT2></ROOT>

bash-2.05$ testXSLT -in foo.xml -xsl foo.xsl
========= Parsing foo.xsl ==========
Parse of foo.xsl took 10 milliseconds
========= Parsing foo.xml ==========
Parse of foo.xml took 0 milliseconds
=============================
Transforming...
<?xml version="1.0" encoding="UTF-8"?>
<ROOT><ELEMENT1>
Some result
</ELEMENT1><ELEMENT2>
other one
</ELEMENT2></ROOT>
transform took 0 milliseconds

Total time took 0 milliseconds

develop@projects: saxon foo.xml foo.xs
l
<?xml version="1.0" encoding="utf-8"?><ROOT><ELEMENT1>
Some result
</ELEMENT1><ELEMENT2>
other one
</ELEMENT2></ROOT>



This is with libxslt 1.0.0, but also shows with 1.0.1
Comment 1 Daniel Veillard 2001-08-13 09:50:21 UTC
Right, this is a libxslt bug. Redefining the same variable twice
in a template is not supported, the easiest solution to work around
this being to use different names. It's also a matter of style but
defining the variables at the top level of the template as the first
instructions makes the XSLt code really cleaner (i.e.
read/understand/maintain).
Fixing it won't be that easy too, unless this is really a blocking
point it may not be fixed quickly. Please tell if this is really
blocking your work.

Daniel
Comment 2 Daniel Veillard 2002-02-11 13:20:57 UTC
Dohh it was actually really easy to fix, I should not have
postponed handling it so long:

http://cvs.gnome.org/bonsai/cvsquery.cgi?module=libxslt&branch=HEAD&branchtype=match&dir=libxslt&file=&filetype=match&who=veillard&whotype=match&sortby=Date&hours=&date=explicit&mindate=02%2F11%2F02+08%3A13&maxdate=02%2F11%2F02+08%3A15&cvsroot=%2Fcvs%2Fgnome


  thanks for the bug report, and sorry for the delay

Daniel
Comment 3 Daniel Veillard 2002-02-12 08:31:02 UTC
Should be fixed in libxslt-1.0.12
 
  thanks,

Daniel