gpt4 book ai didi

xml - 如何在 XSL-FO 中将分页符从表行组中分离出来

转载 作者:数据小太阳 更新时间:2023-10-29 02:41:22 26 4
gpt4 key购买 nike

我有一个相当复杂的表格,我认为这是我的问题的根源。该表是根据从客户端数据库的 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"在表格和迭代 block 上以各种组合出现,但似乎没有任何内容。任何人都可以找到解决方案吗?感谢任何帮助,谢谢。

最佳答案

我(不情愿地)使用的解决方法是嵌套表。使用此解决方案(如果它适合您),您最好在表格上使用 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>

关于xml - 如何在 XSL-FO 中将分页符从表行组中分离出来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15712032/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com