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