首页 > 解决方案 > 如何使用 XSL/XSL-FO 在静态表中添加连续标签?

问题描述

我正在使用类似于下面示例的 xml 数据。有一个可能的风险列表,每个风险都可以有一个名称和描述。

<risks>
    <freezeDeductible name="item1" description="desc 1"/>
    <moneySecLimit name="item2" description="desc 2"/>
    <unscheduledLimit name="item3" description="desc 3"/>
    ...
</risks>

我的模板结构如下:

<xsl:template name="displayRisks">
    <fo:block>

        <fo:table>
            <fo:table-column column-width="proportional-column-width(33.333)" column-number="1"/>
            <fo:table-column column-width="proportional-column-width(33.333)" column-number="2"/>
            <fo:table-column column-width="proportional-column-width(33.333)" column-number="3"/>
            <fo:table-body>
                <fo:table-row>
                    <fo:table-cell>
                        <fo:block font-weight="bold">ALL RISKS</fo:block>
                    </fo:table-cell>
                    <fo:table-cell>
                        <fo:block><xsl:value-of select="/risks/freezeDeductible/@name"/></fo:block>
                    </fo:table-cell>
                    <fo:table-cell>
                        <fo:block><xsl:value-of select="/risks/freezeDeductible/@description"/></fo:block>
                    </fo:table-cell>
                </fo:table-row>
                <fo:table-row>
                    <fo:table-cell>
                        <fo:block> </fo:block>
                    </fo:table-cell>
                    <fo:table-cell>
                        <fo:block><xsl:value-of select="/risks/moneySecLimit/@name"/></fo:block>
                    </fo:table-cell>
                    <fo:table-cell>
                        <fo:block><xsl:value-of select="/risks/moneySecLimit/@description"/></fo:block>
                    </fo:table-cell>
                </fo:table-row>
            </fo:table-body>
        </fo:table>
    </fo:block>
</xsl:template>

根据上面的模板,我正在生成 PDF 输出。由于风险描述的大小,以及风险元素的数量是未知的,该表可以跨越多个一页或一页。

在 column1 x row1 上,第一页上显示了标题 - “所有风险”。它需要与第一个风险名称和描述在同一行,因此不能将其移动到表头。

有什么方法可以在表格到达 page2、page3 等时在新页面的第一行显示标题(ALL RISKS),并带有标签 - 例如:(继续..)?

例如: Page1:应该在第一行显示标题,如下所示:ALL RISKS

如果有 Page2:在 Pag2 的第一个表行显示标题,如下所示:ALL RISKS(continued..)

谢谢!

标签: xsltxsl-fo

解决方案


在https://www.antennahouse.com/xsl-fo-samples#table-retrieve-table-marker-1fo:retrieve-table-marker的“XSL-FO 样本集合”中有一个示例。(由于页面上的横幅,您可能需要在点击链接后向上滚动。)

在https://www.antennahouse.com/xsl-fo-samples#axf-table-cell-repeated-marker-1上还有一个axf:repeat-content-at-breakaxf:table-cell-repeated-markerAH Formatter 扩展的示例,它演示了重复和“(续)”像你想要的那样标记。


推荐阅读