Can the function defined by the xsl function: replace with the built-in function xpath 3.0?

I played with this example in the xpath 3.0 specification:

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

I tried to substitute the inline function with the function defined by the 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 I got the error that "the first fold-left parameter cannot be an empty sequence.

Am I doing something wrong or is it impossible?

Thanks in advance.

+4
source share
1 answer

Here is the 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> 

if applied to any XML document (not used), the desired, correct result is required :

 15 
+4
source

All Articles