[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT code for function fn:fold-right()

Subject: XSLT code for function fn:fold-right()
From: "Mukul Gandhi gandhi.mukul@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 13 Mar 2019 09:11:36 -0000
 XSLT code for function fn:fold-right()
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). I propose the following new XSLT code for this
function,

<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="fn:fold-right(fn:subsequence($seq, 1,
fn:count($seq)-1), $f($seq[fn:last()], $zero), $f)"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:function>

I wanted to raise this issue on this spec's bugzilla. But I wanted to make
sure that I'm right, by asking the question here first.




-- 
Regards,
Mukul Gandhi

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.