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

Re: [xsl] Mutual Recursion with Anonymous (Inline) Functions in XPath 3

  • From: Mukul Gandhi <mukulg@softwarebytes.org>
  • To: XML Developers List <xml-dev@lists.xml.org>
  • Date: Thu, 5 Oct 2023 21:13:07 +0530

Re: [xsl] Mutual Recursion with Anonymous (Inline) Functions in XPath 3
Hi Dimitre,
    Nice use case you've shared for XPath and XSLT. I've felt like responding to this.

On Thu, Oct 5, 2023 at 8:27 AM Dimitre Novatchev dnovatchev@gmail.com <xsl-list-service@l...> wrote:
Thought this topic might be interesting to some of us:

https://medium.com/@dimitrenovatchev/mutual-recursion-with-anonymous-inline-functions-in-xpath-3-0eb7c961806f

Also published in my blog.

I've understood the intent of this use case, by reading the following C language program that you've shared on your blog,

bool is_even(unsigned int n) {
    if (n == 0)
        return true;
    else
        return is_odd(n - 1);
}

bool is_odd(unsigned int n) {
    if (n == 0)
        return false;
    else
        return is_even(n - 1);
}

You wrote that you've solved this use case, with pure XPath 3, using Saxon. Ofcourse, Saxon is expected to be able to solve this for XML technologies, since its grately compliant to XSLT 3.0 and XPath 3.1 specs.

XalanJ currently has an XSLT 3.0 development branch on its codebase repos, where XalanJ team has implemented various XSLT 3.0 and XPath 3.1 language features.

I wrote the following XSLT 3.0 stylesheet to solve this use case (I've translated the C program, that you've cited on your blog and I've reproduced that as mentioned above),

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                         version="3.0">
               
  <xsl:output method="xml" indent="yes"/>
 
  <xsl:variable name="isEven" select="function($n) { if ($n eq 0) then true() else $isOdd($n - 1) }"/>
 
  <xsl:variable name="isOdd" select="function($n) { if ($n eq 0) then false() else $isEven($n - 1) }"/>
 
  <xsl:template match="/">    
     <result>
         <one>
              <xsl:value-of select="$isEven(255)"/>
         </one>
         <two>
             <xsl:value-of select="$isOdd(255)"/>
         </two>
     </result>
  </xsl:template>

</xsl:stylesheet>

Running the above XSLT 3.0 stylesheet with XalanJ's dev codebase build (and with Saxon HE 12.2 as well), produces following expected XSLT transformation result,

<?xml version="1.0" encoding="UTF-8"?><result>
    <one>false</one>
    <two>true</two>
</result>
 

--
Regards,
Mukul Gandhi


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.