Search code examples
xmlxsltxpathxslt-1.0exslt

Function called with too many arguments


I want to write a function in XSLT 1.0 using EXSLT library. Here is my stylesheet.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:func="http://exslt.org/functions"
    xmlns:my="http://www.example.com/">

    <xsl:output method="text" encoding="UTF-8"/>

    <func:function name="my:test">
        <xsl:param name="param1" />
        <xsl:param name="param2" />
        <func:result select="concat($param1, $param2)" />
    </func:function>

    <xsl:template match="/">
        <xsl:value-of select="my:test('test1', 'test2')" />
    </xsl:template>
</xsl:stylesheet>

Unfortunately when I try to execute it with xsltproc I am getting the following error.

{http://www.example.com/}test: called with too many arguments xmlXPathCompiledEval: 1 objects left on the stack. runtime error: file exslt_function_test.xsl line 16 element value-of XPath evaluation returned no result.

I do not see any error. The function is defined and called with exactly two parameters. Did anyone have a similar problem in the past?

To cut any unnecessary comments... No, I cannot use XSLT 2.0.


Solution

  • Well, this is a nice puzzle. Turns out libxslt (the processor used by xsltproc) will not execute the function unless you include extension-element-prefixes="func" in the <xsl:stylesheet> element.

    Not sure why that is - other processors have no such problem.