[xsl] Is there another way to do this?

Subject: [xsl] Is there another way to do this?
From: "Tim Lumley" <tlumley@xxxxxxxxxxxxxxx>
Date: Wed, 3 Mar 2004 21:19:04 +1100
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):

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

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"/>

To this template:

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

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

Tim Lumley

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

Current Thread