XSL-FO fo:repeatable-page-master-alternatives无法正常工作

时间:2018-11-07 16:01:32

标签: xslt pagination 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="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

感谢您的回答。

1 个答案:

答案 0 :(得分: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的{​​{1}}中的“内容”文本更改为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> https://www.w3.org/TR/xsl11/#fo_conditional-page-master-reference)的工作方式是,如果它是所有子条件都为真的第一个替代方法,则选择它。如果有足够的内容制作第二页,则fo:conditional-page-master-reference子条件不再成立,因此格式化程序应尝试使用其他替代方法。

格式化程序应再试一次,因为如果不这样做,则page-position="only"https://www.w3.org/TR/xsl11/#fo_repeatable-page-master-alternatives)不能满足其约束(我强调):

  

如果(a)页面的子序列由零个或多个页面组成,(b)每个页面为,则映射到该子序列说明符的页面的子序列满足该子序列说明符的约束。使用fo:repeatable-page-master-alternatives的子项之一引用的fo:simple-page-master生成的(c)该替代项的条件为真 ,(d)替代方案是所有条件都成立的子项序列中的第一个替代方案,并且(e)子序列的长度小于或等于“最大重复数”的值。 / p>