繁体   English   中英

XSL-FO:如何设置整个文档的初始页码?

[英]XSL-FO: How to set initial page number for whole document?

我的xml根目录以任意顺序包含许多不同的子元素,每个子元素在page-sequence都有其自己的标记。 Xslt模板采用一个参数-本文档的初始页。 而且我无法在page-sequence initial-page-number属性中设置它,因为不知道哪个元素将是第一个。 在xsl-fo或xslt级别中,是否有任何变通方法可将给定的编号用作第一页序列的页码?

xml范例1:

<root>
 <item-abc/>
 <item-def/>
 <item-ghj/>
</root>

xml范例2:

<root>
 <item-ghj/>
 <item-ghj/>
 <item-abc/>
</root>

XSLT:

<x:stylesheet version="1.0" xmlns:x="http://www.w3.org/1999/XSL/Transform">
 <x:template match="/">
  <fo:root text-align="center" font-family="Arial" font-size="9pt">
    <fo:layout-master-set>
        <fo:simple-page-master master-name="m" margin-left="7mm" margin-right="9mm" margin-top="8mm" margin-bottom="1mm" page-width="210mm" page-height="297mm">
            <fo:region-body margin-top="14mm" margin-left="2mm"/>
            <fo:region-before />
            <fo:region-after />
        </fo:simple-page-master>
    </fo:layout-master-set>
   <x:apply-templates select="root/item-abc"/>
   <x:apply-templates select="root/item-def"/>
   <x:apply-templates select="root/item-ghj"/>
  </fo:root>
 </x:template>

 <x:template match="root/item-abc">
  <fo:page-sequence master-reference="m" format="00001">
   ....
  </fo:page-sequence>
 </x:template>

 ...another items' templates
</x:stylesheet>

因为不知道哪个元素将是第一个。

如果是真的,请更改代码

<x:apply-templates select="root/item-abc"/>
<x:apply-templates select="root/item-def"/>
<x:apply-templates select="root/item-ghj"/>

<x:apply-templates select="root/*"/>

并首先通过position()函数检查哪个:

<x:template match="root/item-abc">
   <fo:page-sequence master-reference="m" format="00001">
       <x:if test="position() eq 1">
           <x:attribute name="initial-page-number" select="'1'"/>
       </x:if>
   ....
   </fo:page-sequence>
</x:template>

这将满足您的要求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM