我使用Apache Fop(2.1)从XML生成RTF文档。我希望第一页的标题与其他页面的标题不同。我已经设置了两个简单页面主页,一个用于第一页,另一个用于其他页面。我遇到一个问题,到了页面位置"首先"。它永远不会到达那里:
<fo:page-sequence-master master-name="my-sequence">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference page-position="first" master-reference="firstPage"/>
<fo:conditional-page-master-reference page-position="rest" master-reference="otherPage"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
它始终到达页面位置=&#34;休息&#34;,即使对于文档的第一页也是如此。谁能告诉我为什么?我该如何解决这个问题?
Fop确实给了我这个错误:
Only simple-page-masters are supported on page-sequences. Using default simple-page-master from page-sequence-master "my-sequence"
以下是我的其他xslt:
<fo:layout-master-set>
<fo:simple-page-master master-name="firstPage"
page-height="11in" page-width="8.5in"
margin-top=".5in" margin-left="1in" margin-right="1in" margin-bottom=".5in">
<fo:region-body />
<fo:region-before region-name="firstPageBefore"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="otherPage"
page-height="11in" page-width="8.5in"
margin-top=".5in" margin-left="1in" margin-right="1in" margin-bottom=".5in">
<fo:region-body />
<fo:region-before region-name="otherPageBefore"/>
</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="firstPage"/>
<fo:conditional-page-master-reference page-position="rest" master-reference="otherPage"/>
</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="firstPageBefore">
<fo:block>First page!</fo:block>
</fo:static-content>
<fo:static-content flow-name="otherPageBefore">
<fo:block>Other page!</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body" >
<xsl:apply-templates/>
</fo:flow>
</fo:page-sequence>
答案 0 :(得分:2)
我使用这个样本:
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="firstPage"
page-height="11in" page-width="8.5in"
margin-top=".5in" margin-left="1in" margin-right="1in" margin-bottom=".5in">
<fo:region-body background-color="red"/>
<fo:region-before region-name="firstPageBefore"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="otherPage"
page-height="11in" page-width="8.5in"
margin-top=".5in" margin-left="1in" margin-right="1in" margin-bottom=".5in">
<fo:region-body />
<fo:region-before region-name="otherPageBefore"/>
</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="firstPage"/>
<fo:conditional-page-master-reference page-position="rest" master-reference="otherPage"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-sequence">
<fo:flow flow-name="xsl-region-body" >
<fo:block break-after="page">First Page</fo:block>
<fo:block break-after="page">Second Page</fo:block>
<fo:block break-after="page">Third Page</fo:block>
<fo:block>Forth Page</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
注意我只为第一页“region-body”红色的背景着色。我用Apache FOP 2.1得到了这个输出:
现在,如果我只将格式更改为RTF而不是PDF,则无法获得预期的输出。如果要测试这个,我甚至将第一页改为5inx5in。如果我检查生成的RTF,则只有一个页面布局是最后一个。
为了证明这一点,我将第一页更改为5x5,其余页面更改为11x8.5格局,原始RTF显示:
{* \ generator Apache XML Graphics RTF Library;} \ fet0 \ ftnbj \ paperw15840 \ paperh12240 \ landscape \ margt720 \ margb720 \ margl1440 \ margr1440 \ headery720 \ footery720 \ itap0
这只是一个页面模板,它不是第一个模板。请参见下图,所有页面均为横向,未应用任何颜色。
这似乎是Apache FOP RTF输出的错误或不支持的功能。