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

Re: Subtotals by page

Subject: Re: Subtotals by page
From: James Fuller <jim.fuller@xxxxxxxxxxxxxx>
Date: Tue, 15 Mar 2005 12:20:07 +0100
xslt subtotal
Now what I actually want is the page total on this
page: which would be the value I get when I subtract
the above two values like this:
pagetotal - partsum
In XSL-FO it is not possible to do this.

So my question is even if I do know the number of rows
how do I make it sum that many number of rows?



instead of struggling with your XSLT, why not make your XML easier to work with.....


take the following example xml which represents an simple order

EXAMPLE XML
<?xml version="1.0" encoding="UTF-8"?>
<order>
   <item name="a" price="1.00"/>
   <item name="b" price="1.00"/>
   <item name="c" price="2.00"/>
   <item name="d" price="1.00"/>
   <item name="e" price="2.00"/>
   <item name="f" price="1.00"/>
   <item name="g" price="1.00"/>
   <item name="h" price="1.00"/>
   <item name="i" price="2.00"/>
   <item name="j" price="1.00"/>
   <item name="k" price="2.00"/>
   <item name="l" price="1.00"/>
</order>

wouldnt it be easier to supply your XSLT with something like;

DESIRED XML
<?xml version="1.0" encoding="utf-8"?>
<page>
  <item name="a" price="1.00"/>
  <item name="b" price="1.00"/>
  <item name="c" price="2.00"/>
  <item name="d" price="1.00"/>
  <item name="e" price="2.00"/>
</page>
<page>
  <item name="f" price="1.00"/>
  <item name="g" price="1.00"/>
  <item name="h" price="1.00"/>
  <item name="i" price="2.00"/>
  <item name="j" price="1.00"/>
</page>
<page>
  <item name="k" price="2.00"/>
  <item name="l" price="1.00"/>
</page>

the XML has segreated 5 <item/>'s per <page/> element

there are a variety of ways to achieve this type of grouping, the following is one way using mod and position() and xsl:for-each

EXAMPLE XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:template match="order">
<xsl:for-each select="item[position() mod 5 = 1]">
<page>
<xsl:for-each select=".|following-sibling::item[position() &lt;5]">
<xsl:copy-of select="."/>
</xsl:for-each>
</page>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


by having the first stage of XSLT processing massage your XML into a paged format makes the 2nd stage much easier to perform your sum() operations to obtain subtotal and total sums.

gl, Jim Fuller

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.