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>
because dont know which element will be first.
如果是,请更改以下代码
<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>
这将满足您的要求。
我的 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>
because dont know which element will be first.
如果是,请更改以下代码
<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>
这将满足您的要求。