File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes subtotal in xslt? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "subtotal in xslt?" Watch "subtotal in xslt?" New topic
Author

subtotal in xslt?

arulraj michealraj
Greenhorn

Joined: Mar 02, 2005
Posts: 28

summaryreport.xsl


//template for row1




The requirement is that subtotals need to be added for each group(group's atrriute is partnerid in summaryReport) in my summary report.
The object(summaryReport) are splitted into row1 and row2 respectively to fullfill our requirements.

Ex: summary report -record 1
partnerid=1;
totalpayment=10.00;
badpayment=20.00;
goodpayment=10.00;
avgpayment=10.00;
minpayment=20.00;
maxpayment=10.00;

summary report -record 2
partnerid=1;
totalpayment=10.00;
badpayment=30.00;
goodpayment=10.00;
avgpayment=40.00;
minpayment=20.00;
maxpayment=10.00;

summary report -record 3
partnerid=3;
totalpayment=10.00;
badpayment=20.00;
goodpayment=10.00;
avgpayment=10.00;
minpayment=20.00;
maxpayment=10.00;

Let's assume I have three records in summaryreport list.when the list is iterating in for-each loop, i have to check the current record's partnerid with next's
partnerid and do the summation(ie:subtotal) for each attribute in summary report till partner id is 1 and displays subtotal at end of each group.similarly i have to do for other group as well.
As i am new to this xsl, i am bit struggling to implement the above scenario.


1) How to compare the first and record object in for-each based on group(partner-id)?
2) how to do the summation for each group(partnerid)attributes?

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I edited your post to use the "code" tags to delimit code instead of the "bold" tags. Notice how it makes the code more readable and prevents your XSLT elements from being converted to smilies? Much easier to read.

As for your question, if you google "xslt grouping" the first link you get is this one: http://www.jenitennison.com/xslt/grouping/.

Your alternative is to use XSLT 2.0, which has new elements for grouping built into the language, but you would have to use a transformer which supported XSLT 2.0 if you chose that option.
arulraj michealraj
Greenhorn

Joined: Mar 02, 2005
Posts: 28
Paul.. Thanks for your help..... I am using XSL1.0. Acutually i cannot change the version to 2.0,as there are so- many xsl files depdend on 1.0.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: subtotal in xslt?
 
Similar Threads
How to Add a Line Counter for Each XML Element in XSL?
xsl to merge duplicate tag
XSLT: escaping " in output text
XSLT parsing XML
An XSLT that's just a little more Specific