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

XSLT: SUM function or "+" operator usage problems to display

Subject: XSLT: SUM function or "+" operator usage problems to display subtotal/total
From: "Albert Tsun" <albert.tsun@xxxxxxxxxxxx>
Date: Fri, 27 Oct 2000 17:26:16 +0800
xslt sum

Hi all,

I had a transform problems which  is related to some arithmetic operation
and displaying total/subtotal problems.

For example I have a XML like this

<Report >
   <Header>
        <ReportID>01</ReportID>
        <Title>Trade Report</Title>
   </Header>
   <Trade>
     <Record>
          <Ref>0001<Ref>
          <User>User1</User>
          </Item>
               <Product>ABC</Product>
               <Price>100.00</Price>
          <Item>
          </Item>
               <Product>CDE</Product>
               <Price>200.00</Price>
          <Item>
     </Record>
     <Record>
          <Ref>0002<Ref>
          <User>User2</User>
          </Item>
               <Product>ABC</Product>
               <Price>100.00</Price>
          <Item>
          </Item>
               <Product>CDE</Product>
               <Price>200.00</Price>
          <Item>
     </Record>
      <Trade>
</Report>


Output:

ID : 01      Trade Report

Product                                                 Price
---------------------------------------------------------
Sales : User 1

ABC                                           100.00
CDE                                           200.00
                                         ------------------
Subtotal                                    300.00


Sales : User 2

ABC                                           100.00
CDE                                           200.00
                                         ------------------
Subtotal                                    300.00
                                         -------------------
Total                                          600.00


my XML:


<xsl:variable name="rptid" select="Report/Header/ReportID/text()">
<xsl:variable name="title" select="Report/Header/Title/text()">
<xsl:variable name="subtotal">0</xsl:variable>
<xsl:variable name="total">0</xsl:variable>
( ... Is this something wrong here??? ..)

<xsl:template match="Report">
     <xsl:apply-template select="*[not(self::Header)]"/>
</xsl:template>

<xsl:template match="Trade">
     (.. Print Report Title...)

     <xsl:apply-templates select="Record"/>

     (....How to Print each trade total using total variable ????...)
     (... How to Reset total variable to 0 ???..)
</xsl:template>

<xsl:template match="Record">
     <xsl:for-each select="item">
          (.... Print each line ..)

          (... increment the total, subtotal by value of <Price>)

          <xsl:variable name="subtotal">
               <xsl:value-of select="$subtotal+number(Price)">
          </xsl:variable>
          <xsl:variable name="total">
               <xsl:value-of select="$total+number(Price)">
          </xsl:variable>
          (..... however, this does not work, would someone point me to the
right way of sum up in for-each loop ??...)
          (..... if possible, please show me sample code ??...)
     </xsl:for-each>

     (.... How to print out subtotal here and reset the subtotal to 0
???... )
</xsl:template>

Thank you very much in advance.

Albert Tsun




 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.