在xsl fo中防止最后一侧的空白页

时间:2014-09-24 07:02:40

标签: xslt xslt-1.0 xsl-fo apache-fop

我使用xsl fo和apache fop生成pdf文档。我有不同的页面序列(封面,toc,印记和"主要内容")。

在主要内容中我处理xml文件中的数据,没问题。

在主要内容的开头,我开始计算页面并在底部/右侧显示。有了这个我有一个问题,它在"主要内容"之前显示一个空白页面,我可以通过添加" force-page-count =" no-force&#34来解决这个问题;在页面序列之前。

但是我在主要内容序列之后有一个空白页面,任何想法如何解决这个问题?

主要内容之前的页面序列:

<fo:page-sequence master-reference="imprint" force-page-count="no-force">
...
</fo:page-sequence>

主要含量:

<fo:page-sequence master-reference="per-Gruppe" initial-page-number="1">
                <fo:static-content flow-name="header">
                    <xsl:call-template name="doc-header" match=""/>
                    <fo:block/>
                </fo:static-content>
                <fo:static-content flow-name="footer">
                    <xsl:call-template name="doc-footer"/>
                    <fo:block/>
                </fo:static-content>
                <fo:flow flow-name="xsl-region-body">
                    <xsl:for-each select="//lb">
                        <xsl:call-template name="Kapitel" select="name"/>
                        <xsl:for-each select="per-group/pe">
                            <xsl:call-template name="st.Table" select="."/>
                        </xsl:for-each>
                        <xsl:for-each select="cu-group/cu">
                            <xsl:call-template name="st.Table" select="."/>
                        </xsl:for-each>
                        <xsl:if test="position()=last()">
                            <fo:block id="lastpage"/>
                        </xsl:if>
                    </xsl:for-each>
                </fo:flow>
            </fo:page-sequence>

有什么建议吗?

感谢。

1 个答案:

答案 0 :(得分:3)

好的,我解决了。我执行以下步骤。

  1. 我把每个循环放在页面序列之外。
  2. 然后我用xsl:选择,在xsl中选择序列:选择我检查位置
  3. 结果我调用模板页面序列和 - &gt; “st.table”模板
  4. 在模板(st.table)中我检查结果,如果它是最后一个位置我设置了lastpage并且我阻止设置page-break-after属性(这就是为什么我得到一个空白页面的原因端)
  5. 页面序列:

    <xsl:for-each select="//lb">
                    <xsl:choose>
                        <xsl:when test="position() = 1">
                            <fo:page-sequence master-reference="per-Gruppe" initial-page-number="1">
                                ...
                            </fo:page-sequence>
                        </xsl:when>
                        <xsl:otherwise>
                            <fo:page-sequence master-reference="per-Gruppe">
                                ...
                                <fo:flow flow-name="xsl-region-body">
                                    ...
                                    <xsl:for-each select="cu-group/cu">
                                        <xsl:call-template name="st.Table" select=".">
                                            <xsl:with-param name="last_pos" select="$last_pos" />
                                        </xsl:call-template>
                                    </xsl:for-each>
                                </fo:flow>
                            </fo:page-sequence>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:for-each>
    

    模板:

    <xsl:template name="st.Table" match=".">
            <xsl:param name="last_pos" select="false()" />
            ...
            <xsl:if test="$last_pos">
                <fo:block id="lastpage"/>       
            </xsl:if>
            <xsl:if test="$last_pos=false()">
                <fo:block page-break-after="always" />
            </xsl:if>
        </xsl:template>