1

我正在做一个 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>

这行不通。我从第一页序列中复制了代码。我希望能够重置到第一页并执行页眉等。

4

1 回答 1

1

也许您希望将此示例改编为您的,这对于多批次文档中的 Y 页 X 引用非常有效。这里的一个关键是您必须使用对文档“块”的唯一引用。您将在 XML 中使用独特的东西,但我发现在重复文档上使用 generate-id(.) 一样容易,将该 id 添加到 fo:flow 然后使用 fo:page-number-citation-last那个身份证 因此,您将获得每个流程的最后一页。

样本输入:

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

输出显示 1 of 5, 2 of 5, 3 of 5 ... 其次是 1 of 3, 2 of 3 ... 完美。

于 2013-11-13T19:49:15.813 回答