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

Is there another way to do this?

Subject: Is there another way to do this?
From: "Tim Lumley" <tlumley@xxxxxxxxxxxxxxx>
Date: Wed, 3 Mar 2004 21:19:04 +1100
tim lumley
Being new to XSL tree climbing (sequential tokenising HTML/XML/SGML for
years), I want to calculate the grand total for the saledetails.  I have
done my home work, around 3 XSLT books later I came up with this solution:

<XML/> (note: this is only a fragment of the xml):

<saledetails>
   <item>
      <sku>34860</sku>
      <description>Black felt-tip pens 0.4 mm</description>
      <units qpu="10">3</units>
      <unit.price gst="10">19.95</unit.price>
   </item>
   <item>
      <sku>49603</sku>
      <description>A4 Inkjet paper white</description>
      <units qpu="500">20</units>
      <unit.price gst="10">5.95</unit.price>
   </item>
</saledetails>

I use this call when I have matched="saledetails":

<xsl:call-template name="grandtotal">
   <xsl:with-param name="nodenumber" select="1"/>
   <xsl:with-param name="grandtotal" select="0"/>
</xsl:call-template>

To this template:

<xsl:template name="grandtotal">
   <xsl:param name="nodenumber"/>
   <xsl:param name="grandtotal"/>
   <xsl:choose>
      <xsl:when test="not(item[$nodenumber])">
         <xsl:value-of select="format-number($grandtotal, '#0.00')"/>
      </xsl:when>
      <xsl:otherwise>
         <xsl:call-template name="grandtotal">
            <xsl:with-param name="nodenumber" select="$nodenumber+1"/>
            <xsl:with-param name="grandtotal"
select="$grandtotal+(item[$nodenumber]/units *
item[$nodenumber]/unit.price)"/>
         </xsl:call-template>
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>


This works but I'm just wondering is there a simpler method for doing this?


Cheers
Tim Lumley
tlumley@xxxxxxxxxxxxxxx



 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.