Subject: Re: [xsl] XPath 3.0: Is it possible to do recursion in an anonymous function? From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Mon, 8 Apr 2013 20:04:55 -0700 |
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@xxxxxxxxx> 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 > -- 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.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Matching string values ac, Michael Sokolov | Thread | Re: [xsl] XPath 3.0: Is it possible, Ihe Onwuka |
Re: [xsl] Matching string values ac, Michael Sokolov | Date | [xsl] Priorities of unionised patte, Ihe Onwuka |
Month |