使用Apache-fop1.0也尝试了2.1的相同行为。
我的问题:
设想情况:
使用下面的XSL fop,偶尔会在页面流的末尾插入一个空的页面。这也会导致奇怪的页面编号,就像3页的第4页一样。
这是3个不同的页面序列,每个序列的页码应该从1开始,第一个应该添加类似于封面的内容。第二页序列应在第一页、最后一页和其他页上使用不同的页脚呈现一些表数据。第三个页面序列应该表示类似于页面序列2的副本,具有相同的输出,但实际上具有稍微不同的页眉和/或页脚。
但是,在每个序列末尾的--一个空的空白页--被插入--除了最后一个页面--序列。
每个页面序列本身(其他注释掉的)工作正常,而不生成空页。
我的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>我的XML有一些简单的数据
<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>
空页(红色)后的最后一页-序列2(蓝色),

发布于 2017-04-26 18:43:14
很难接受。如果是“自动”,则页序列上的强制页计数将“强制它为偶数页,如果下一页序列的初始页码为奇数”w3c。
因此,由于你的第三页序列有初始页码1(奇数),但第二页的最后一页实际上是5(如果省略第一页的话)(也是奇数),所以会添加一页,显然不把它当作最后一页(不太好)。它将显示3的第4页(因为它是第4页)(因为引用的id在第3页上)。
它的方法是添加一个
force-page-count="no-force"
属性设置为fo:page-sequence的
编辑
如果您还有一个没有页眉或页脚的blank-or-not-blank="blank"条件页面主引用,那么添加的页面上就不会出现页码。但我知道你一点都不想要。
https://stackoverflow.com/questions/43639741
复制相似问题