Domanda

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:integer*">
<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.

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top