W3C home > Mailing lists > Public > www-xsl-fo@w3.org > September 2002

Alternate table footers

From: <RShonk@flowserve.com>
Date: Fri, 27 Sep 2002 11:47:00 -0400
To: www-xsl-fo@w3.org
Message-ID: <OFC768F7BC.4C471C69-ON85256C41.005367DA@idpump.com>

Hi all,
I have an xsl that I am using to create pdf invoices. There are two xml
files involved
with this particular issue that I use for input. The first is header
information for
invoices and the second is the line items for each invoice. My xsl-fo
stylesheet is
 laid out as a table with a header, containing information from the header
xml.
A table-body with the line items and a table-footer. Everything is working
except
when an invoice translates to more than 1 page. What I would like is to
have
1 footer when all the line items are processed and another showing running
sub-totals when there are more line items to process. I have been playing
with
xsl, xsl-fo and xml for 2 weeks and would appreciate any pointers in how to
accomplish. Hopefully I did not trim too much from my code (or not enough :
-) )

Thanks,
Richard Shonk
Flowserve Corp.

===================== header.xml ===========================
<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<INVOICES>
   <INVOICE id="7148" account="143500">
      <INVOICE_NBR>52993972</INVOICE_NBR>
      <INVOICE_DATE>3/10/2000 0:0:0</INVOICE_DATE>
      <ORDER_NBR>047-93286</ORDER_NBR>
      <SHOP_REPORT_NBR>MOS   6381</SHOP_REPORT_NBR>
      <NAME>OCEAN COUNTY UA - CWPCF</NAME>
      <ADDRESS1>501 HICKORY LANE</ADDRESS1>
      <ADDRESS2>-</ADDRESS2>
      <CITY>BAYVILLE</CITY>
      <STATE>NJ</STATE>
      <ZIPCODE>08721</ZIPCODE>
      <COUNTRY>US</COUNTRY>
      <CUSTOMER_ORDER_NBR>00-WP-102-BI</CUSTOMER_ORDER_NBR>
      <DESTCODE>031</DESTCODE>
      <TERMS>01</TERMS>
      <MULTIPLIER>0</MULTIPLIER>
      <DATE_SHIPPED>3/8/2000 0:0:0</DATE_SHIPPED>
      <SHIPPED_VIA>RPS</SHIPPED_VIA>
      <SHIPPED_FROM>MOOSIC</SHIPPED_FROM>
      <FREIGHT>4.9</FREIGHT>
      <TOTAL>1671.18</TOTAL>
   </INVOICE>
   <INVOICE id="8972" account="143500">
............
   </INVOICE>
</INVOICE>
===================== header.xml ===========================

===================== lineitem.xml ===========================
<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<LINEITEMS>
   <LINEITEM id="7148">
      <QUANTITY>1</QUANTITY>
      <PART>807121-35</PART>
      <DESCRIPTION>CUTTER OSC P</DESCRIPTION>
      <DISCOUNT>750</DISCOUNT>
      <LIST>2221.71</LIST>
      <NET>1666.28</NET>
      <CCN>27989458</CCN>
   </LINEITEM>
   <LINEITEM id="8972">
      <QUANTITY>1</QUANTITY>
      <PART>196782-90</PART>
      <DESCRIPTION>CUTTER KIT</DESCRIPTION>
      <DISCOUNT>750</DISCOUNT>
      <LIST>2271</LIST>
      <NET>1703.25</NET>
      <CCN>27474212</CCN>
   </LINEITEM>
   <LINEITEM id="8972">
.....
   </LINEITEM>
   <LINEITEM id="8972">
.....
   </LINEITEM>
</LINEITEMS>
===================== lineitem.xml ===========================

===================== invoice.xsl ===========================
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:fo="http://www.w3.org/1999/XSL/Format"
     xmlns:Date="http://xml.apache.org/xslt/java/java.util.Date">

<xsl:template match="/invoice-xml-files">
    <xsl:variable name="TA-Parties"
                  select="document
(@bill-to)/TRANSACTION_PARTIES/TRANSACTION_PARTY"/>
    <xsl:variable name="details"
                  select="document(@invoice-detail)/LINEITEMS/LINEITEM"/>

