473,390 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

Subtotals & Grand Total

XML
Expand|Select|Wrap|Line Numbers
  1. <nodeAA>AA</nodeAA>
  2.     <nodeBB>BB</nodeBB>
  3.         <nodeCC>
  4.             <From>12/05</From>
  5.             <To>11/06</To>
  6.             <Months>12</Months>
  7.             <Amount>10.00</Amount>
  8.             CC
  9.         </nodeCC>
  10.     </nodeBB>
  11.     <nodeDD>DD</nodeDD>
  12.         <nodeEE>
  13.             <From>12/06</From>
  14.             <To>11/07</To>
  15.             <Months>12</Months>
  16.             <Amount>20.00</Amount>
  17.             EE
  18.         </nodeEE>
  19.     </nodeDD>
  20. </nodeAA>
Desired Output
12/05 - 11/06 (12) 0010.00 = 0120.00
12/06 - 11/07 (12) 0020.00 = 0240.00

Grand Total: 0360.00
Nov 28 '08 #1
3 5892
Dormilich
8,658 Expert Mod 8TB
that seems not that difficult. for the number format you should read about the format-number() function. if you run into problems, we're around to assist you.

regards
Nov 28 '08 #2
jkmyoung
2,057 Expert 2GB
Agreed, most of it is easy, up to the grand total part.
For this, there are 2 recommended methods:
1. Recursive template, adding up the product from each part, pass sum as parameter or result
2. Create a temporary variable with the products. Then sum up using the sum function and the node-set function if necessary.

1. Pros: does not require extension functions.
Cons: uses more memory. Can break if there are too many nodes to calculate.

2. Pros: Requires only single pass.
Cons: Requires use of XSLT 2.0, or the node-set extension function, which differs across processors.

quick example of 1:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template name="addProducts">
  2.   <xsl:variable name="currentProduct" select="(*/Months) * (*/Amount)"/>
  3.   <xsl:choose>
  4.     <xsl:when test="not(following-sibling::*)">
  5.       <xsl:value-of select="$currentProduct"/>
  6.    </xsl:when>
  7.    <xsl:otherwise>
  8.       <xsl:variable name="$nextProductSums">
  9.          <xsl:for-each select="following-sibling::*[1]">
  10.             <xsl:call-template name="addProducts"/>
  11.          </xsl:for-each>
  12.        </xsl:variable>
  13.       <xsl:value-of select="$nextProductSums + $currentProduct"/>
  14.   </xsl:otherwise>
  15.   </xsl:choose>
  16. </xsl:template>
  17.  
Quick example of 2:
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="products">
  2.    <xsl:for-each select="*">
  3.        <node>
  4.          <xsl:value-of select="(*/Months) * (*/Amount)"/>
  5.        </node>
  6.   </xsl:for-each>
  7. </xsl:variable>
  8.  
  9. <xsl:value-of select="sum($products/node)"/>
  10.  
