xslt - XSL-FO :repeatable-page-master-alternatives not working properly

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

感谢您的回答。

最佳答案

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

相关文章:

asp.net - 与标准 MVC3 View 语法相比,XSL 有哪些优势?

xml - xsl :for-each loop counter

javascript - XSL FO 如何处理 javascript 脚本?

xslt - xsl - 格式编号从一位到两位数字 1 => 01

xml - 根据属性值 XSLT 更改元素名称

xml - XSL 检查以查看是否有任何子节点具有属性

javascript - AngularJS:自定义指令不适用于 dirPagination

Java 与分页

android - 如何在两个 View 之间的确切位置滚动用户。?

xsl-fo - XSL :FO, 在 F.O.P 中 float