【问题标题】:How to indicate a fo:block spans a page如何指示一个 fo:block 跨越一个页面
【发布时间】:2019-05-23 02:22:07
【问题描述】:

我有一个可能跨越页面的 fo:block。我想在该块所在的第一页底部放置一些文本,例如“继续”。

源文档在 标签中有一系列

我能看到的唯一方法是在源文档的正确位置添加 Continued on next page,但这需要在编写文档时不断进行编辑。

是否有一个测试块是否跨越页面?

源文件:

<recipe page-break="auto">
  <instructions>
    <step>The first thing to do</step>
    <step>The second thing to do</step>
  </instructions>
<recipe>

样式表的相关部分:

<xsl:template match="recipe">
  <xsl:variable name="pbi"><xsl:choose><xsl:when test="@page-break"><xsl:value-of select="@page-break"/></xsl:when><xsl:otherwise>avoid</xsl:otherwise></xsl:choose></xsl:variable>
  <xsl:variable name="pbb"><xsl:choose><xsl:when test="@page-break">always</xsl:when><xsl:otherwise>auto</xsl:otherwise></xsl:choose></xsl:variable>
  <fo:block page-break-inside="{$pbi}" page-break-before="{$pbb}" margin-bottom="1.5em">
    <xsl:apply-templates select="instructions/step" mode="plain"/>
  </fo:block>
</xsl:template>

谢谢。

【问题讨论】:

  • 如果我理解正确,如果&lt;recipe&gt; 的格式跨越多个页面,您希望显示“继续”,对吗?

标签: xsl-fo


【解决方案1】:

虽然 Tony 的建议可行,但它仅适用于支持该构造的格式化程序。正如他所建议的那样,您可以将纯标记拉入页脚。您可能对内容结尾和页脚之间的垂直空间的控制较少,但这取决于您的内容。

您只需在页脚区域使用检索标记,例如:

    <fo:static-content flow-name="footer">
        <fo:block-container text-align="left" margin-left="1in">
            <fo:block><fo:retrieve-marker retrieve-class-name="continued" retrieve-boundary="page" retrieve-position="last-starting-within-page"/>
            </fo:block>
        </fo:block-container>
    </fo:static-content>

现在,在您的流程中,您有一些块,当该块打破页面时,您希望消息出现在其中。你使用这样的东西:

 <fo:block-container>
    <fo:marker marker-class-name="continued">I am continued on next page ...</fo:marker>
    <fo:block margin-top="6pt">I am some text that will break across the page somewhere. When I do break the footer should have continued. I am some text that will break across the page somewhere. When I do break the footer should have continued. </fo:block>
 <!-- More content here, whatever you need -->

 </fo:block-container>
 <fo:block-container keep-with-previous.within-page="always">
     <fo:marker marker-class-name="continued"></fo:marker>
 </fo:block-container>

块容器内的第一个标记将创建一个带有您想要的连续文本的“标记”。如果页面在该块内中断,则将标记拉入页脚区域。第二个标记有效地“清除”它,因为它没有内容。它被拉到页脚,但它是空白的,所以什么都没有出现。

结果是这样的,不存在续文(第 1、3、4 页),除非在标有续文的区域内分页符(第 2 页)。

【讨论】:

    【解决方案2】:

    使用标记。要么将所有内容放在fo:table 中,然后在fo:table-footer 中使用fo:retrieve-table-marker(参见https://www.w3.org/TR/xsl11/#fo_retrieve-table-marker),或者在fo:static-content 中使用fo:retrieve-marker 作为fo:region-after。不同之处在于,使用fo:table 方法,“继续”指示可以立即出现在页面上的最后一个文本之后(如本例所示),而不是使用fo:retrieve-marker 方法在页面页脚中的固定位置。

    <fo:table table-layout="fixed">
      <fo:table-footer>
        <fo:retrieve-table-marker
            retrieve-class-name="footer-continued"
            retrieve-position-within-table="last-ending"/>
      </fo:table-footer>
      <fo:table-body>
        <fo:table-row>
          <fo:marker marker-class-name="footer-continued">
            <fo:table-row>
              <fo:table-cell padding="3pt">
                <fo:block text-align="right"
                          font-style="italic">continued.....</fo:block>
              </fo:table-cell>
            </fo:table-row>
          </fo:marker>
          <fo:table-cell padding="3pt">
            <fo:block>The first thing to do</fo:block>
          </fo:table-cell>
        </fo:table-row>
        ...
        <fo:table-row>
          <fo:marker marker-class-name="footer-continued" />
          <fo:table-cell padding="3pt">
            <fo:block>The fourth thing to do</fo:block>
          </fo:table-cell>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
    

    您可以使用 FOP 执行 fo:retrieve-table-marker 方法,如果您解决其记录(固定表格布局,检索到的标记不能更改块进度维度)和未记录(对放置 fo:retrieve-table-marker 的位置很挑剔,不得不将fo:marker 移动到fo:table-cell) 限制:

    <fo:table table-layout="fixed" width="100%">
      <fo:table-footer>
        <fo:table-row>
          <fo:table-cell padding="3pt">
            <fo:block text-align="right"
                      font-style="italic">
              <fo:retrieve-table-marker
                  retrieve-class-name="footer-continued"
                  retrieve-position-within-table="last-ending"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
      </fo:table-footer>
      <fo:table-body>
        <fo:table-row>
          <fo:table-cell padding="3pt">
            <fo:marker marker-class-name="footer-continued">continued.....</fo:marker>
            <fo:block>The first thing to do</fo:block>
          </fo:table-cell>
        </fo:table-row>
        ...
        <fo:table-row>
          <fo:table-cell padding="3pt">
            <fo:marker marker-class-name="footer-continued">&#xA0;</fo:marker>
            <fo:block>The fourth thing to do</fo:block>
          </fo:table-cell>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
    

    【讨论】:

    • 许多 xsl fo 引擎不支持检索表标记,此处不需要。只需在内部使用块容器设置标记,然后清除标记。
    猜你喜欢
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多