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

Re: XPath 3.0: Is it possible to do recursion in an a

Subject: Re: 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
Re:  XPath 3.0: Is it possible to do recursion in an  a
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

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.