Using apache-fop 1.0 also tried 2.1 with the same behaviour.
My Questions:
- Why is the empty page generated?
- How can the page numbering be as weird as Page 4 of 3?
- How can I omit the empty page, while keeping the page numbering?
The Scenario:
Using the following XSL fop inserts occasionally an empty page at the end of the page flow. This also leads to strange page numbering like Page 4 of 3 Pages.
The are 3 different page-sequences and for each sequence the page numbering should start with 1. The first should just add something like a cover page. The second page-sequence should render some table data using different footers on first-page, last-page and others. The third page-sequence should represent something like a copy of page-sequence two, having the same output but in reality having slightly different headers and/or footers.
However, at the end of each sequence an empty blank page is insert - except for the last page-sequence.
Each page-sequence for itself (the others commented out) is working fine, without generating the empty page.
My XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Format http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop/src/foschema/fop.xsd?view=co">
<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-cover"
page-width="210mm" page-height="297mm" margin="1cm">
<fo:region-body region-name="body"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="A4-first"
page-width="210mm" page-height="297mm" margin="1cm">
<fo:region-body region-name="body" space-before="11cm" space-after="3cm"/>
<fo:region-before region-name="header-first" extent="11cm"/>
<fo:region-after region-name="footer-first" extent="3cm"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="A4-other"
page-width="210mm" page-height="297mm" margin="1cm">
<fo:region-body region-name="body" space-before="3cm" space-after="5cm"/>
<fo:region-before region-name="header-other" extent="3cm"/>
<fo:region-after region-name="footer-other" extent="5cm"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="A4-last"
page-width="210mm" page-height="297mm" margin="1cm">
<fo:region-body region-name="body" space-before="3cm" space-after="5cm"/>
<fo:region-before region-name="header-last" extent="3cm"/>
<fo:region-after region-name="footer-last" extent="5cm"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="A4-multi">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference page-position="first" master-reference="A4-first"/>
<fo:conditional-page-master-reference page-position="rest" master-reference="A4-other"/>
<fo:conditional-page-master-reference page-position="last" master-reference="A4-last"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
<fo:page-sequence-master master-name="A4-very-first">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference page-position="first" master-reference="A4-cover"/>
<fo:conditional-page-master-reference page-position="rest" master-reference="A4-other"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-very-first" initial-page-number="1">
<fo:flow flow-name="body">
<fo:block>just the first page</fo:block>
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="A4-multi" initial-page-number="1">
<xsl:call-template name="header-first"/>
<xsl:call-template name="header-other"/>
<xsl:call-template name="header-last"/>
<xsl:call-template name="footer-first"/>
<xsl:call-template name="footer-other"/>
<xsl:call-template name="footer-last"/>
<xsl:call-template name="flow-1"/>
</fo:page-sequence>
<fo:page-sequence master-reference="A4-multi" initial-page-number="1">
<xsl:call-template name="header-first"/>
<xsl:call-template name="header-other"/>
<xsl:call-template name="header-last"/>
<xsl:call-template name="footer-first"/>
<xsl:call-template name="footer-other"/>
<xsl:call-template name="footer-last"/>
<xsl:call-template name="flow-2"/>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template name="flow-1">
<fo:flow flow-name="body">
<xsl:call-template name="item-table"/>
<fo:block id="last-page-flow-1"></fo:block>
</fo:flow>
</xsl:template>
<!-- just a copy of flow 1-->
<xsl:template name="flow-2">
<fo:flow flow-name="body">
<xsl:call-template name="item-table"/>
<fo:block id="last-page-flow-2"></fo:block>
</fo:flow>
</xsl:template>
<!-- table -->
<xsl:template name="item-table">
<fo:table width="100%" border="1px solid black" table-layout="fixed">
<fo:table-column column-width="proportional-column-width(1)"/>
<fo:table-header>
<fo:table-row border="1px solid red">
<fo:table-cell>
<fo:block>Item: header</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-footer>
<fo:table-row>
<fo:table-cell border="1px solid blue">
<fo:block>Item: footer</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-footer>
<fo:table-body>
<xsl:apply-templates select="list"/>
</fo:table-body>
</fo:table>
</xsl:template>
<!-- row -->
<xsl:template match="item">
<fo:table-row>
<fo:table-cell border-bottom="1px dashed black">
<fo:block>
<xsl:value-of select="out"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
<!-- the different headers -->
<xsl:template name="header-initial">
<fo:static-content flow-name="header-initial">
<fo:table background-color="yellow" width="100%" table-layout="fixed">
<fo:table-body>
<fo:table-row>
<fo:table-cell height="4cm">
<fo:block>Header first page</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
</xsl:template>
<xsl:template name="header-first">
<fo:static-content flow-name="header-first">
<fo:table background-color="yellow" width="100%" table-layout="fixed">
<fo:table-body>
<fo:table-row>
<fo:table-cell height="11cm">
<fo:block>Header first page</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
</xsl:template>
<xsl:template name="header-other">
<fo:static-content flow-name="header-other">
<fo:table background-color="red" width="100%" table-layout="fixed">
<fo:table-body>
<fo:table-row>
<fo:table-cell height="3cm">
<fo:block>Header other pages</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
</xsl:template>
<xsl:template name="header-last">
<fo:static-content flow-name="header-last">
<fo:table background-color="blue" width="100%" table-layout="fixed">
<fo:table-body>
<fo:table-row>
<fo:table-cell height="3cm">
<fo:block>Header last page</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
</xsl:template>
<!-- the different footers -->
<xsl:template name="footer-initial">
<fo:static-content flow-name="footer-initial">
<fo:table background-color="orange" width="100%" table-layout="fixed">
<fo:table-body>
<fo:table-row>
<fo:table-cell height="106mm">
<fo:block>Footer initial page - ESR</fo:block>
<fo:block>P<fo:page-number/>/
<fo:page-number-citation-last ref-id="last-page-flow-1"/>
<fo:page-number-citation-last ref-id="last-page-flow-2"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
</xsl:template>
<xsl:template name="footer-first">
<fo:static-content flow-name="footer-first">
<fo:table background-color="yellow" width="100%" table-layout="fixed">
<fo:table-body>
<fo:table-row>
<fo:table-cell height="3cm">
<fo:block>Footer first page</fo:block>
<fo:block>Page
<fo:page-number/>
of
<fo:page-number-citation-last ref-id="last-page-flow-1"/>
<fo:page-number-citation-last ref-id="last-page-flow-2"/>
Pages
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
</xsl:template>
<xsl:template name="footer-other">
<fo:static-content flow-name="footer-other">
<fo:table background-color="red" width="100%" table-layout="fixed">
<fo:table-body>
<fo:table-row>
<fo:table-cell height="5cm">
<fo:block>Footer other pages</fo:block>
<fo:block>Page
<fo:page-number/>
of
<fo:page-number-citation-last ref-id="last-page-flow-1"/>
<fo:page-number-citation-last ref-id="last-page-flow-2"/>
Pages
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
</xsl:template>
<xsl:template name="footer-last">
<fo:static-content flow-name="footer-last">
<fo:table background-color="blue" width="100%" table-layout="fixed">
<fo:table-body>
<fo:table-row>
<fo:table-cell height="5cm">
<fo:block>Footer last page</fo:block>
<fo:block>Page<fo:page-number/>of
<fo:page-number-citation-last ref-id="last-page-flow-1"/>
<fo:page-number-citation-last ref-id="last-page-flow-2"/>
Pages
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
</xsl:template>
</xsl:stylesheet>
My XML with some simple data
<list>
<item>
<out>Test1</out>
</item>
<item>
<out>Test2</out>
</item>
<item>
<out>Test3</out>
</item>
<item>
<out>Test4</out>
</item>
<item>
<out>Test5</out>
</item>
<item>
<out>Test6</out>
</item>
<item>
<out>Test7</out>
</item>
<item>
<out>Test8</out>
</item>
<item>
<out>Test9</out>
</item>
<item>
<out>Test10</out>
</item>
<item>
<out>Test11</out>
</item>
<item>
<out>Test12</out>
</item>
<item>
<out>Test13</out>
</item>
<item>
<out>Test14</out>
</item>
<item>
<out>Test15</out>
</item>
<item>
<out>Test16</out>
</item>
<item>
<out>Test17</out>
</item>
<item>
<out>Test18</out>
</item>
<item>
<out>Test19</out>
</item>
<item>
<out>Test20</out>
</item>
<item>
<out>Test21</out>
</item>
<item>
<out>Test22</out>
</item>
<item>
<out>Test23 -- last on page-first</out>
</item>
<!-- max items on first page -->
<item>
<out>Test24 -- first on page-other/page-last</out>
</item>
<item>
<out>Test25</out>
</item>
<item>
<out>Test26</out>
</item>
<item>
<out>Test27</out>
</item>
<item>
<out>Test28</out>
</item>
<item>
<out>Test29</out>
</item>
<item>
<out>Test30</out>
</item>
<item>
<out>Test31</out>
</item>
<item>
<out>Test32</out>
</item>
<item>
<out>Test33</out>
</item>
<item>
<out>Test34</out>
</item>
<item>
<out>Test35</out>
</item>
<item>
<out>Test36</out>
</item>
<item>
<out>Test37</out>
</item>
<item>
<out>Test38</out>
</item>
<item>
<out>Test39</out>
</item>
<item>
<out>Test40</out>
</item>
<item>
<out>Test41</out>
</item>
<item>
<out>Test42</out>
</item>
<item>
<out>Test43</out>
</item>
<item>
<out>Test44</out>
</item>
<item>
<out>Test45</out>
</item>
<item>
<out>Test46</out>
</item>
<item>
<out>Test47</out>
</item>
<item>
<out>Test48</out>
</item>
<item>
<out>Test49</out>
</item>
<item>
<out>Test50</out>
</item>
<item>
<out>Test51</out>
</item>
<item>
<out>Test52</out>
</item>
<item>
<out>Test53</out>
</item>
<item>
<out>Test54</out>
</item>
<item>
<out>Test55</out>
</item>
<item>
<out>Test56</out>
</item>
<item>
<out>Test57 - last on page-other</out>
</item>
<item>
<out>Test58 -first on page-last</out>
</item>
Empty Page (red) after last page of page-sequence two (blue),
<fo:block id="last-page-flow-23">
probably ..-flow-2? - What fop version are you using? – Stefan Hegny