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

Re: How smart are the XSLT processors? Are there any X

Subject: Re: How smart are the XSLT processors? Are there any XSLT processors that convert tree-recursive functions into efficient iterative procedures?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 28 Apr 2010 23:42:36 +0100
Re:  How smart are the XSLT processors? Are there any X
On 28/04/2010 23:20, Florent Georges wrote:
David Carlisle wrote:

Hi,

You are making it pretty inefficient in any case by using
value-of (or relying on your xslt engine to optimise this away)
by using value-of you are asking for a document node with a
text node child

I didn't follow the whole discussion in details, so I probably missed something, but why do you say "by using value-of you are asking for a document node"? I thought it just created one text node.

Regards,



er because it was the middle of the night and I'm so used to moaning at people for using xsl:variable with content rather than a select attribute that "document node with text node child" just slipped off my fingers, sorry. (If you look at the saxon list you'll see that I hadn't woken up enough this morning to notice my error:-)

but the main point is that it's really too hard to expect automatic conversions from O(n^2) algorithms to O(log n). My own attempt was the following which I'd hoped would beat dimitre's for speed, but it doesn't consistently, and his has the advantage of using exact integer arithmetic (I didn't do the analysis to see at what the point the following will succumb to rounding error)

<xsl:function name="ex:pow" as="xs:decimal">
<xsl:param name="a" as="xs:decimal"/>
<xsl:param name="n" as="xs:integer"/>
<xsl:choose>
<xsl:when test="$n=0">
<xsl:sequence select="1"/>
</xsl:when>
<xsl:when test="$n=1">
<xsl:sequence select="$a"/>
</xsl:when>
<xsl:when test="$n mod 2 = 0">
<xsl:sequence select="for $z in ex:pow($a,$n idiv 2) return $z*$z"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="for $z in ex:pow($a,$n idiv 2) return $z*$z*$a"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>


<xsl:variable name="phi" select="1.618033988749894848204586834365638117720"/>
<xsl:variable name="r5" select="2.2360679774997896964091736687312762354406"/>


<xsl:function  name="ex:fibclosed" as="xs:integer">
  <xsl:param name="n"  as="xs:integer"/>
  <xsl:sequence select="xs:integer(floor(ex:pow($phi,$n) div $r5 + 0.5))"/>
</xsl:function>

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.