【问题标题】:Can a function defined by xsl:function substitute for an xpath 3.0 inline function?xsl:function 定义的函数可以替代 xpath 3.0 内联函数吗?
【发布时间】:2011-10-30 17:44:25
【问题描述】:

我在 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的第一个参数不能为空序列。

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

提前致谢。

【问题讨论】:

    标签: xslt saxon xslt-3.0 xpath-3.0


    【解决方案1】:

    这是一个正确的例子

    <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
    

    【讨论】:

    • 我必须承认我差点忘了这个问题。但是,很高兴知道。谢谢。
    • @FredFinkle:不客气。几天前我只是不小心碰到了“xpath 3.0”标签。
    猜你喜欢
    • 2010-09-16
    • 1970-01-01
    • 2012-01-17
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多