[xsl] Different footer in fo:region-after

Subject: [xsl] Different footer in fo:region-after
From: Arjan Bokx <abokx@xxxxxxxxxxx>
Date: Fri, 28 Jan 2011 13:37:40 +0100
Hello,

I have XML data in the following format:
There's one batch, which can contain multiple invoices, which can contain
multiple detail lines.


<?xml version="1.0" encoding="ISO-8859-1" ?>
<batch>
  <invoice>
    <id>Invoice1</id>
    <date>28-01-2011</date>
    <detail>
      <spec>Smurfs</spec>
      <amount>10.00</amount>
    </detail>
    <detail>
      <spec>LCD screen</spec>
      <amount>155.50</amount>
    </detail>
  </invoice>
  <invoice>
    <id>Invoice2</id>
    <date>27-01-2011</date>
    <detail>
      <spec>Rice</spec>
      <amount>5.00</amount>
    </detail>
    <detail>
      <spec>Wheat</spec>
      <amount>27.00</amount>
    </detail>
  </invoice>
</batch>


I have written XSL to make every invoice start on a new page. Detail lines may
spill over to extra pages, on which the same header and footer are printed. So
far, so good. It even has page numbers; numbering starts at 1 for every new
invoice.
I use Apache fop 1.0.
The XSL I have so far is (minimized but working example):



<?xml version="1.0"
      encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:fo="http://www.w3.org/1999/XSL/Format";>
  <xsl:output method="xml"
              indent="yes" />
  <xsl:strip-space elements="*" />
  <xsl:template match="/">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>
      <fo:layout-master-set>
        <fo:simple-page-master master-name="A4"
                               page-height="29.7cm"
                               page-width="21cm"
                               margin-top="6mm"
                               margin-bottom="18mm"
                               margin-left="6mm"
                               margin-right="0.25cm">
          <fo:region-body region-name="xsl-region-body"
                          margin-top="73mm"
                          margin-bottom="29mm"/>              <!-- page body
-->
          <fo:region-before region-name="xsl-region-before"
                            extent="73mm"/>                   <!-- page header
-->
          <fo:region-after region-name="xsl-region-after"
                           extent="29mm"/>                    <!-- page footer
-->
        </fo:simple-page-master>
      </fo:layout-master-set>
      <xsl:apply-templates select="/batch" />
    </fo:root>
  </xsl:template>
  <xsl:template match="invoice">
    <fo:page-sequence master-reference="A4"
                      initial-page-number="1"
                      force-page-count="no-force">
      <fo:static-content flow-name="xsl-region-before">
        <fo:block>
          <fo:retrieve-marker retrieve-class-name="headfields"/>
        </fo:block>
      </fo:static-content>
      <fo:static-content flow-name="xsl-region-after">
        <fo:block>
          <fo:retrieve-marker retrieve-class-name="footfields"/>
        </fo:block>
      </fo:static-content>
      <fo:flow flow-name="xsl-region-body">
        <fo:block break-before="page">
          <xsl:call-template name="invoice-lines" />
        </fo:block>
      </fo:flow>
    </fo:page-sequence>
  </xsl:template>

  <xsl:template name="invoice-lines">

    <fo:marker marker-class-name="headfields">
      <fo:block>
        <fo:page-number />
        <xsl:text> / </xsl:text>
        <fo:page-number-citation ref-id="{generate-id(.)}" />
      </fo:block>
      <!-- other header stuff -->
    </fo:marker>

    <fo:marker marker-class-name="footfields">
      <!-- footer stuff -->
    </fo:marker>

    <xsl:for-each select="detail">
      <fo:block>
        <xsl:value-of select="spec" />
      </fo:block>
    </xsl:for-each>
    <fo:block id="{generate-id(.)}" />
  </xsl:template>
</xsl:stylesheet>


What I want now, but fail to accomplish, is:
Only on the last page of every invoice, there must be an extra field in the
footer with, say, the contents of batch.invoice.id
Have you any hints or directions?


Thanks in advance,
Arjan

Current Thread