2014-12-03 124 views
0

我想使用EXSLT库在XSLT 1.0中编写函数。这是我的样式表。函数调用的参数太多

<?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> 

不幸的是,当我尝试用xsltproc我收到以下错误来执行它。

{ 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.

我没有看到任何错误。这个函数是用两个参数定义和调用的。过去有没有人有类似的问题?

削减任何不必要的评论...不,我不能使用XSLT 2.0。

回答

2

嗯,这是一个很好的谜题。变成libxslt(由xsltproc使用的处理器)将不会执行该功能,除非在<xsl:stylesheet>元素中包含extension-element-prefixes="func"

不知道这是为什么 - 其他处理器没有这样的问题。

+0

就是这样。谢谢! – Jagger 2014-12-03 21:52:43

+0

XSLT 1.0是一个非常简洁的书面规范,很容易错过它的一些细微之处,其中之一就是术语“元素”和“指令”之间的区别。仔细阅读“扩展元素”的定义,显然只有指令可以是扩展元素,而不是声明;并且扩展元素前缀对于特定于供应商的声明不是必需的。但你必须非常仔细地阅读才能得出这个结论。 – 2014-12-03 23:55:47