xsl-list
[Top] [All Lists]

RE: [xsl] XPath 3.0: Is it possible to do recursion in an anonymous function?

2012-10-14 11:44:15
Thank you very much Dimitre. That is a fantastic technique.

Using Dimitre's technique, I implemented the "until" function:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                            xmlns:xs="http://www.w3.org/2001/XMLSchema";
                            version="3.0">
    
    <xsl:output method="text"/>
    
    <xsl:variable name="isNegative" select="function($x as xs:integer) {$x lt 
0}" />
    <xsl:variable name="decrement" select="function($x as xs:integer) {$x - 1}" 
/>
    <xsl:variable name="_until" select="
                  function(
                                    $p as function(item()*) as xs:boolean,
                                    $f as function(item()*) as item()*,
                                    $x as item()*,
                                    $_until as function(function(), function(), 
item()*, function()) as item()* 
                                 ) as item()*
                     {if ($p($x)) then $x else $_until($p, $f, $f($x), $_until)}
        " />
    
    <xsl:variable name="until" select="
                  function(
                                     $p as function(item()*) as xs:boolean,
                                     $f as function(item()*) as item()*,
                                     $x as item()* 
                                  ) as item()*
                      {$_until($p, $f, $x, $_until)}
          " />
    
    <xsl:template match="/">
        <xsl:value-of select="$until($isNegative, $decrement, 3)" />
    </xsl:template>
    
</xsl:stylesheet>

/Roger

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


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