鉴于此XML片段:
<table>
<tbody>
<tr>
<td>
<strong>Specifications</strong>
</td>
</tr>
<tr>
<td>Finish</td>
<td>Black</td>
</tr>
<tr>
<td>Action</td>
<td>Semi-Automatic</td>
</tr>
<tr>
<td>Caliber</td>
<td>7.62mmX39mm</td>
</tr>
</tbody>
</table>
我正在尝试选择所有tr
个不包含文本Specifications
的{@ 1}}元素,但我对XPath感到很恐怖并且无法正确使用它。我试过了
//table/tbody/tr[not(contains(text(),'Specifications'))]
但显然仍然是我的tr
节点包含Specifications
。
答案 0 :(得分:2)
请求的XPath:
/table/tbody/tr[not(.//text()[contains(.,'Specifications')])]
示例测试程序:
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<table>
<tbody>
<xsl:copy-of select="/table/tbody/tr[not(.//text()[contains(.,'Specifications')])]"/>
</tbody>
</table>
</xsl:template>
</xsl:transform>
根据您的输入提供输出:
<?xml version="1.0" encoding="utf-8"?>
<table>
<tbody>
<tr>
<td>Finish</td>
<td>Black</td>
</tr>
<tr>
<td>Action</td>
<td>Semi-Automatic</td>
</tr>
<tr>
<td>Caliber</td>
<td>7.62mmX39mm</td>
</tr>
</tbody>
</table>
答案 1 :(得分:1)
// table / tbody / tr [not(contains(td,'Specifications'))]#bad one
// table / tbody / tr [not(contains(。,'Specifications'))]#better