xsl-list
[Top] [All Lists]

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

2012-10-13 14:03:38
Hi Folks, 

Is it possible to do recursion in an anonymous function?

Example: I would like to implement an "until" function. It has three arguments:

1. p is a boolean function
2. f is a function on x
3. x is the value being processed

Read the following function call as: decrement 3 until it is negative
      $until ($isNegative, $decrement, 3) 

where
      $isNegative := function($x as xs:integer) {$x lt 0}
      $decrement := function($x as xs:integer) {$x - 1}

Here's how I attempted to implement function until:

$until := function(
                                     $p as function(item()*) as xs:boolean,
                                     $f as function(item()*) as item()*,
                                     $x as item()*
                                ) as item()*
                         {
                             if ($p($x)) then 
                                   $x 
                             else 
                                   $until($p, $f, $f($x))  <-- RECURSE ...THIS 
IS NOT ALLOWED, I THINK
                           }

Is there a way to implement function until in XPath 3.0? (I know how to 
implement it in XSLT 3.0)

/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>
--~--