gpt4 book ai didi

xslt - xsl :function substitute for an xpath 3. 0 内联函数定义的函数可以吗?

转载 作者:行者123 更新时间:2023-11-30 23:45:45 25 4
gpt4 key购买 nike

我在 xpath 3.0 规范中使用这个例子:

fn:fold-left(function($a, $b) { $a + $b }, 0, 1 to 5)

我试图用 xsl:function 定义的函数替换内联函数。
<xsl:function name="ki:plus" as="xs:integer*">
<xsl:param name="a" as="xs:integer*">
<xsl:param name="b" as="xs:integer">

<xsl:value-of select="$a + $b">

</xsl:function>

但是得到了“fold-left的第一个参数不能是空序列”的错误。

我做错了什么还是不可能?

提前致谢。

最佳答案

这是一个正确的例子 :

<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="my:my">
<xsl:output omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="/">
<xsl:sequence select=
"fold-left(my:add#2, 0, 1 to 5)
"/>
</xsl:template>

<xsl:function name="my:add" as="xs:integer">
<xsl:param name="arg1" as="xs:integer"/>
<xsl:param name="arg2" as="xs:integer"/>

<xsl:sequence select="$arg1 + $arg2"/>
</xsl:function>
</xsl:stylesheet>

当应用于任何 XML 文档(未使用)时,会产生想要的正确结果 :
15

关于xslt - xsl :function substitute for an xpath 3. 0 内联函数定义的函数可以吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7123972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com