我正在使用XSL FO将XML数据从文件转换为呈现为PDF文档的表格。如果XML中没有数据,我被要求渲染空表结构 - 将表体留空。
我尝试了以下代码
<!-- Addresses -->
<fo:table border="1px solid black" table-layout="fixed" width="100%">
<fo:table-column column-width="2in"/>
<fo:table-column column-width="2in"/>
<fo:table-column column-width="2.5in"/>
<fo:table-column column-width="2.5in"/>
<fo:table-column column-width="2in"/>
<fo:table-header>
<fo:table-row>
<fo:table-cell border="0.1pt solid black" text-align="left" font-size="12pt" font-weight="bold" number-columns-spanned="5" background-color= "#B6B6B4"><fo:block>Addresses</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell border="0.1pt solid black" text-align="left" font-size="10pt" font-weight="bold">
<fo:block> Address Type </fo:block>
</fo:table-cell>
<fo:table-cell border="0.1pt solid black" text-align="left" font-size="10pt" font-weight="bold">
<fo:block> Fields</fo:block>
</fo:table-cell>
<fo:table-cell border="0.1pt solid black" text-align="left" font-size="10pt" font-weight="bold">
<fo:block> Values </fo:block>
</fo:table-cell>
<fo:table-cell border="0.1pt solid black" text-align="left" font-size="10pt" font-weight="bold">
<fo:block> Data Source</fo:block>
</fo:table-cell>
<fo:table-cell border="0.1pt solid black" text-align="left" font-size="10pt" font-weight="bold">
<fo:block> DMC Doc Link</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:if test="core/clientMembers/address">
<xsl:apply-templates select="core/clientMembers/address"/>
</xsl:if>
<xsl:if test="not(core/clientMembers/address)">
<fo:table-row>
<fo:table-cell border="0.1pt solid black" text-align="left" font-size="9pt"><fo:block>Primary Address</fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell border="0.1pt solid black" text-align="left" font-size="9pt"><fo:block>Incorporated Address</fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell border="0.1pt solid black" text-align="left" font-size="9pt"><fo:block>Registered Address</fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell border="0.1pt solid black" text-align="left" font-size="9pt"><fo:block>Mailing Address</fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
<fo:table-cell border="0.1pt solid black"><fo:block white-space-treatment="preserve"><fo:leader /></fo:block></fo:table-cell>
</fo:table-row>
</xsl:if>
</fo:table-body>
</fo:table>
但是这段代码没有按预期工作。 请问这里的专家请问是否有办法在XSL FO中实现所需的行为? “core / clientMain / coverage”是xsl模板。
答案 0 :(得分:0)
根据您呈现的代码,“离开桌面空间”是什么意思有点不清楚。当然,我可以相信,在XPath表达式core/clientMain/coverage
求值为空节点集的情况下,它不会执行您想要的操作,因为它将在<fo:table-body>
元素内生成单个{{1子元素,没有任何干预<fo:table-cell>
。
我可以看到你想要产生一排空单元格(显然其中五个与五个标题匹配),或者根本没有行,但是你所呈现的内容没有意义。
所有情况下的无行都很简单:只需省略第二个<fo:table-row>
元素及其内容,只留下
xsl:if
(我认为当事实上有数据时,该部分按预期工作。)
如果实际上您想提供一个空数据行,那么提供它!详细信息取决于您的具体需求,但可能如下所示:
<xsl:if test="core/clientMain/coverage">
<xsl:apply-templates select="core/clientMain/coverage"/>
</xsl:if>