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 339320 - Scope of variables in a template included by multiple imports
Scope of variables in a template included by multiple imports
Status: RESOLVED FIXED
Product: libxslt
Classification: Platform
Component: general
1.1.15
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2006-04-21 15:51 UTC by kbuchcik
Modified: 2016-04-30 19:26 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description kbuchcik 2006-04-21 15:51:54 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>
Comment 1 Nick Wellnhofer 2016-04-30 19:26:59 UTC
Works for me with libxslt 1.1.28.