我正在进行xsl转换,我想在同一个pdf中放入几个不同的文档。我有第一页,最后一页和其他页面的简单页面主页。我需要找出一种方法来使用最后一页然后第一页开始一个新文档并重置页码。
<fo:layout-master-set>
<fo:simple-page-master master-name="first-page">
<fo:region-body margin-bottom="1in" region-name="main-body"/>
<fo:region-after extent="1in" region-name="page-footer" display-align="after"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="other-pages">
<fo:region-body margin-top=".5in" margin-bottom=".5in" region-name="main-body"/>
<fo:region-before extent=".5in" region-name="page-header" display-align="before"/>
<fo:region-after extent=".5in" region-name="page-footer" display-align="after"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="last-page">
<fo:region-body margin-top=".5in" margin-bottom="1in" region-name="main-body"/>
<fo:region-before extent=".5in" region-name="page-header" display-align="before"/>
<fo:region-after extent="1in" region-name="page-footer" display-align="after"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="my-sequence">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference page-position="first"
master-reference="first-page"/>
<fo:conditional-page-master-reference page-position="last"
master-reference="last-page"/>
<fo:conditional-page-master-reference odd-or-even="rest"
master-reference="other-pages"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
我尝试设置初始页码但不允许我在页面内执行此操作。有什么想法吗?
这是页面序列。
<fo:page-sequence master-reference="my-sequence">
<fo:static-content flow-name="page-header" font-style="italic">
<xsl:if test="/Report[string-length(@print-page-headers) = 0 or @print-page-headers != 'false']">
<fo:block>
<fo:table width="100%" table-layout="fixed">
<fo:table-column/>
<fo:table-column/>
<fo:table-body>
<fo:table-row line-height="12pt" font-size="10pt">
<fo:table-cell>
<fo:block text-align="left">
<xsl:value-of select="/Report/ReportInfo/title "/>
</fo:block>
</fo:table-cell>
<fo:table-cell line-height="12pt" font-size="10pt">
<fo:block text-align="right">
Page <fo:page-number/> of <fo:page-number-citation ref-id="terminator"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
<fo:block>
<fo:leader leader-pattern="rule" rule-thickness="1pt" leader-length="100%"/>
</fo:block>
</xsl:if>
</fo:static-content>
<fo:static-content flow-name="page-footer">
<xsl:if test="/Report[string-length(@print-page-footers) = 0 or @print-page-footers != 'false']">
<fo:block >
<fo:table width="100%" table-layout="fixed">
<fo:table-column/>
<fo:table-body>
<fo:table-row height="9in">
<fo:table-cell display-align="after">
<fo:retrieve-marker retrieve-class-name="includes"/>
<fo:table width="100%" table-layout="fixed">
<fo:table-column/>
<fo:table-column/>
<fo:table-column/>
<fo:table-body>
<fo:table-row>
<fo:table-cell text-align="left">
<fo:block font-family="serif" font-size="8pt">
<xsl:value-of select="/Report/reportName"/>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="center">
<fo:block font-family="serif" font-size="6pt">
<xsl:text></xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right">
<fo:block font-family="serif" font-size="8pt">
<xsl:value-of select="/Report/ReportInfo/date"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell number-columns-spanned="3" text-align="center">
<fo:block font-family="serif" font-size="6pt">
<xsl:text></xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
</xsl:if>
</fo:static-content>
<fo:flow flow-name="main-body">
<fo:block hyphenate="true" language="en">
<xsl:apply-templates/>
</fo:block>
<fo:block id="terminator"/>
</fo:flow>
</fo:page-sequence>
我尝试使用模板重置初始页码:
<xsl:template match="newreport">
<fo:page-sequence initial-page-number="1" master-reference="my-sequence">
<fo:static-content flow-name="page-header" font-style="italic">
<fo:block break-before="page"/>
<fo:block>
<fo:table width="100%" table-layout="fixed">
<fo:table-column/>
<fo:table-column/>
<fo:table-body>
<fo:table-row line-height="12pt" font-size="10pt">
<fo:table-cell>
<fo:block text-align="left">
<xsl:value-of select="/Report/ReportInfo/title "/>
</fo:block>
</fo:table-cell>
<fo:table-cell line-height="12pt" font-size="10pt">
<fo:block text-align="right">
Page <fo:page-number/> of <fo:page-number-citation ref-id="terminator"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
<fo:block>
<fo:leader leader-pattern="rule" rule-thickness="1pt" leader-length="100%"/>
</fo:block>
</fo:static-content>
</fo:page-sequence>
</xsl:template>
这不起作用。我复制了第一页序列中的代码。我希望能够重置到第一页并执行页眉等。
答案 0 :(得分:1)
也许您希望将此示例调整为您的,这对于多批文档中的Y引用的Page X非常有效。这里的一个关键是你必须使用唯一的引用来记录“块”。你会在XML中使用一些独特的东西,但我发现在重复文档上使用generate-id(。)同样容易,将id添加到fo:flow然后使用fo:page-number-citation-last with那个id。因此,您将获得每个流程的最后一页。
示例输入:
<batch>
<document>
<page/>
<page/>
<page/>
<page/>
<page/>
</document>
<document>
<page/>
<page/>
<page/>
</document>
<document>
<page/>
<page/>
<page/>
</document>
</batch>
示例XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="pages">
<fo:region-body margin-top="1in"/>
<fo:region-before extent="0.5in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:apply-templates/>
</fo:root>
</xsl:template>
<xsl:template match="document">
<fo:page-sequence master-reference="pages" initial-page-number="1" force-page-count="no-force">
<fo:static-content flow-name="xsl-region-before">
<fo:block>
Page <fo:page-number/> of <fo:page-number-citation-last ref-id="{generate-id(.)}"/>
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body" id="{generate-id(.)}">
<xsl:apply-templates/>
</fo:flow>
</fo:page-sequence>
</xsl:template>
<xsl:template match="page">
<fo:block break-before="page">
I am a page
</fo:block>
</xsl:template>
</xsl:stylesheet>
输出显示5个中的1个,5个中的2个,5个中的3个...然后是3个中的1个,3个中的2个......完美无缺。