XSL-FO 页码 2a、2b

XSL-FO page-number 2a, 2b

在我的 XSL-FO 中: 我需要在页脚中显示页码。

我需要:
当两个 table 应该在不同的页面上时,将这些页码显示为 2a 和 2b,否则当两个 table 应该在一页上时,显示第 2 页。

为此我需要额外的 <fo:simple-page-master><fo:conditional-page-master-reference> 吗?如果是这样,我不确定如何组织它,也不知道如何获得显示为 2a 和 2b 的页码。我知道您可以将其用于字母:<fo:page-number format="a"/>.

这个 XML 标志决定了应该打印什么。如果此处为“1”,则应打印第 2a 和 2b 页,如果此处为“0”,则应打印第 2 页。

<PAGE2FLAG>1</PAGE2FLAG>

感谢您的帮助!

这是我的样式表:

<xslt:stylesheet xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xslt:output method="xml" indent="yes" encoding="utf-8"/>
<xslt:param name="XFTemplateName">Document</xslt:param>
<xsl:template match="/">
    <fo:root>
        <fo:layout-master-set>
            <fo:simple-page-master master-name="first-page" page-width="8.5in" page-height="11in">
                <fo:region-body region-name="xsl-region-body" column-count="2" margin="0.4in 0.4in 0.4in 0.4in"/>
                <fo:region-before region-name="xsl-region-before" display-align="after" extent="0.7in"/>
                <fo:region-after region-name="xsl-region-after" extent="0.7in"/>
                <fo:region-start region-name="xsl-region-start" extent="0.7in"/>
                <fo:region-end region-name="xsl-region-end" extent="0.7in"/>
            </fo:simple-page-master>
            <fo:simple-page-master master-name="other-page" page-width="8.5in" page-height="11in">
                <fo:region-body region-name="xsl-region-body" column-count="2" margin="0.4in 0.4in 0.4in 0.4in"/>
                <fo:region-before region-name="xsl-region-before" display-align="after" extent="0.7in"/>
                <fo:region-after region-name="xsl-region-after-other" extent="0.7in"/>
                <fo:region-start region-name="xsl-region-start" extent="0.7in"/>
                <fo:region-end region-name="xsl-region-end" extent="0.7in"/>
            </fo:simple-page-master>                
            <fo:page-sequence-master master-name="default">
                <fo:repeatable-page-master-alternatives maximum-repeats="no-limit">
                    <fo:conditional-page-master-reference page-position="first" master-reference="first-page"/>
                    <fo:conditional-page-master-reference master-reference="other-page"/>
                </fo:repeatable-page-master-alternatives>
            </fo:page-sequence-master>
        </fo:layout-master-set>
        <fo:page-sequence master-reference="default" font-family="Helvetica">
            <fo:static-content flow-name="xsl-region-before">
                <fo:block start-indent="-20.000pt" end-indent="-20.000pt">&#xa0;</fo:block>
            </fo:static-content>
            <xslt:comment> FIRST PAGE ONLY FOOTER </xslt:comment>
            <fo:static-content flow-name="xsl-region-after">
                <fo:block start-indent="-20.000pt" end-indent="-20.000pt">
                    <fo:block text-align-last="justify">
                        <fo:inline font-size="8pt">DOCUMENT</fo:inline>
                        <fo:inline font-size="14pt">
                            <xslt:comment> BARCODE GOES HERE </xslt:comment>
                        </fo:inline>
                        <fo:leader leader-pattern="space"/>
                        <fo:inline font-size="8pt">
                            PAGE <fo:page-number format="1"/> OF 5                  
                            · FORM ID #<xsl:value-of select="XMLDOC/FORMID"/>
                        </fo:inline>
                    </fo:block>
                </fo:block>
            </fo:static-content>
            <xslt:comment> ALL OTHER PAGES FOOTER </xslt:comment>
            <fo:static-content flow-name="xsl-region-after-other">
                <fo:block start-indent="-20.000pt" end-indent="-20.000pt">
                    <fo:block text-align-last="justify">
                        <fo:inline font-size="8pt">DOCUMENT</fo:inline> 
                        <fo:inline font-size="14pt">&#xa0;</fo:inline>
                        <fo:leader leader-pattern="space"/>
                        <fo:inline font-size="8pt">
                            PAGE <fo:page-number format="1"/> OF 5              
                            · FORM ID #<xsl:value-of select="XMLDOC/FORMID"/>
                        </fo:inline>
                    </fo:block>
                </fo:block>
            </fo:static-content>                
            <fo:static-content flow-name="xsl-region-start">
                <fo:block> </fo:block>
            </fo:static-content>
            <fo:static-content flow-name="xsl-region-end">
                <fo:block> </fo:block>
            </fo:static-content>
            <fo:flow flow-name="xsl-region-body">
                <fo:block>
                    <xslt:comment> THIS IS PAGE 1 </xslt:comment>
                </fo:block>
                <fo:block break-before="page"/>

                <fo:block>
                    <fo:table>
                        <xslt:comment> PAGE 2 (First Table) </xslt:comment>
                    </fo:table>                     
                </fo:block>

                <xsl:if test="XMLDOC/PAGE2FLAG = 1">
                    <xslt:comment> This IF and BREAK separates the two tables into two pages. </xslt:comment>
                    <xslt:comment> These are the two pages that I want Page 2a and Page 2b. </xslt:comment>
                    <xslt:comment> In my printout, they are being shown as Page 2 and Page 3. </xslt:comment>
                    <fo:block break-before="page"/>
                </xsl:if>                   

                <fo:block>
                    <fo:table>
                        <xslt:comment> PAGE 2 (Second Table) </xslt:comment>
                    </fo:table>                     
                </fo:block>

                <fo:block break-before="page"/>                 
                <fo:block>
                    <xslt:comment> THIS IS PAGE 3 </xslt:comment>
                </fo:block>

                <fo:block break-before="page"/>                     
                <fo:block>
                    <xslt:comment> THIS IS PAGE 4 </xslt:comment>
                </fo:block>

                <fo:block break-before="page"/>                 
                <fo:block>
                    <xslt:comment> THIS IS PAGE 5 </xslt:comment>
                </fo:block>             
            </fo:flow>
        </fo:page-sequence>
    </fo:root>
