GNOME Bugzilla – Bug 381319
parameter variable of EXSLT-function not found
Last modified: 2006-12-11 23:00:06 UTC
The attached sample files cause xsltproc (libxslt 1.1.18 and 1.1.19) to report the following error message although the "missing" parameter has been declared: runtime error: file test.xsl line 10 element variable Variable 'table' has not been declared. xmlXPathCompiledEval: evaluation failed runtime error: file test.xsl line 15 element param Failed to evaluate the expression of variable 'tr'. This behavior was introduced with libxslt 1.1.18. --- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:func="http://exslt.org/functions" xmlns:math="http://exslt.org/math" xmlns:mg="mg" extension-element-prefixes="exsl func"> <xsl:template match="table"> <xsl:variable name="cols" select="mg:function(.)"/> </xsl:template> <func:function name="mg:function"> <xsl:param name="table"/> <xsl:param name="tr" select="$table/tr[1]"/> <func:result select="0"/> </func:function> </xsl:stylesheet> <?xml version="1.0" encoding="UTF-8"?> <root> <table> <tr> <td align="center">a</td> </tr> </table> </root>
Although this looked like a simple problem, it turned out to be a bit difficult (for me). I have changed the logic of the module handling exslt:function, as well as a couple of other related spots, and I think it should now be ok. Please try the current CVS with your original stylesheet and re-open the bug if there is any further problem. I also added a slightly-modified version of your test case to the libxslt regression tests so that the situation will be tested and verified with any future releases. Thanks for the report, and for your patience.
Thanks for your bugfix. Unfortunately, it seems there's still a problem with EXSLT function parameters, especially in conjunction with recursion. When using the current CVS version the following stylesheet produces a wrong result. mg:recurse(5,1) should return 15 but I get 6. Maybe a bug in the parameter stack management? <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://exslt.org/functions" xmlns:mg="mg" extension-element-prefixes="func"> <xsl:template match="text"> <xsl:value-of select="mg:recurse(5, 1)"/> </xsl:template> <func:function name="mg:recurse"> <xsl:param name="a"/> <xsl:param name="b"/> <xsl:choose> <xsl:when test="$a > 0"> <func:result select="$a+mg:recurse($a - $b, $b)"/> </xsl:when> <xsl:otherwise> <func:result select="0"/> </xsl:otherwise> </xsl:choose> </func:function> </xsl:stylesheet>
Here is a more complete test case with sample xml file: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://exslt.org/functions" xmlns:mg="mg" extension-element-prefixes="func"> <xsl:template match="root"> <xsl:value-of select="mg:recurse(a, b)"/> </xsl:template> <func:function name="mg:recurse"> <xsl:param name="a"/> <xsl:param name="b"/> <xsl:choose> <xsl:when test="$a > 0"> <func:result select="$a+mg:recurse($a - $b, $b)"/> </xsl:when> <xsl:otherwise> <func:result select="0"/> </xsl:otherwise> </xsl:choose> </func:function> </xsl:stylesheet> <?xml version="1.0"?> <root> <a>5</a> <b>1</b> </root>
Yes, you are correct, there was an additional problem which wasn't revealed by the previous tests. I have enhanced the applicable code (libexslt/functions.c), and also added this test to the regression test suite. Fixed code is in CVS. Thanks for the report.