在我的XSL-FO中: 我需要在页脚中显示页码。
我需要什么:
当两个表应位于不同的页面上时,将这些页面编号显示为2a和2b,否则当两个表格应位于一个页面上时,显示第2页。
我还需要额外的<fo:simple-page-master>
和<fo:conditional-page-master-reference>
吗?如果是这样,我不知道如何组织它,也不知道如何将页码显示为2a和2b。我知道您可以将其用于字母:<fo:page-number format="a"/>
。
此XML标志确定应打印的内容。如果&#34; 1&#34;在这里,然后应该打印第2a和2b页,如果&#34; 0&#34;在这里,然后应该打印第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"> </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"> </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>
答案 0 :(得分:3)
根据@Jean-François Savard建议,我已将<fo:retrieve-marker>
和<fo:marker>
添加到我的代码中。
请注意,在生成的FO文件中,每个<fo:marker>
必须是<fo:block>
的第一个孩子,否则您将收到错误"fo:marker" must be declared before "(%block;)"
。
我的问题已经解决:它正在按照我想要的方式运行,页面 2 或页面 2a 和 2b 正常显示。< / p>
<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"> </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"> </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>