XSL-FO fo:repeatable-page-master-alternatives 无法正常工作 [英] XSL-FO fo:repeatable-page-master-alternatives not working properly

查看:22
本文介绍了XSL-FO fo:repeatable-page-master-alternatives 无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to add the page number in footer if the number of pages is more than one, but not for if there is only one page.

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

I tried the following code but it shows the page number in all cases :

<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>

如果我更改选项的顺序,则永远不会显示页码:

If I change the order of alternatives, then page number is never shown:

<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

I'm using FOP 2.0

感谢您的回答.

推荐答案

您的第二个替代方案适用于 FOP 2.0 和 FOP 2.2:

Your second alternative works for me with both FOP 2.0 and 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> 以强制第二页.

Did you try it with enough content to make a second page? E.g., add <fo:block break-before="page">content</fo:block> to force a second page.

如果您将 fo:static-content 中的内容"文本更改为 fo:region-after,那么您将更好地了解哪个 fo:conditional-page-master-reference 正在使用;例如:

If you change the 'content' text in your fo:static-content for the fo:region-after then you'll get a better idea of which fo:conditional-page-master-reference is being used; e.g.:

<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" 子条件不再为真,因此格式化程序应使用其他替代方法重试.

The way that fo:conditional-page-master-reference (https://www.w3.org/TR/xsl11/#fo_conditional-page-master-reference) works is that it is selected if it is the first alternative for which all of its sub-conditions are true. If there is enough content to make a second page, then the page-position="only" sub-condition is no longer true, so the formatter should try again with other alternatives.

格式化程序应该再试一次,因为如果没有,那么 fo:repeatable-page-master-alternatives (https://www.w3.org/TR/xsl11/#fo_repeatable-page-master-alternatives) 不满足它的约束(我的重点):

The formatter should try again because if it doesn't, then the fo:repeatable-page-master-alternatives (https://www.w3.org/TR/xsl11/#fo_repeatable-page-master-alternatives) doesn't satisfy its constraints (my emphasis):

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

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'.

这篇关于XSL-FO fo:repeatable-page-master-alternatives 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