如何在XSL-FO中保持表行组的分页符

  • 本文关键字:分页 XSL-FO xml xslt xsl-fo xmlspy
  • 更新时间 :
  • 英文 :


我有一个相当复杂的表,我认为这是我的问题的根源。该表是根据从客户机数据库的XML文件中检索到的数据填充的。下面是我试图应用于XML的XSL代码的摘录:

<fo:table-row>
    <fo:table-cell number-columns-spanned="2">
        <fo:block/>
    </fo:table-cell>
    <fo:table-cell number-columns-spanned="2">
        <fo:block/>
    </fo:table-cell>
</fo:table-row>
<xsl:for-each select="xml/value">
    <fo:table-row>
        <fo:table-cell number-columns-spanned="2">
            <fo:block>
                <xsl:value-of select="@value"/>/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell number-columns-spanned="2">
            <fo:block>
                <xsl:value-of select="@othervalue"/>/>
            </fo:block>
        </fo:table-cell>
        </fo:table-row>
</xsl:for-each>

这被捆绑在一起,并被当作单行处理,所以如果页面在这个更大的行中分割某个地方,它看起来就像这行被分割了。

我试过用keep-together。Within-page ="always", page-break-inside="avoid", keep-with-previous。Within-page ="always"和keep-with-next。Within-page ="always"在表和迭代块上以各种组合,但似乎没有什么坚持。有人能找到解决这个问题的办法吗?

我(不情愿地)使用了嵌套表。使用此解决方案(如果它适合您),您最好在表上使用table-layout="fixed",并显式指定列及其宽度,以确保列对齐。因此,我将引入一些进一步的模板来整理一些内容并提高可维护性:

<xsl:template match="Whatever">
    <fo:table table-layout="fixed">
        <xsl:call-template name="fourColumnTemplate"/>
        <fo:table-body>
            <!-- UNSEEN ROWS HERE -->
            <!-- UNSEEN ROWS HERE -->
            <!-- UNSEEN ROWS HERE -->
            <fo:table-row keep-together.within-page="always">
                <fo:table-cell number-columns-spanned="4">
                    <fo:block>
                        <xsl:call-template name="outputXmlValueTable">
                            <xsl:with-param name="xmlNodes" select="xml/value"/>
                        </xsl:call-template>
                    </fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</xsl:template>
<xsl:template name="fourColumnTemplate">
    <!-- note that these values should only be specified in one place for maintenance reasons -->
    <fo:table-column column-width="proportional-column-width(2)"/>
    <fo:table-column column-width="proportional-column-width(3)"/>
    <fo:table-column column-width="proportional-column-width(2)"/>
    <fo:table-column column-width="proportional-column-width(3)"/>
</xsl:template>
<xsl:template name="outputXmlValueTable">
    <xsl:param name="xmlNodes"/>
    <fo:table table-layout="fixed">
        <xsl:call-template name="fourColumnTemplate"/>
        <fo:table-header>
            <fo:table-row>
                <fo:table-cell number-columns-spanned="2">
                    <fo:block>Title1</fo:block>
                </table-cell>
                <fo:table-cell number-columns-spanned="2">
                    <fo:block>Title2</fo:block>
                </table-cell>
            </fo:table-row>
        </fo:table-header>
        <fo:table-body>
            <xsl:apply-templates select="$xmlNodes" mode="outputXmlValueRow"/>
        </fo:table-body>
    </fo:table>
</xsl:template>
<xsl:template match="*" mode="outputXmlValueRow">
    <fo:table-row>
        <fo:table-cell number-columns-spanned="2">
            <fo:block>
                <xsl:value-of select="@value"/>/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell number-columns-spanned="2">
            <fo:block>
                <xsl:value-of select="@othervalue"/>/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template>

最新更新