INPUT
<?xml version="1.0"?>
<TABLE>
<THEAD>
<ROW id="rh">
<CELL rowmerged="F" rowspan="1" >
<Para >A</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >B</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >C</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >D</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >F</Para>
</CELL>
</ROW>
</THEAD>
<TBODY editable="T">
<ROW id="r1">
<CELL rowmerged="T" rowspan="2" >
<Para >11</Para>
</CELL>
<CELL rowmerged="T" rowspan="2" >
<Para >12</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >13</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >14</Para>
</CELL>
<CELL rowmerged="T" rowspan="2" >
<Para ></Para>
</CELL>
</ROW>
<ROW id="r2">
<CELL rowmerged="T" rowspan="2" >
<Para ></Para>
</CELL>
<CELL rowmerged="T" rowspan="2" >
<Para ></Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >23</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >24</Para>
</CELL>
<CELL rowmerged="T" rowspan="2" >
<Para ></Para>
</CELL>
</ROW>
</TBODY>
</TABLE>
输出:
<?xml version="1.0"?>
<TABLE>
<THEAD>
<ROW id="rh">
<CELL rowmerged="F" rowspan="1" >
<Para >A</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >B</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >C</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >D</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >F</Para>
</CELL>
</ROW>
</THEAD>
<TBODY editable="T">
<ROW id="r1">
<CELL rowmerged="F" rowspan="1" >
<Para >11</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >12</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >13</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >14</Para>
</CELL>
<CELL rowmerged="F" rowspan=1" >
<Para ></Para>
</CELL>
</ROW>
<ROW id="r2">
<CELL rowmerged="F" rowspan="1" >
<Para >11</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >12</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >23</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para >24</Para>
</CELL>
<CELL rowmerged="F" rowspan="1" >
<Para ></Para>
</CELL>
</ROW>
</TBODY>
</TABLE>
使用此转换XSL转换输入XML时:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>
<xsl:template match="CELL">
<CELL rowmerged="F" rowspan="1">
<xsl:apply-templates select="node()"/>
</CELL>
</xsl:template>
<xsl:template match="Para[not(normalize-space())][../@rowmerged='T']">
<xsl:variable name="cellnum" select="count(../preceding-sibling::CELL) + 1" />
<xsl:variable name="matchingCells" select="
../../preceding-sibling::ROW/CELL[$cellnum]/Para" />
<xsl:copy-of select="$matchingCells[normalize-space()][last()]" />
</xsl:template>
未评估的标签未被确切的位置替换,因此返回
<CELL>
Para not found in OUTPUTXML
</CELL>
我们生成了输出,但在发生行合并时,EMPTY Para(<Para>
)内容丢失了。
请帮助我实现这个目标,并且我是这个XSLT的新手。 规则:对于合并行:将主合并单元格的内容复制到合并行中的其他单元格。在这种情况下,你能帮我解决吗?我是xslt的新手。
答案 0 :(得分:0)
要保留没有文本节点的元素,您应该执行以下操作:
<Para>
<xsl:value-of select="$matchingCells[normalize-space()][last()]"/>
</Para>
您的模板几乎无法读取。为什么要这么麻烦:
Para[not(normalize-space())][../@rowmerged='T']
如果你能更清楚地解释你想要得到什么,那将会更有帮助。