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

Re: how to optimize recursive algorithm?

Subject: Re: how to optimize recursive algorithm?
From: David Tolpin <dvd@xxxxxxxxxxxxxx>
Date: Thu, 27 Nov 2003 18:16:55 +0400 (AMT)
xsl attibute
> For instance, say you have a source document like this:
> 
> <top>
>     <a/>
>     <b/>
>     <c/>
>     <d/>
> </top>
> 
> and the output of "b" depends on the position of "a", "c" depends on "b" and
> so on.

Functional languages are good at expressing loops.

<xsl:template name="position">
 <!-- get results of previous computations via parameters -->
  <xsl:param name="prev-x"/><xsl:param name="prev-y"/>

 <!-- compute current values based on the current node and results computed for the previous one -->
  <xsl:variable name="x" select="$prev-x + @width"/>
  <xsl:variable name="y" select="$prev-y + @height"/>

 <!-- output the current node with the results computed -->
  <xsl:copy>
    <xsl:copy-of select="@*">
    <xsl:attibute name="x"><xsl:value-of select="$x"/></xsl:attribute>
    <xsl:attibute name="y"><xsl:value-of select="$y"/></xsl:attribute>
  </xsl:copy>

 <!-- call the template for the next sibling, if there is one -->
  <xsl:for-each select="following-sibling::*[1]">
    <xsl:call-template name="position">
      <xsl:with-param name="prev-x" select="$x"/>
      <xsl:with-param name="prev-y" select="$y"/>
    </xsl:call-template>
  </xsl:for-each>

</xsl:template>

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.