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

Re: Two versions of sum over node list by recursion--w

Subject: Re: Two versions of sum over node list by recursion--why and how does second one work?
From: "andrew welch" <andrew.j.welch@xxxxxxxxx>
Date: Tue, 5 Sep 2006 17:15:10 +0100
Re:  Two versions of sum over node list by recursion--w
On 9/5/06, hanged.man@xxxxxxxxx <hanged.man@xxxxxxxxx> wrote:
SECOND EXAMPLE:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

<xsl:template name="total-sales-value">
   <xsl:param name="list"/>
   <xsl:choose>
      <xsl:when test="$list">
         <xsl:variable name="first" select="$list[1]"/>
         <xsl:variable name="total-of-rest">
            <xsl:call-template name="total-sales-value">
               <xsl:with-param name="list" select="$list[position()!=1]"/>
            </xsl:call-template>
         </xsl:variable>
         <xsl:value-of select="$first/sales * $first/price +
$total-of-rest"/>
      </xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
   </xsl:choose>
</xsl:template>
QUESTION:

In Mr. Kay's example, why does the variable $total-of-rest indeed contain
the total
and not just the result of the addition in the last recursion?

It's as the recursion unravels - it essentially adds it from last item to the first. It's a great example of a mind-bending recursive programming :)

cheers
andrew

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-2011 All Rights Reserved.