[xsl] result = node1 * node2 and then get total of all the result from whole document at the end

Subject: [xsl] result = node1 * node2 and then get total of all the result from whole document at the end
From: "Khalid Ali" <k_ali@xxxxxxxxxxxxxxx>
Date: Tue, 1 Jan 2002 07:26:44 -0700
Hello everybody,I am new to this forum and new to xslt as well.I have been
stuck with this problem for several days.
what I want to do is,to go through an xml file multiply rate with value at
each level and print the product.
Then at the end of the document I need to add all of the products of
multiplication and print a grand total.
In a structured programming language it may look like this.
double rate=0.0;
int quantity = 0;
double total= 0.0;
double grandtotal =0.0;
for(int x=0;x<xmldoc.length;x++){
    if(element.name=="rate"){
        rate = (double)elementRate.value
    }else if(element.name=="quantity"){
        quantity = (double)elementQuantity.value;
    }
    total= rate * quantity;
    //at aevery cycle I would like to print the total i.e. value
    //then I have to add this value to a agrand total variable.
    grandtotal +=total;
}
I would appreciate if some one can guide me to get this functionality.
below is the segment of an xml file that I am working on.


<adjustments>
 <adjustment>
     <system-id>1</system-id>
        <last-modified />
        <edition>
         <system-id>66</system-id>
          <last-modified>4 December, 2001 11:56</last-modified>
          <edition-name>NW1-Edition</edition-name>
          <start-date>4 December, 2001</start-date>
          <end-date />
        </edition>
        <currency>
         <system-id>2</system-id>
          <last-modified>3 December, 2001 10:01</last-modified>
          <description>Dollars</description>
          <code>CAD</code>
        </currency>
        <transaction-type>
         <system-id>1</system-id>
          <last-modified>3 December, 2001 11:14</last-modified>
          <description>Handling Allowance</description>
        </transaction-type>
        <transaction-date>7 December, 2001</transaction-date>
*        <rate>.32</rate>
*        <quantity>22145</quantity>
        <adjustment-taxes />
 </adjustment>
 <adjustment>
     <system-id>1</system-id>
        <last-modified />
        <edition>
         <system-id>66</system-id>
          <last-modified>4 December, 2001 11:56</last-modified>
          <edition-name>NW1-Edition</edition-name>
          <start-date>4 December, 2001</start-date>
          <end-date />
        </edition>
        <currency>
         <system-id>2</system-id>
          <last-modified>3 December, 2001 10:01</last-modified>
          <description>Dollars</description>
          <code>CAD</code>
        </currency>
        <transaction-type>
         <system-id>1</system-id>
          <last-modified>3 December, 2001 11:14</last-modified>
          <description>Handling Allowance</description>
        </transaction-type>
        <transaction-date>7 December, 2001</transaction-date>
*        <rate>.79</rate>
*        <quantity>1425</quantity>
        <adjustment-taxes />
 </adjustment>
</adjustments>

At this point I can go through the document and get the values from all the
rate and quantity nodes and print their product as well.I am having hard
time adding the product of rate and quantity into a variable and then
increment it and print it at the end of document.
Please help me.In the actual document there will be several
adjustment,supply and other nodes who has rate and quantity nodes.I want to
get the result = rate*quantity and print it on the page as well as I want to
calculate a grand total with all the results of the multiplications of rate
and quantity and print it at the end of the document.
Please help.

Khalid


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


Current Thread