使用 XSL-FO 删除 Lotus Notes XML 中的合并行
Delete merged rows in Lotus Notes XML using XSL-FO
我正在使用 FOP 和 XSL-FO 从 Lotus Notes XML 生成 PDF。当一行中的所有单元格在 Notes 文档中合并时,它在 XML(没有 <tablecell>
子项)中变为 <tablerow/>
。例如:
<table widthtype='fixedleft' refwidth='12.5083in'>
<tablecolumn width='4.1694in'/>
<tablecolumn width='4.1694in'/>
<tablecolumn width='4.1694in'/>
<tablerow>
<tablecell rowspan='4'>...</tablecell>
<tablecell>...</tablecell>
<tablecell>...</tablecell>
</tablerow>
<tablerow>
<tablecell>...</tablecell>
<tablecell>...</tablecell>
</tablerow>
<tablerow>
<tablecell rowspan='2'>...</tablecell>
<tablecell rowspan='2'>...</tablecell>
</tablerow>
<tablerow/>
</table>
我正在 xsl-fo 中寻找解决方法来删除空行并调整行跨度。否则我在 FOP 中有一个错误:
fo:table-row is missing child elements. Required content model: <table-cell+>
这是我想要的结果:
<table widthtype='fixedleft' refwidth='12.5083in'>
<tablecolumn width='4.1694in'/>
<tablecolumn width='4.1694in'/>
<tablecolumn width='4.1694in'/>
<tablerow>
<tablecell rowspan='3'>...</tablecell>
<tablecell>...</tablecell>
<tablecell>...</tablecell>
</tablerow>
<tablerow>
<tablecell>...</tablecell>
<tablecell>...</tablecell>
</tablerow>
<tablerow>
<tablecell rowspan='1'>...</tablecell>
<tablecell rowspan='1'>...</tablecell>
</tablerow>
</table>
这是我的 xsl :
<xsl:template match="dxl:table">
<fo:table width="100%" table-layout="fixed">
<xsl:for-each select="dxl:tablecolumn">
<fo:table-column column-width="@width"/>
</xsl:for-each>
<fo:table-body>
<xsl:apply-templates />
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="dxl:tablerow">
<fo:table-row>
<xsl:apply-templates/>
</fo:table-row>
</xsl:template>
<xsl:template match="dxl:tablecell">
<xsl:variable name="rows">
<xsl:choose>
<xsl:when test="@rowspan">
<xsl:value-of select="@rowspan"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<fo:table-cell number-rows-spanned="{$rows}">
<xsl:apply-templates/>
</fo:table-cell>
</xsl:template>
提前致谢!
您可以创建第二个变量来计算包含当前 table 单元格
的行之后的所有 "blank" 行
<xsl:variable
name="blankrows"
select="count(../following-sibling::dxl:tablerow[position() < number($rows)]
[not(dxl:tablecell)])" />
然后您可以按此数量调整 $rows 变量以生成 number-rows-spanned
属性。
试试这个 XSLT(带有虚构的命名空间...)
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:dxl="dxl" xmlns:fo="fo">
<xsl:output method="xml" indent="yes" />
<xsl:template match="dxl:table">
<fo:table width="100%" table-layout="fixed">
<xsl:for-each select="dxl:tablecolumn">
<fo:table-column column-width="@width"/>
</xsl:for-each>
<fo:table-body>
<xsl:apply-templates />
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="dxl:tablerow[not(dxl:tablecell)]" />
<xsl:template match="dxl:tablerow">
<fo:table-row>
<xsl:apply-templates/>
</fo:table-row>
</xsl:template>
<xsl:template match="dxl:tablecell">
<xsl:variable name="rows">
<xsl:choose>
<xsl:when test="@rowspan">
<xsl:value-of select="@rowspan"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="blankrows" select="count(../following-sibling::dxl:tablerow[position() < number($rows)][not(dxl:tablecell)])" />
<fo:table-cell>
<xsl:if test="$rows - 1 > $blankrows">
<xsl:attribute name="number-rows-spanned">
<xsl:value-of select="$rows - $blankrows" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</fo:table-cell>
</xsl:template>
</xsl:stylesheet>
我已将属性设置为有条件的,因此如果将其设置为 1 则不会显示它。
另请注意使用空模板 <xsl:template match="dxl:tablerow[not(dxl:tablecell)]" />
来删除空行本身。
我正在使用 FOP 和 XSL-FO 从 Lotus Notes XML 生成 PDF。当一行中的所有单元格在 Notes 文档中合并时,它在 XML(没有 <tablecell>
子项)中变为 <tablerow/>
。例如:
<table widthtype='fixedleft' refwidth='12.5083in'>
<tablecolumn width='4.1694in'/>
<tablecolumn width='4.1694in'/>
<tablecolumn width='4.1694in'/>
<tablerow>
<tablecell rowspan='4'>...</tablecell>
<tablecell>...</tablecell>
<tablecell>...</tablecell>
</tablerow>
<tablerow>
<tablecell>...</tablecell>
<tablecell>...</tablecell>
</tablerow>
<tablerow>
<tablecell rowspan='2'>...</tablecell>
<tablecell rowspan='2'>...</tablecell>
</tablerow>
<tablerow/>
</table>
我正在 xsl-fo 中寻找解决方法来删除空行并调整行跨度。否则我在 FOP 中有一个错误:
fo:table-row is missing child elements. Required content model: <table-cell+>
这是我想要的结果:
<table widthtype='fixedleft' refwidth='12.5083in'>
<tablecolumn width='4.1694in'/>
<tablecolumn width='4.1694in'/>
<tablecolumn width='4.1694in'/>
<tablerow>
<tablecell rowspan='3'>...</tablecell>
<tablecell>...</tablecell>
<tablecell>...</tablecell>
</tablerow>
<tablerow>
<tablecell>...</tablecell>
<tablecell>...</tablecell>
</tablerow>
<tablerow>
<tablecell rowspan='1'>...</tablecell>
<tablecell rowspan='1'>...</tablecell>
</tablerow>
</table>
这是我的 xsl :
<xsl:template match="dxl:table">
<fo:table width="100%" table-layout="fixed">
<xsl:for-each select="dxl:tablecolumn">
<fo:table-column column-width="@width"/>
</xsl:for-each>
<fo:table-body>
<xsl:apply-templates />
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="dxl:tablerow">
<fo:table-row>
<xsl:apply-templates/>
</fo:table-row>
</xsl:template>
<xsl:template match="dxl:tablecell">
<xsl:variable name="rows">
<xsl:choose>
<xsl:when test="@rowspan">
<xsl:value-of select="@rowspan"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<fo:table-cell number-rows-spanned="{$rows}">
<xsl:apply-templates/>
</fo:table-cell>
</xsl:template>
提前致谢!
您可以创建第二个变量来计算包含当前 table 单元格
的行之后的所有 "blank" 行<xsl:variable
name="blankrows"
select="count(../following-sibling::dxl:tablerow[position() < number($rows)]
[not(dxl:tablecell)])" />
然后您可以按此数量调整 $rows 变量以生成 number-rows-spanned
属性。
试试这个 XSLT(带有虚构的命名空间...)
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:dxl="dxl" xmlns:fo="fo">
<xsl:output method="xml" indent="yes" />
<xsl:template match="dxl:table">
<fo:table width="100%" table-layout="fixed">
<xsl:for-each select="dxl:tablecolumn">
<fo:table-column column-width="@width"/>
</xsl:for-each>
<fo:table-body>
<xsl:apply-templates />
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="dxl:tablerow[not(dxl:tablecell)]" />
<xsl:template match="dxl:tablerow">
<fo:table-row>
<xsl:apply-templates/>
</fo:table-row>
</xsl:template>
<xsl:template match="dxl:tablecell">
<xsl:variable name="rows">
<xsl:choose>
<xsl:when test="@rowspan">
<xsl:value-of select="@rowspan"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="blankrows" select="count(../following-sibling::dxl:tablerow[position() < number($rows)][not(dxl:tablecell)])" />
<fo:table-cell>
<xsl:if test="$rows - 1 > $blankrows">
<xsl:attribute name="number-rows-spanned">
<xsl:value-of select="$rows - $blankrows" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</fo:table-cell>
</xsl:template>
</xsl:stylesheet>
我已将属性设置为有条件的,因此如果将其设置为 1 则不会显示它。
另请注意使用空模板 <xsl:template match="dxl:tablerow[not(dxl:tablecell)]" />
来删除空行本身。