如果页数超过一页,我想在页脚中添加页码,但如果只有一页,则不添加页码。
我尝试了以下代码,但它在所有情况下都显示页码:
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="singlePage" page-height="800pt" page-width="612pt" margin-top="0pt" margin-bottom="46pt" margin-left="26pt" margin-right="26pt">
<fo:region-body margin-top="110pt" margin-bottom="65pt" />
<fo:region-before extent="72pt" />
<fo:region-after region-name="xsl-region-after-single" extent="75pt" />
</fo:simple-page-master>
<fo:simple-page-master master-name="multiPage" page-height="800pt" page-width="612pt" margin-top="0pt" margin-bottom="46pt" margin-left="26pt" margin-right="26pt">
<fo:region-body margin-top="110pt" margin-bottom="65pt" />
<fo:region-before extent="72pt" />
<fo:region-after region-name="xsl-region-after-multi" extent="75pt" />
</fo:simple-page-master>
<fo:page-sequence-master master-name="allPages">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference page-position="any" master-reference="multiPage"/>
<fo:conditional-page-master-reference page-position="only" master-reference="singlePage"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="allPages">
<fo:static-content flow-name="xsl-region-before">
<fo:block>content</fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after-single">
<fo:block>content</fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after-multi">
<fo:block>content</fo:block>
<fo:block text-align="right">
<fo:inline><fo:page-number font-weight="normal"/>/<fo:page-number-citation ref-id = "lastPage"/></fo:inline>
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body" font-size="12pt" line-height="11pt">
<fo:block>content</fo:block>
<fo:block id = "lastPage"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
如果我更改替代项的顺序,则永远不会显示页码:
<fo:page-sequence-master master-name="allPages">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference page-position="only" master-reference="singlePage"/>
<fo:conditional-page-master-reference page-position="any" master-reference="multiPage"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
我正在使用 FOP 2.0
感谢您的回答。
最佳答案
你的第二种选择对我来说适用于 FOP 2.0 和 FOP 2.2:
<fo:page-sequence-master master-name="allPages">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference page-position="only" master-reference="singlePage"/>
<fo:conditional-page-master-reference page-position="any" master-reference="multiPage"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
您尝试使用足够的内容制作第二页了吗?例如,添加 <fo:block break-before="page">content</fo:block>
强制第二页。
如果您更改 fo:static-content
中的“内容”文本对于 fo:region-after
然后你会更好地了解哪个fo:conditional-page-master-reference
正在使用;例如:
<fo:static-content flow-name="xsl-region-after-single">
<fo:block>after single</fo:block>
</fo:static-content>
fo:conditional-page-master-reference
的方式( https://www.w3.org/TR/xsl11/#fo_conditional-page-master-reference ) 的工作原理是,如果它是所有子条件都为真的第一个备选方案,它就会被选中。如果有足够的内容制作第二页,则 page-position="only"
子条件不再为真,因此格式化程序应使用其他替代方案重试。
格式化程序应该再试一次,因为如果没有,那么 fo:repeatable-page-master-alternatives
( https://www.w3.org/TR/xsl11/#fo_repeatable-page-master-alternatives ) 不满足其约束条件(我强调):
The sub-sequence of pages mapped to this sub-sequence-specifier satisfies the constraints of this sub-sequence-specifier if (a) the sub-sequence of pages consists of zero or more pages, (b) each page is generated using the fo:simple-page-master referenced by the one of the alternatives that are the children of the fo:repeatable-page-master-alternatives, (c) the conditions on that alternative are true, (d) that alternative is the first alternative in the sequence of children for which all the conditions are true, and (e) the length of the sub-sequence is less than or equal to the value of 'maximum-repeats'.
关于xslt - XSL-FO :repeatable-page-master-alternatives not working properly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53193217/