xsl-list
[Top] [All Lists]

Re: [xsl] XSLT code for function fn:fold-right()

2019-03-13 06:30:07
Am 13.03.2019 um 10:11 schrieb Mukul Gandhi 
gandhi(_dot_)mukul(_at_)gmail(_dot_)com:
Hi all,
    Please look at following link, for description of XPath 3.1 function fn:fold-right(),

https://www.w3.org/TR/xpath-functions-31/#func-fold-right

Within this function's description, its mentioned
The effect of the function is equivalent to the following implementation
or its equivalent in XSLT:

<xsl:function name="fn:fold-right" as="item()*">
  <xsl:param name="seq" as="item()*"/>
  <xsl:param name="zero" as="item()*"/>
  <xsl:param name="f" as="function(item(), item()*) as item()*"/>
  <xsl:choose>
    <xsl:when test="fn:empty($seq)">
      <xsl:sequence select="$zero"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:sequence select="$f(fn:head($seq), fn:fold-right(fn:tail($seq), $zero, $f))"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:function>

I've a feeling, that above XSLT logic of this function may be wrong (particularly the line <xsl:sequence select="$f(fn:head($seq), fn:fold-right(fn:tail($seq), $zero, $f))"/>. But I'll appreciate if anyone may point me wrong).

Is there any input for which the function fails to give the right result?

For instance for any of the test cases in https://github.com/w3c/qt3tests/blob/master/fn/fold-right.xml?

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>