GNOME Bugzilla – Bug 339320
Scope of variables in a template included by multiple imports
Last modified: 2016-04-30 19:26:59 UTC
This is an issue about the scope of global variables in conjunction with imports and includes. Scenario: - two imported stylesheets (A) and (B) both include the same third stylesheet (C) - stylesheet (C) has two references to variables: - the first references a variable in (A) - the second references a variable in (B) Question: Is this an error? Or are global variables of imported sheets merged before inclusion of sheets is performed? Or does an other mechanism apply? Tested with MSXML 4.0/.NET and Xalan-J (an older version unfortunately): Those processors allow such a scenario. Libxslt reports an error here. Example: "multi.xsl" - the main sheet ----------- <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:import href="multi-imp.xsl"/> <xsl:include href="multi-inc.xsl"/> <xsl:variable name="var-1" select="'value-1'"/> <xsl:template match="/"> <foo> <xsl:apply-templates/> </foo> </xsl:template> </xsl:stylesheet> "multi-imp.xsl" - the imported sheet --------------- <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:include href="multi-inc.xsl"/> <xsl:variable name="var-2" select="'value-2'"/> <xsl:template match="bar"> <bar> <xsl:apply-templates/> </bar> </xsl:template> </xsl:stylesheet> "multi-inc.xsl" - the sheet included by both above sheets --------------- <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="zoo"> <zoo attr-1="{$var-1}" attr-2="{$var-2}"> <xsl:apply-templates/> </zoo> </xsl:template> </xsl:stylesheet> "test.xml" - the input document <?xml version="1.0"?> <foo><bar><zoo/></bar></foo> result of xsltproc ------------------ >xsltproc multi.xsl ..\test.xml runtime error: file multi-inc.xsl line 4 element zoo unregistered variable var-1 xmlXPathCompiledEval: evaluation failed runtime error: file multi-inc.xsl line 4 element zoo unregistered variable var-2 xmlXPathCompiledEval: evaluation failed <?xml version="1.0"?> <foo><bar><zoo attr-1="runtime error" attr-2="runtime error"/></bar></foo> Result of other processors -------------------------- <?xml version='1.0' ?> <foo><bar><zoo attr-2="value-2" attr-1="value-1"/></bar></foo>
Works for me with libxslt 1.1.28.