开发者

Can a function defined by xsl:function substitute for an xpath 3.0 inline function?

开发者 https://www.devze.com 2023-03-29 13:47 出处:网络
I was playing with this example in the xpath 3.0 spec: fn:fold-left(function($a, $b) { $a + $b }, 0, 1 to 5)

I was playing with this example in the xpath 3.0 spec:

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

I tried to substitute the inline function with a function defined by xsl:function.

<xsl:function name="ki:plus" as="xs:integer*">
<xsl:param name="a" as="xs:inte开发者_Python百科ger*">
<xsl:param name="b" as="xs:integer">

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

</xsl:function>

But got the error that "first parameter of fold-left can't be an empty sequence.

Am I doing something wrong or is this not possible?

Thanks in advance.


Here is a correct example:

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

when applied on any XML document (not used), the wanted, correct result is produced:

15
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号