GNOME Bugzilla – Bug 160400
Compiles invalid XSLT; unbound variable accepted
Last modified: 2006-07-14 16:24:24 UTC
Please describe the problem: Have a look at this stylesheet: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:call-template name="callee"> <xsl:with-param name="variable">output</xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template name="callee"> <!-- NOTE: no param element declaring $variable --> <xsl:value-of select="$variable" /> </xsl:template> </xsl:stylesheet> The template callee references $variable, but it haven't been declared with <param>. The specification says it is ok to pass a value with with-param and that the callee do Not have a corresponding <param>, but I can't tell whether $variable should be in callee's scope or not, according to the specification. The current behavior is that the variable is in the scope; the result tree has "output". If it must not, I don't understand why one should declare <param>s inside a template. If it's invalid, the stylesheet should fail to compile. This was encountered by Bob Stayton, and the stylesheet failed to compile with other processors, I was told. My MUA is down(bleeding edge), but I will return with more details. Cheers, Frans PS. bugzilla.gnome.org has 1.1.11 as latest version option, not 1.1.12. Steps to reproduce: Actual results: Expected results: Does this happen every time? Other information:
This is a bug. 11.6 Passing Parameters to Templates: "It is not an error to pass a parameter x to a template that does not have an xsl:param element for x; the parameter is simply ignored." The bugs here: 1) There's no binding for $variable in scope; this should raise an error already at compile-time. 2) The xsl:with-param value is ignored; xsl:with-param is used to *override* the value of a declared xsl:param (not of a xsl:variable); xsl:with-param does not declare a parameter binding.
There's at least one related bug in the regression tests: "tests\general\bug-41-.xsl". The bugs in this test case (and in Libxslt): 1) xsl:with-param must not override an xsl:variable 2) xsl:with-param will only override the value of an xsl:param inside the called template. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:variable name="foo" select="'FAILURE'"/> <xsl:template name="test"> <xsl:value-of select="$foo"/> </xsl:template> <xsl:template match="/"> <xsl:variable name="foo" select="'FAILURE'"/> <xsl:call-template name="test"> <xsl:with-param name="foo" select="'SUCCESS'"/> </xsl:call-template> </xsl:template> </xsl:stylesheet> $ xsltproc tests/general/bug-41-.xsl tests/docs/bug-41-.xml <?xml version="1.0"?> SUCCESS The correct result would be: <?xml version="1.0"?> FAILURE
Fixed in CVS HEAD. (The regression test results still need to be fixed)