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

How smart are the XSLT processors? Are there any XSLT

Subject: How smart are the XSLT processors? Are there any XSLT processors that convert tree-recursive functions into efficient iterative procedures?
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Tue, 27 Apr 2010 19:27:11 -0400
 How smart are the XSLT processors? Are there any XSLT
Hi Folks,

Below are two implementations of the Fibonacci sequence.

The first version is a direct translation of the definition of the Fibonacci
sequence into XSLT -- it is declarative code.

The second version is an iterative approach -- it is imperative code.

The advantage of the first version is that it is easy to specify and
understand. It's disadvantage is that, if the XSLT processor is not smart, it
is highly inefficient --  Fib(n) grows exponentially with n.

However, a "smart compiler" could transform tree-recursive functions into more
efficient iterative procedures that compute the same result -- a smart XSLT
processor could convert the first version into the second version.

I ran both versions on Fib(100). The second version finished in less than 1
second. As for the first (declarative) version, after 10 minutes it was still
executing so I killed the process.

I conclude that, at least for the XSLT processor I used, it does not convert
the first version into more efficient iterative procedures. This is sad. I
would prefer writing declarative code, but if XSLT processors do not optimize
the execution of declarative code then how realistic is declarative

Are there any XSLT processors that convert tree recursive functions into more
efficient iterative procedures?


     Version #1: Tree Recursion
    <xsl:function name="ex:fibonacci">
      <xsl:param name="n" />

          <xsl:when test="$n eq 0">
              <xsl:value-of select="0" />
          <xsl:when test="$n eq 1">
              <xsl:value-of select="1" />
              <xsl:value-of select="ex:fibonacci($n - 1) + ex:fibonacci($n -
2)" />


     Version #2: Tree Iterator
    <xsl:function name="ex:fibonacci">
      <xsl:param name="n" />

      <xsl:value-of select="ex:fibonacci-iterator(1, 0, $n)" />


    <xsl:function name="ex:fibonacci-iterator">
      <xsl:param name="a" />
      <xsl:param name="b" />
      <xsl:param name="count" />

          <xsl:when test="$count eq 0">
              <xsl:value-of select="$b" />
              <xsl:value-of select="ex:fibonacci-iterator($a + $b, $a, $count
- 1)" />


Current Thread


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.
First Name
Last Name
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.