Search code examples
xsltxslt-1.0xsl-foapache-fop

Prevent blank page on last side in xsl fo


i'm using xsl fo and apache fop to generate pdf documents. i have different fo page-sequences (coverpage, toc, imprint and the "main content").

In the main content i handle the datas from the xml file, it's fine.

At the beginning of the main content i started count the pages and show this in the bottom/right. With this i had a problem that it show a blank page before the "main content", i could resolve this issue with adding "force-page-count="no-force" on the page-sequence before.

But i have a blank page after the main-content sequence, any idea how can i solve this?

page-sequence before main-content:

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

main-content:

<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>

Any suggestions?

Thanks.


Solution

  • OK, i solve it. i do the following steps.

    1. i put the for each loop outside of the page-sequence.
    2. then i enclose the sequence with an xsl:choose, in the xsl:choose i check the position
    3. with the result i call the template page-sequence and -> "st.table" template
    4. in the template (st.table) i check the result and if it the last position i set the lastpage and i prevent to set the page-break-after property (this was the reason why i get a blank page at the end)

    page-sequence:

    <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>
    

    template:

    <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>