【问题标题】:XSL-FO fo:repeatable-page-master-alternatives not working properlyXSL-FO fo:repeatable-page-master-alternatives 无法正常工作
【发布时间】:2019-04-11 02:30:15
【问题描述】:

如果页数超过一页,我想在页脚中添加页码,但如果只有一页,则不添加。

我尝试了以下代码,但它在所有情况下都显示页码:

<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

感谢您的回答。

【问题讨论】:

    标签: xslt pagination xsl-fo apache-fop


    【解决方案1】:

    您的第二种选择对我来说适用于 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>
    

    您是否尝试了足够的内容来制作第二页?例如,添加 &lt;fo:block break-before="page"&gt;content&lt;/fo:block&gt; 以强制打开第二个页面。

    如果您将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) 不满足它的约束(我强调):

    如果(a)页面的子序列由零个或多个页面组成,(b)每个页面是使用作为 fo:repeatable-page-master-alternatives 的子项的备选方案之一引用的 fo:simple-page-master 生成,(c) 该备选方案的条件为真 , (d) 该备选方案是所有条件都为真的子序列中的第一个备选方案,并且 (e) 子序列的长度小于或等于“最大重复次数”的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 2016-12-01
      相关资源
      最近更新 更多