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

查看:73
本文介绍了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:region-after fo:static-content 中更改内容"文本,则可以更好地了解哪个<使用code> 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 的方式(子条件不再成立,因此格式化程序应尝试使用其他替代方法.

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 (

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)子序列的长度小于或等于最大重复数"的值./p>

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天全站免登陆