Loading ...
Sorry, an error occurred while loading the content.

Re: grand total and subtotals

Expand Messages
  • hilz <hsalameh@yahoo.com>
    ... rows are ... subtotals ... litteral ... a footer. ... each ... even ... last ... in the ... i am trying to post this again, with text wraping option...
    Message 1 of 4 , Feb 26 12:21 PM
    • 0 Attachment
      --- In XSL-FO@yahoogroups.com, "W. Eliot Kimber" <eliot@i...> wrote:
      > hilz wrote:
      > > Hi:
      > > I hope anyone can help me with this.
      > >
      > > Is there a way to create a page subtotal?
      > > Creating the grand total was not a problem. it's only the page
      > > subtotal that is puzzling me.
      >
      > [This is starting to become something of an FAQ--Dave?]
      >
      > There is no possible general solution for this in XSL 1.0 without
      > extensions (which have been discussed on the exslfo list
      > (http://exslfo.sourceforge.net)). There are two possible
      workarounds:
      >
      > 1. If the number of rows per page is predictable (i.e., all the
      rows are
      > the same depth), you can simply emit a "footer" row with the
      subtotals
      > (calculated by your FO generation process). This would not be a
      litteral
      > table footer but would just be a normal row formatted to look like
      a footer.
      >
      > 2. If the number of rows per page is not predictable, use the
      > region-after's static text to display a row that uses markers to
      > retrieve the subtotals. To create the totals, just put a marker in
      each
      > cell with the total up to that cell and then use
      > retrieve-position="last-ending-within-page" in your retrieve-marker.
      >
      > The downside with this approach is that you cannot guarantee (or
      even
      > expect) that the summary row will be vertically adjancent to the
      last
      > row of the table, but it does allow you to show per-page totals).
      >
      > Or, you can put the summary row at the top of table by putting it
      in the
      > region-before static text (which can overlap with the region-body).
      >
      > Cheers,
      >
      > Eliot
      > --
      > W. Eliot Kimber, eliot@i...
      > Consultant, ISOGEN International
      >
      > 1016 La Posada Dr., Suite 240
      > Austin, TX 78752 Phone: 512.656.4139

      i am trying to post this again, with text wraping option... hoping it
      will look better.
      sorry for the confusion.

      Hi Eliot:
      Thank you for your answer.
      I tried your suggested solution #2.
      i am almost there, but not quite yet!

      i am stuck at calculating the total "up to that cell"
      i am having a problem with retreiving the marker and saving its value
      in a variable.
      i have attached below a simplified (but working) version of my
      stylesheet, and a sample xml file that goes with it , and i have a
      specific question.
      i have created 2 variables "first_cumulative_total"
      and "last_cumulative_total". the values of the two variables are
      retreived from the marker "cumulative total".
      now i need to subtract the first from the last. i do this as follows:

      <xsl:value-of select="$last_cumulative_total -
      $first_cumulative_total"/>

      and the result i get is NaN while i expect it to give me the result
      of the subtraction so i can get the subtotal for every page.

      the style sheet and the sample xml file are posted below. i use fop
      0.20.5rc to create the pdf file.

      i appreciate any help.

      ----------------sample.xsl-----------------------------
      <?xml version="1.0" encoding="ISO-8859-1"?>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.1"
      xmlns:saxon="http://icl.com/saxon" extension-element-prefixes="saxon"
      xmlns:fox="http://xml.apache.org/fop/extensions">
      <xsl:template match="QdmProject">
      <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
      <fo:simple-page-master master-
      name="pagemaster1" page-height="612.0pt" page-width="1008.0pt">
      <fo:region-body margin-
      left="35pt" margin-top="176pt" margin-bottom="180pt" margin-
      right="45pt"/>
      <fo:region-before
      extent="176pt"/>
      <fo:region-after
      extent="180pt"/>
      <fo:region-start
      extent="35pt"/>
      <fo:region-end extent="45pt"/>
      </fo:simple-page-master>
      </fo:layout-master-set>
      <xsl:apply-templates select="Payitem"/>
      </fo:root>
      </xsl:template>
      <xsl:template match="Payitem">
      <fo:page-sequence master-name="pagemaster1" master-
      reference="pagemaster1">
      <fo:static-content flow-name="xsl-region-
      before">
      <fo:block-container
      position="absolute" top="156pt" left="0pt" height="20.0pt"
      width="100.0pt">
      <fo:block span="none"
      position="relative" top="156pt" left="0pt" height="20.0pt"
      width="100.0pt" text-align="end">
      <xsl:text>Absolute
      station</xsl:text>
      </fo:block>
      </fo:block-container>
      <fo:block-container
      position="absolute" top="156pt" left="100pt" height="20.0pt"
      width="100.0pt">
      <fo:block span="none"
      position="relative" top="156pt" left="0pt" height="20.0pt"
      width="52.0pt" text-align="end">
      <xsl:text>Net
      Value</xsl:text>
      </fo:block>
      </fo:block-container>
      </fo:static-content>
      <fo:static-content flow-name="xsl-region-
      after">
      <fo:block-container
      position="absolute" top="4pt" left="100pt" height="16.0pt"
      width="200.0pt">
      <fo:block span="none"
      position="relative" top="4pt" left="539pt" height="16.0pt"
      width="76.0pt">
      <xsl:text>Page Total
      </xsl:text>
      <xsl:variable
      name="first_cumulative_total">
      <fo:retrieve-
      marker retrieve-class-name="cumulative_total" retrieve-
      boundary="page" retrieve-position="first-starting-within-page"/>
      </xsl:variable>
      <xsl:variable
      name="last_cumulative_total">
      <fo:retrieve-
      marker retrieve-class-name="cumulative_total" retrieve-
      boundary="page" retrieve-position="last-ending-within-page"/>
      </xsl:variable>

      <!-- this section
      should display the subtotal-->

      <xsl:value-of
      select="$last_cumulative_total - $first_cumulative_total"/>
      <!--
      <xsl:copy-of
      select="$last_cumulative_total"/>
      <xsl:text> -
      </xsl:text>
      <xsl:copy-of
      select="$first_cumulative_total"/>
      -->

      </fo:block>
      </fo:block-container>
      <fo:block-container
      position="absolute" top="20pt" left="100pt" height="16.0pt"
      width="200.0pt">
      <fo:block span="none"
      position="relative" top="20pt" left="539pt" height="16.0pt"
      width="76.0pt">
      <xsl:text>Grand Total
      </xsl:text>
      <xsl:value-of
      select="format-number(sum(//NetValue),'#0.00')"/>
      </fo:block>
      </fo:block-container>
      </fo:static-content>
      <fo:static-content flow-name="xsl-region-
      start"/>
      <fo:static-content flow-name="xsl-region-
      end"/>
      <fo:flow flow-name="xsl-region-body">
      <!-- GENERATING TABLE STARTS HERE-->
      <fo:block span="none">
      <fo:table table-
      layout="fixed">
      <fo:table-column
      column-width="100pt"/>
      <fo:table-column
      column-width="100pt"/>
      <fo:table-body>
      <xsl:for-each
      select="Quantity">
      <!--
      <xsl:sort select="MinimumStation/AbsoluteStation" data-
      type="number"/>-->

      <fo:table-row>

      <fo:table-cell text-align="end">

      <fo:block >

      <xsl:value-of
      select="MinimumStation/AbsoluteStation"/>

      </fo:block>

      </fo:table-cell>

      <fo:table-cell text-align="end" >

      <fo:block >

      <fo:marker marker-class-
      name="cumulative_total"><xsl:value-of select="sum((.|preceding-
      sibling::Quantity)/NetValue)"/></fo:marker>

      <xsl:value-of select="format-number
      (NetValue,'#0.00')"/>

      </fo:block>

      </fo:table-cell>

      </fo:table-row>
      </xsl:for-
      each>
      </fo:table-body>
      </fo:table>
      </fo:block>
      </fo:flow>
      </fo:page-sequence>
      </xsl:template>
      </xsl:stylesheet>

      ----------------end sample.xsl-------------------------





      ----------------sample.xml-----------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <QdmProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <Payitem>
      <Name>681-6208</Name>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>4112</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>1458</AbsoluteStation>
      </MinimumStation>
      <NetValue>2</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>2547</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>6858</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>3447</AbsoluteStation>
      </MinimumStation>
      <NetValue>2</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>7386</AbsoluteStation>
      </MinimumStation>
      <NetValue>3</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>3785</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>1758</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>45281</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>4953</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>7446</AbsoluteStation>
      </MinimumStation>
      <NetValue>2</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>7261</AbsoluteStation>
      </MinimumStation>
      <NetValue>2</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>7854</AbsoluteStation>
      </MinimumStation>
      <NetValue>2</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>6575</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>2678</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>5286</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>5218</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>8624</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>2517</AbsoluteStation>
      </MinimumStation>
      <NetValue>2</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>5434</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>8671</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>8274</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>2584</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>5584</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>4562</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>4747</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>2544</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>
      <Quantity>
      <MinimumStation>

      <AbsoluteStation>4535</AbsoluteStation>
      </MinimumStation>
      <NetValue>1</NetValue>
      </Quantity>

      </Payitem>
      </QdmProject>


      ---------------- end sample.xml-------------------------
    Your message has been successfully submitted and would be delivered to recipients shortly.