<!-- [SNIP] -->

    <!-- BODY -->

    <fo:flow flow-name="xsl-region-body">
      <fo:block/>
      <xsl:apply-templates
           select="document(@invoice-header)/INVOICES/INVOICE">
        <xsl:with-param name="TA-Parties" select="$TA-Parties"/>
        <xsl:with-param name="details" select="$details"/>
        <xsl:with-param name="appPath" select="$appPath"/>
      </xsl:apply-templates>
    </fo:flow>
  </fo:page-sequence>

</fo:root>

</xsl:template>

<xsl:template match="INVOICES/INVOICE">
  <xsl:param name="TA-Parties"/>
  <xsl:param name="details"/>
  <xsl:param name="appPath"/>
  <xsl:param name="sumItems" select="sum($details[@id=current
()/@id]/NET)"/>
  <xsl:param name="subTotal" select="number(TOTAL) - number(FREIGHT)"/>

  <!-- Table to contain the whole document -->

  <fo:table width="7.5in" table-layout="fixed">
  <fo:table-column column-width="7.5in"/>

  <!-- Table header to emulate page header -->

  <fo:table-header>
   [SNIP]
  <!--  tables with value-of from header.xml -->
  </fo:table-header>

  <fo:table-footer>
   [SNIP]
  <!-- if all line items are processed
            show sub-total, freight and grand total
            from header.xml (this works fine)
         otherwise
            show total of all line items processed so far -->
  </fo:table-footer>

  <fo:table-body>
  <fo:table-row>
  <fo:table-cell>

  <!-- LINE ITEMS -->

  <fo:table border-collapse="collapse" border-color="black"
      border-style="solid" border-width="1pt"
      height="5.0in" table-layout="fixed">
    <fo:table-column column-width=".5in"/>
    <fo:table-column column-width="1.25in"
        border-width="1pt" border-color="black"
        border-left-style="solid"/>
    <fo:table-column column-width="3.25in"
        border-width="1pt" border-color="black"
        border-left-style="solid"/>
    <fo:table-column column-width=".5in"
        border-width="1pt" border-color="black"
        border-left-style="solid"/>
    <fo:table-column column-width="1in"
        border-width="1pt" border-color="black"
        border-left-style="solid"/>
    <fo:table-column column-width="1in"
        border-width="1pt" border-color="black"
        border-left-style="solid"/>
    <fo:table-body font-family="sans-serif" font-weight="normal">
      <xsl:apply-templates select="$details[@id=current()/@id]"/>
    </fo:table-body>
  </fo:table>

  </fo:table-cell>
  </fo:table-row>
  </fo:table-body>

  </fo:table>

</xsl:template>

[SNIP]

<xsl:template match="LINEITEM">
  <fo:table-row line-height="12pt" font-size="10pt">
    <fo:table-cell padding-top="1pt" padding-right="3pt">
      <fo:block text-align="end">
        <xsl:value-of select="QUANTITY"/>
      </fo:block>
    </fo:table-cell>
    <fo:table-cell padding-top="1pt" padding-left="3pt" padding-right
="3pt">
      <fo:block text-align="start">
        <xsl:value-of select="PART"/>
      </fo:block>
      <fo:block text-align="end">
        <xsl:value-of select="CCN"/>
      </fo:block>
    </fo:table-cell>
    <fo:table-cell  padding-top="1pt" padding-left="3pt" padding-right
="3pt">
      <fo:block text-align="start">
        <xsl:value-of select="DESCRIPTION"/>
      </fo:block>
      <fo:block text-align="end">
        <xsl:value-of select="MATERIAL"/>
      </fo:block>
    </fo:table-cell>
    <fo:table-cell padding-top="1pt" padding-right="3pt">
      <fo:block text-align="end">
        <xsl:if test="DISCOUNT!='0'">
          <xsl:value-of select="((1000 - number(DISCOUNT)) div 10)"/>%
        </xsl:if>
      </fo:block>
    </fo:table-cell>
    <fo:table-cell padding-top="1pt" padding-right="3pt">
      <fo:block text-align="end">
        <xsl:value-of select="format-number(LIST,'$###,##0.00')"/>
      </fo:block>
    </fo:table-cell>
    <fo:table-cell padding-top="1pt" padding-right="3pt">
      <fo:block text-align="end">
        <xsl:value-of select="format-number(NET,'$###,##0.00')"/>
      </fo:block>
    </fo:table-cell>
  </fo:table-row>
</xsl:template>

</xsl:stylesheet>
=========================invoice.xsl===========================
Received on Friday, 27 September 2002 11:53:28 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 3 October 2007 16:06:09 GMT