</xsl:template>

根据 @Jean-François Savard 的建议,我已将 <fo:retrieve-marker><fo:marker> 添加到我的代码中。

请注意,在生成的 FO 文件中,每个 <fo:marker> 必须是 第一个 child<fo:block>,否则您将得到错误 "fo:marker" must be declared before "(%block;)".

我的问题已经解决:它按照我想要的方式工作,页面 2 或页面 2a2b 正确显示。

<xslt:stylesheet xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xslt:output method="xml" indent="yes" encoding="utf-8"/>
<xslt:param name="XFTemplateName">Document</xslt:param>
<xsl:template match="/">
    <fo:root>
        <fo:layout-master-set>
            <fo:simple-page-master master-name="first-page" page-width="8.5in" page-height="11in">
                <fo:region-body region-name="xsl-region-body" column-count="2" margin="0.4in 0.4in 0.4in 0.4in"/>
                <fo:region-before region-name="xsl-region-before" display-align="after" extent="0.7in"/>
                <fo:region-after region-name="xsl-region-after" extent="0.7in"/>
                <fo:region-start region-name="xsl-region-start" extent="0.7in"/>
                <fo:region-end region-name="xsl-region-end" extent="0.7in"/>
            </fo:simple-page-master>
            <fo:simple-page-master master-name="other-page" page-width="8.5in" page-height="11in">
                <fo:region-body region-name="xsl-region-body" column-count="2" margin="0.4in 0.4in 0.4in 0.4in"/>
                <fo:region-before region-name="xsl-region-before" display-align="after" extent="0.7in"/>
                <fo:region-after region-name="xsl-region-after-other" extent="0.7in"/>
                <fo:region-start region-name="xsl-region-start" extent="0.7in"/>
                <fo:region-end region-name="xsl-region-end" extent="0.7in"/>
            </fo:simple-page-master>                
            <fo:page-sequence-master master-name="default">
                <fo:repeatable-page-master-alternatives maximum-repeats="no-limit">
                    <fo:conditional-page-master-reference page-position="first" master-reference="first-page"/>
                    <fo:conditional-page-master-reference master-reference="other-page"/>
                </fo:repeatable-page-master-alternatives>
            </fo:page-sequence-master>
        </fo:layout-master-set>
        <fo:page-sequence master-reference="default" font-family="Helvetica">
            <fo:static-content flow-name="xsl-region-before">
                <fo:block start-indent="-20.000pt" end-indent="-20.000pt">&#xa0;</fo:block>
            </fo:static-content>
            <xslt:comment> FIRST PAGE ONLY FOOTER </xslt:comment>
            <fo:static-content flow-name="xsl-region-after">
                <fo:block start-indent="-20.000pt" end-indent="-20.000pt">
                    <fo:block text-align-last="justify">
                        <fo:inline font-size="8pt">DOCUMENT</fo:inline>
                        <fo:inline font-size="14pt">
                            <xslt:comment> BARCODE GOES HERE </xslt:comment>
                        </fo:inline>
                        <fo:leader leader-pattern="space"/>
                        <fo:inline font-size="8pt">
                            PAGE <fo:retrieve-marker retrieve-class-name="page_number"/> OF 5
                        </fo:inline>
                    </fo:block>
                </fo:block>
            </fo:static-content>
            <xslt:comment> ALL OTHER PAGES FOOTER </xslt:comment>
            <fo:static-content flow-name="xsl-region-after-other">
                <fo:block start-indent="-20.000pt" end-indent="-20.000pt">
                    <fo:block text-align-last="justify">
                        <fo:inline font-size="8pt">DOCUMENT</fo:inline> 
                        <fo:inline font-size="14pt">&#xa0;</fo:inline>
                        <fo:leader leader-pattern="space"/>
                        <fo:inline font-size="8pt">
                            PAGE <fo:retrieve-marker retrieve-class-name="page_number"/> OF 5
                        </fo:inline>
                    </fo:block>
                </fo:block>
            </fo:static-content>                
            <fo:static-content flow-name="xsl-region-start">
                <fo:block> </fo:block>
            </fo:static-content>
            <fo:static-content flow-name="xsl-region-end">
                <fo:block> </fo:block>
            </fo:static-content>
            <fo:flow flow-name="xsl-region-body">
                <fo:marker marker-class-name="page_number">1</fo:marker>
                <fo:block>
                    <xslt:comment> THIS IS PAGE 1 </xslt:comment>
                </fo:block>
                <fo:block break-before="page"/>

                <fo:block>
                    <xsl:if test="XMLDOC/PAGE2FLAG = 0">
                        <fo:marker marker-class-name="page_number">2</fo:marker>
                    </xsl:if>
                    <xsl:if test="XMLDOC/PAGE2FLAG = 1">
                        <fo:marker marker-class-name="page_number">2a</fo:marker>
                    </xsl:if>
                    <fo:table>
                        <xslt:comment> PAGE 2 (First Table) </xslt:comment>
                    </fo:table>                     
                </fo:block>

                <xsl:if test="XMLDOC/PAGE2FLAG = 1">
                    <xslt:comment> This IF and BREAK separates the two tables into two pages. </xslt:comment>
                    <xslt:comment> These are the two pages that I want Page 2a and Page 2b. </xslt:comment>
                    <xslt:comment> In my printout, they are being shown as Page 2 and Page 3. </xslt:comment>
                    <fo:block break-before="page"/>
                </xsl:if>                   

                <fo:block>
                    <xsl:if test="XMLDOC/PAGE2FLAG = 0">
                        <fo:marker marker-class-name="page_number">2</fo:marker>
                    </xsl:if>
                    <xsl:if test="XMLDOC/PAGE2FLAG = 1">
                        <fo:marker marker-class-name="page_number">2b</fo:marker>
                    </xsl:if>
                    <fo:table>
                        <xslt:comment> PAGE 2 (Second Table) </xslt:comment>
                    </fo:table>                     
                </fo:block>

                <fo:block break-before="page"/>                 
                <fo:block>
                    <fo:marker marker-class-name="page_number">3</fo:marker>
                    <xslt:comment> THIS IS PAGE 3 </xslt:comment>
                </fo:block>

                <fo:block break-before="page"/>
                    <fo:marker marker-class-name="page_number">4</fo:marker>
                    <xslt:comment> THIS IS PAGE 4 </xslt:comment>
                </fo:block>

                <fo:block break-before="page"/>
                    <fo:marker marker-class-name="page_number">5</fo:marker>
                    <xslt:comment> THIS IS PAGE 5 </xslt:comment>
                </fo:block>             
            </fo:flow>
        </fo:page-sequence>
    </fo:root>
</xsl:template>