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

calculating list of values using variables

  • From: Ian Rogers <ian.rogers@n...>
  • To: 'Xml-Dev <xml-dev@l...>
  • Date: Wed, 19 Sep 2001 12:02:06 +0100

using variables in xsl
can anyone help.

I sent a post out before about trying to use variables, and have been trying
some code but it comes up with the error "Keyword xsl:stylesheet may not
contain PCDATA nodes."

I have a set of details which contain an amount and a quantity and i want to
calculate the total amount for each set of details. I can calculate that and
place it in a variable, but i now want to calculate the total for all the
sets of details, giving an overall amount for all the sets of details

<xsl:variable name="Items" select="//details"/>

   <xsl:variable name="TotalValue">
    <xsl:call-template name="Total">
     <xsl:with-param name="Items" select="$Items"/>
     <xsl:with-param name="RunningTotal"    select="0"/>
    </xsl:call-template>
  </xsl:variable>

    Total = <xsl:value-of
    select="format-number($TotalValue, '####0.0#')"/>

 <xsl:template name="Total">
  <xsl:param name="Items"/>
  <xsl:param name="RunningTotal"/>
  <xsl:choose>
   <xsl:when test="not($Items)">
    <xsl:copy-of select="$RunningTotal"/>
   </xsl:when>
   <xsl:otherwise>
  <xsl:variable name="CurrentTotal"
			 select="$RunningTotal + ($Items[1]/amount * $Items[1]/quantity)"/>

   <xsl:call-template name="Total">
    <xsl:with-param name="Items" select="$Items[position()>1]"/>
    <xsl:with-param name="RunningTotal" select="$CurrentTotal"/>
   </xsl:call-template>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

"then i am calling the rest of my code to generate the table by using a
template and matching on the root node. I don't know if this could be
causing a problem?

<xsl:template match="/">

i would be very grateful if anyone could see what i am doing wrong or if
there is another way to calculate the total amount

thanks

Ian


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.