Dec 1 '08 #3
* Note * I had to remove the $'s at lines 5 and 8 of example 1. I'm forced to use xml version 1.0

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <xsl:stylesheet
  3.     version="1.0"
  4.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  5.  
  6.     <xsl:template match="/">
  7.         <html>
  8.             <body>
  9.                 <head>
  10.                     <title>PHUS Transformation</title>
  11.                 </head>
  12.                 <h1>PHUS Transformation</h1>
  13.                 <!-- <xsl:apply-templates select="PHUS/pBICYEAR"/> -->
  14.                 <xsl:apply-templates select="PHUS"/>
  15.             </body>
  16.         </html>
  17.     </xsl:template>
  18.  
  19.     <xsl:template match="pBICYEAR">
  20.  
  21.             <!-- pBICYEAR attribute: pBicYearData, child node of pBICYEAR -->
  22.             <xsl:for-each select="@pBicYearData">
  23.  
  24.                 <!-- Tax Year Headers -->
  25.                 <font size="6"><b><xsl:value-of select="." /></b></font><br/>
  26.  
  27.             </xsl:for-each>
  28.  
  29.                 <!-- pTRANS node: child node of pBICYEAR -->
  30.                 <xsl:for-each select="pTRANS">
  31.                     <font color="brick"><xsl:value-of select="@TransData" /></font><br/>
  32.  
  33.                     <!-- Event Data -->
  34.                     <xsl:for-each select="pEVNT">
  35.                         <font color="red">
  36.                             <xsl:value-of select="EventID" />*
  37.                             <xsl:value-of select="Description" />*
  38.                             <xsl:value-of select="From" />*-
  39.                             <xsl:value-of select="To" />*
  40.                             (<xsl:value-of select="ElapsedMonths" />)*
  41.                             <xsl:value-of select="Amount" /> *
  42.  
  43.                             <xsl:value-of select = "format-number(ElapsedMonths * Amount, '#######.00')"/>
  44.  
  45.                         </font><br/>
  46.                     </xsl:for-each><br/>
  47.  
  48.                 </xsl:for-each>
  49.  
  50.     </xsl:template>
  51.  
  52.     <xsl:template name="addProducts">
  53.       <xsl:variable name="currentProduct" select="(*/ElapsedMonths) * (*/Amount)"/>
  54.       <xsl:choose> 
  55.        <xsl:when test="not(following-sibling::*)"> 
  56.          <xsl:value-of select="currentProduct"/> 
  57.       </xsl:when> 
  58.        <xsl:otherwise> 
  59.          <xsl:variable name="nextProductSums"> 
  60.             <xsl:for-each select="following-sibling::*[1]"> 
  61.                <xsl:call-template name="addProducts"/> 
  62.             </xsl:for-each> 
  63.           </xsl:variable> 
  64.          <xsl:value-of select="$nextProductSums + $currentProduct"/> 
  65.       </xsl:otherwise> 
  66.       </xsl:choose> 
  67.     </xsl:template>   
  68.  
  69. </xsl:stylesheet>
  70.  
  71. <!-- This template is placed here for reference -->
  72. <!-- <xsl:template name="addProducts"> 
  73.   <xsl:variable name="currentProduct" select="(*/Months) * (*/Amount)"/> 
  74.   <xsl:choose> 
  75.     <xsl:when test="not(following-sibling::*)"> 
  76.       <xsl:value-of select="$currentProduct"/> 
  77.    </xsl:when> 
  78.    <xsl:otherwise> 
  79.       <xsl:variable name="$nextProductSums"> 
  80.          <xsl:for-each select="following-sibling::*[1]"> 
  81.             <xsl:call-template name="addProducts"/> 
  82.          </xsl:for-each> 
  83.        </xsl:variable> 
  84.       <xsl:value-of select="$nextProductSums + $currentProduct"/> 
  85.   </xsl:otherwise> 
  86.   </xsl:choose> 
  87. </xsl:template> -->
Dec 1 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Andy V | last post by:
Hi. I've got a multi page report of my monthly purchases. I'd like a running total (month to date) at the end of each page and to have that total at the top of the following page. So far all I can...
1
by: Teemu Keiski | last post by:
Hi, I have following type of scenario (also explained here http://blogs.aspadvice.com/joteke/archive/2005/01/10/2196.aspx ) We have problematic web server (wink2 Standard, 1.5GB of physical...
2
by: Richard Grene | last post by:
I am creating an Excel spreadsheet using a query function in my vb code. This works fine. I can format the columns but dont know how to create subtotals and a grand total. Thanks, Richard
4
by: Jerry LeVan | last post by:
Is is possible, via some clever sql coding ( perhaps with PL/pgsql) to get subtotals to appear in a selection, ie If I have a query: select * from checks order by category I would like the have...
3
by: Greg | last post by:
I have a database that tracks the vacation time of each employee of the company that I work for. Everything works great and totals all of the vacation time that has been used. Could someone give me...
17
by: barkarlo | last post by:
I need help to make grand total time in continuous forms. to calculate total work time I use following formula =format(+1--nz();"short time"). but when I make grand total time in form footer (for...
0
by: jessicaeatworld | last post by:
Hi, I'm using Access 2003 on Windows XP. I have created a PivotTable View Form and at the bottom is an automatically inserted Grand Total row. I added sum and avg fields and then hid the details so...
4
by: Micheal | last post by:
Greetings Access Group, Being relatively new to Access, I try to work through problems on my own and have been very successful, although I have a conundrum that I have been working on for two days...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.