Alain ROY wrote:
I made a stylesheet to generate a PDF file. It print table rows with
an amount on each row. I'd like to calculate subtotals of these
amounts while running through my xml document so that I could print
the rows subtotal on the page footer when there is a page break. Does
anybody knows how I could do that ?
This is more an XSLT question, it comes up now and then
on the XSL list
http://www.mulberrytech.com/xsl/xsl-list/
and theres's probably already a FAQ entry (reachable from the
URL above).
The common advice is to use markers. Add a marker with the
running subtotal to each table row, and reference the
last marker of the page in the page footer. In FOP 0.20.5,
you must put the marker definition in a block in a table cell,
it wont work if the marker is an immediate child of a table
row.
Here is an old XML+XSLT to get you started:
?xml version=1.0?
elements
element
nameprod 1/nameprice10.0/price
/element
element
nameprod 2/nameprice5.0/price
/element
element
nameprod 3/nameprice2.0/price
/element
element
nameprod 4/nameprice1.1/price
/element
element
nameprod 5/nameprice3.4/price
/element
element
nameprod 6/nameprice5.9/price
/element
element
nameprod 7/nameprice4.88/price
/element
element
nameprod 8/nameprice20.04/price
/element
/elements
xsl:stylesheet version=1.0
xmlns:xsl=http://www.w3.org/1999/XSL/Transform;
xmlns:fo=http://www.w3.org/1999/XSL/Format;
xsl:strip-space elements=*/
xsl:template match=elements
fo:root
fo:layout-master-set
fo:simple-page-master master-name=simple
page-width=6cm page-height=5cm
fo:region-body margin-bottom=2cm/
fo:region-after extent=2cm/
/fo:simple-page-master
/fo:layout-master-set
fo:page-sequence master-reference=simple font-size=24pt
fo:static-content flow-name=xsl-region-after
fo:table table-layout=fixed width=100%
fo:table-column column-width=3cm/
fo:table-column column-width=3cm/
fo:table-body
fo:table-row
fo:table-cell border-before-style=solid
border-before-width=2pt
fo:block
fo:retrieve-marker retrieve-class-name=subtotalname
retrieve-boundary=page
retrieve-position=last-starting-within-page/
/fo:block
/fo:table-cell
fo:table-cell border-before-style=solid
border-before-width=2pt
fo:block text-align-last=end
fo:retrieve-marker retrieve-class-name=subtotalvalue
retrieve-boundary=page
retrieve-position=last-starting-within-page/
/fo:block
/fo:table-cell
/fo:table-row
/fo:table-body
/fo:table
/fo:static-content
fo:flow flow-name=xsl-region-body
fo:table table-layout=fixed width=100%
fo:table-column column-width=3cm/
fo:table-column column-width=3cm/
fo:table-body
xsl:apply-templates select=element/
/fo:table-body
/fo:table
/fo:flow
/fo:page-sequence
/fo:root
/xsl:template
xsl:template match=element
fo:table-row
fo:table-cell
fo:block
fo:marker marker-class-name=subtotalname
xsl:choose
xsl:when test=position()=last()
xsl:texttotal/xsl:text
/xsl:when
xsl:otherwise
xsl:textsubtotal/xsl:text
/xsl:otherwise
/xsl:choose
/fo:marker
fo:marker marker-class-name=subtotalvalue
xsl:value-of select=price + sum(preceding::price)/
/fo:marker
xsl:value-of select=name/
/fo:block
/fo:table-cell
fo:table-cell
fo:block text-align-last=end
xsl:value-of select=price/
/fo:block
/fo:table-cell
/fo:table-row
/xsl:template
/xsl:stylesheet
J.Pietschmann
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]