Something new in addition to the treatment of this subject in the
current thread -- tail-call optimization and how to survive its
complete lack in current XPath 3.0 processors:
http://dnovatchev.wordpress.com/2013/04/08/recursion-with-anonymous-inline-functions-in-xpath-3-0-part-ii/
On Sun, Oct 14, 2012 at 9:44 AM, Costello, Roger L.
<costello(_at_)mitre(_dot_)org> wrote:
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>
--~--
--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
--~------------------------------------------------------------------
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>
--~--