我想构造一个XPath查询,它将返回一个"div"或"table"元素,只要它有一个包含文本"abc"的后代.一个警告是它不能有任何div或table后代.
<div>
<table>
<form>
<div>
<span>
<p>abcdefg</p>
</span>
</div>
<table>
<span>
<p>123456</p>
</span>
</table>
</form>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
所以这个查询唯一正确的结果是:
/div/table/form/div
Run Code Online (Sandbox Code Playgroud)
我最好的尝试看起来像这样:
//div[contains(//text(), "abc") and not(descendant::div or descendant::table)] | //table[contains(//text(), "abc") and not(descendant::div or descendant::table)]
Run Code Online (Sandbox Code Playgroud)
但不会返回正确的结果.
谢谢你的帮助.