You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XSL FO页面母版页眉页脚属性不生效问题咨询

XSL FO奇偶页页眉页脚文本属性不生效问题

在XSL Formatting Objects(XSL FO)中设置奇偶页不同的页脚文本对齐方式时,发现页面母版里<region-after>的text-align、text-indent等属性被忽略,所有页脚都显示为左对齐。使用的代码如下:

<?xml version="1.0" encoding="UTF-8"?>

<root xmlns="http://www.w3.org/1999/XSL/Format">
    <layout-master-set>
        <!-- Define master for odd pages -->
        <simple-page-master master-name="odd-page" page-width="8.5in" page-height="11in" margin="1in">
            <region-body margin="1in"/>
            <region-before extent="1in"/>
            <region-after extent="1in" text-align="left" text-indent="10%"/>
        </simple-page-master>
        
        <!-- Define master for even pages -->
        <simple-page-master master-name="even-page" page-width="8.5in" page-height="11in" margin="1in">
            <region-body margin="1in"/>
            <region-before extent="1in"/>
            <region-after extent="1in" text-align="right" text-indent="50%"/>
        </simple-page-master>
        
        <!-- Define page sequence master for alternating odd and even pages -->
        <page-sequence-master master-name="main">
            <repeatable-page-master-alternatives>
                <conditional-page-master-reference master-reference="odd-page" odd-or-even="odd"/>
                <conditional-page-master-reference master-reference="even-page" odd-or-even="even"/>
            </repeatable-page-master-alternatives>
        </page-sequence-master>
    </layout-master-set>
    
    <!-- Main page sequence using the page sequence master -->
    <page-sequence master-reference="main">
        <static-content flow-name="xsl-region-before">
            <block>test</block>
        </static-content>
        <static-content flow-name="xsl-region-after">
            <!-- Your footer content goes here -->
            <block>
                Page <page-number-citation ref-id="dummy-id"/>
            </block>
        </static-content>
        <flow flow-name="xsl-region-body">
            <!-- Your content goes here -->
            <block id="dummy-id">Some content...</block>
        </flow>
    </page-sequence>
    <page-sequence master-reference="main">
        <static-content flow-name="xsl-region-before">
            <block>test</block>
        </static-content>
        <static-content flow-name="xsl-region-after">
            <block>
                Page <page-number-citation ref-id="dummy-id2"/>
            </block>
        </static-content>
        <flow flow-name="xsl-region-body">
            <!-- Your content goes here -->
            <block id="dummy-id2">Some content... 2</block>
        </flow>
    </page-sequence></root>

问题原因与解决方法

问题出在文本格式化属性的应用层级错误。XSL FO的<region-after>、<region-before>这类区域元素仅负责定义页面区域的布局参数(如尺寸、边距),并不支持text-align、text-indent这类文本属性——这些属性需要直接应用到区域内的内容容器(比如<block>)上。

修改方案是将原本写在<region-after>里的文本属性,移到对应<static-content>内的<block>元素上,示例代码如下:

<?xml version="1.0" encoding="UTF-8"?>

<root xmlns="http://www.w3.org/1999/XSL/Format">
    <layout-master-set>
        <!-- 奇数页母版:移除region-after的文本属性 -->
        <simple-page-master master-name="odd-page" page-width="8.5in" page-height="11in" margin="1in">
            <region-body margin="1in"/>
            <region-before extent="1in"/>
            <region-after extent="1in"/>
        </simple-page-master>
        
        <!-- 偶数页母版:移除region-after的文本属性 -->
        <simple-page-master master-name="even-page" page-width="8.5in" page-height="11in" margin="1in">
            <region-body margin="1in"/>
            <region-before extent="1in"/>
            <region-after extent="1in"/>
        </simple-page-master>
        
        <page-sequence-master master-name="main">
            <repeatable-page-master-alternatives>
                <conditional-page-master-reference master-reference="odd-page" odd-or-even="odd"/>
                <conditional-page-master-reference master-reference="even-page" odd-or-even="even"/>
            </repeatable-page-master-alternatives>
        </page-sequence-master>
    </layout-master-set>
    
    <!-- 第一个页面序列:奇数页页脚设置左对齐和缩进 -->
    <page-sequence master-reference="main">
        <static-content flow-name="xsl-region-before">
            <block>test</block>
        </static-content>
        <static-content flow-name="xsl-region-after">
            <block text-align="left" text-indent="10%">
                Page <page-number-citation ref-id="dummy-id"/>
            </block>
        </static-content>
        <flow flow-name="xsl-region-body">
            <block id="dummy-id">Some content...</block>
        </flow>
    </page-sequence>
    <!-- 第二个页面序列:偶数页页脚设置右对齐和缩进 -->
    <page-sequence master-reference="main">
        <static-content flow-name="xsl-region-before">
            <block>test</block>
        </static-content>
        <static-content flow-name="xsl-region-after">
            <block text-align="right" text-indent="50%">
                Page <page-number-citation ref-id="dummy-id2"/>
            </block>
        </static-content>
        <flow flow-name="xsl-region-body">
            <block id="dummy-id2">Some content... 2</block>
        </flow>
    </page-sequence>
</root>

如果需要在同一页面序列内自动为奇偶页应用不同样式,可以结合XSLT的条件判断逻辑,根据当前页面的奇偶性为<block>动态添加对应的文本属性。


内容的提问来源于stack exchange,提问作者Peter Scholz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 23:25:56