如何在最后一页上创建页脚

时间:2019-06-26 14:51:02

标签: xml xslt xslt-2.0 xsl-fo apache-fop

这是干净的代码:

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <fo:layout-master-set>
        <fo:simple-page-master
                master-name="pages-normale"
                page-width="297mm"
                page-height="210mm"
                margin-top="0.5cm"
                margin-bottom="0.5cm"
                margin-left="0.5cm"
                margin-right="0.5cm">
            <fo:region-body   margin-top="1cm" margin-bottom="1cm"/>
            <fo:region-before margin-top="1cm" margin-bottom="1cm" extent="7cm"/>
            <fo:region-after  margin-top="1cm" margin-bottom="1cm" extent="1cm"/>
        </fo:simple-page-master>
    </fo:layout-master-set>
    <fo:page-sequence
            master-reference="pages-normale"
            initial-page-number="1"
            force-page-count="even"
            language="it"
            country="it">
        <fo:static-content flow-name="xsl-region-before">
            <fo:block>
                <fo:table  width="100%" border-width="0.5mm" margin-bottom="4mm" border-style="transparent">
                    <fo:table-column  column-width="50%"/>
                    <fo:table-column  column-width="50%"/>
                    <fo:table-header>
                        <fo:table-row>
                            <fo:table-cell border-style="normal">
                                <fo:block font-size="15" font-style="oblique" font-weight="bold">

                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell border-style="normal">
                                <fo:block font-size="8" font-weight="normal" text-align="right"/>
                            </fo:table-cell>
                        </fo:table-row>
                    </fo:table-header>
                    <fo:table-body>
                        <fo:table-row>
                            <fo:table-cell border-style="transparent">
                                <fo:block>
                                    <fo:block font-size="8" text-align="left" font-weight="normal" >
                                    </fo:block>
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell border-style="transparent">
                                <fo:block>
                                    <fo:block font-size="8" text-align="left" font-weight="normal" >
                                    </fo:block>
                                </fo:block>
                            </fo:table-cell>
                        </fo:table-row>             
                    </fo:table-body>
                </fo:table>
            </fo:block>
        </fo:static-content>
        <fo:static-content flow-name="xsl-region-after">
            <fo:block>
                <xsl:value-of select="intestazione2_1/cliente3"/>
            </fo:block>
        </fo:static-content>
        <fo:flow flow-name="xsl-region-body">
            <fo:block>

            </fo:block>
            <fo:block>

            </fo:block>
        </fo:flow>
    </fo:page-sequence>
</fo:root>

这是我尝试过的代码:

我是在版面母版上制作的:

<fo:layout-master-set>
    <fo:simple-page-master
                master-name="pages-normale"
                page-width="297mm"
                page-height="210mm"
                margin-top="0.5cm"
                margin-bottom="0.5cm"
                margin-left="0.5cm"
                margin-right="0.5cm">
        <fo:region-body   margin-top="1cm" margin-bottom="1cm"/>
        <fo:region-before region-name="normal-header" margin-top="1cm" margin-bottom="1cm" extent="7cm"/>
        <fo:region-after  region-name="normal-footer" margin-top="1cm" margin-bottom="1cm" extent="1cm"/>
    </fo:simple-page-master>
    <fo:page-sequence-master master-name="pages">
        <fo:repeatable-page-master-alternatives>
            <fo:conditional-page-master-reference master-reference="pages-last" page-position="last"/>
            <fo:conditional-page-master-reference master-reference="pages-normale" />
        </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>
</fo:layout-master-set>

并在以下代码上进行操作:

 <fo:page-sequence
        master-reference="pages-normale"

按照页面顺序执行此操作:

<fo:page-sequence force-page-count="no-force"
                    master-reference="pages" initial-page-number="auto"
                    format="1">
    <fo:static-content flow-name="normal-footer">
        <xsl:value-of select="intestazione2_1/cliente3"/>
    </fo:static-content>
</fo:page-sequence>

我尝试将这个页面序列放入<fo:page-sequence master-reference="pages-normale"中 但是错误是相同的。

这是FOP给我的错误:

  

在页面序列母版“ fo:repeatable-page-master-alternatives”中没有与“ pages-last”相匹配的简单页面母版。 (没有可用的上下文信息)

这是我遵循的建议:

1 个答案:

答案 0 :(得分:0)

除了您的<fo:simple-page-master master-name="pages-normale">外,您还需要定义<fo:simple-page-master master-name="pages-last">

在此母版中,您需要为最后一页<fo:region-after region-name="last-page-footer"定义一个具有唯一名称的页脚。然后,在页面序列中,可以添加<fo:static-content flow-name="last-page-footer">并添加要在该页脚中显示的信息。