【发布时间】:2011-12-21 10:02:18
【问题描述】:
我一直在努力解决这个问题的正确语法,它归结为:
如何测试父节点的属性是否有一定的值?
我正在转换一些 XHTML。我模板匹配<tr>,以便重新格式化该行中某些单元格的colspan 属性。为了进一步确信这只会发生在某些表中,我需要检查 <table> 所属的 <tr> 是否具有特定的 id 属性值。
<xsl:template match="tr">
<tr>
<xsl:choose>
<xsl:when test="(count(td[@colspan='2'])=2 and count(td)=3)">
<td colspan="1">
<xsl:copy-of select="td[1]/node()" />
</td>
<td colspan="4">
<xsl:copy-of select="td[2]/node()" />
</td>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="@*|node()" />
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:template>
这是我到目前为止的代码。我需要在我的 when 测试或另一个 xsl:if 或 xsl:when 中添加更多“和”来检查表属性。对于这种情况,让表 id="Transformable"。
为了澄清,我只希望在<tr> 所属的表的 id 为“Transformable”时进行上述转换。
任何帮助将不胜感激。
【问题讨论】:
-
请问可以发布一些您的源 XML 吗?一个样本就完美了。