我有一张相当复杂的桌子,我觉得这是我问题的根源。该表基于从客户端数据库的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 =&#34; always&#34;,page-break-inside =&#34;避免&#34 ;, keep-with-previous.within- page =&#34; always&#34;,并且keep-with-next.within-page =&#34; always&#34;在桌子上和各种组合的迭代块,但似乎没有什么坚持。有人能找到解决方案吗?感谢任何帮助,谢谢。
答案 0 :(得分:1)
我(不情愿地)使用的解决方法是嵌套表。使用此解决方案(如果它适用于您),您最好在表上使用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>