XPath 选择所有父节点不包含特定属性和值的节点 [英] XPath Select Nodes where all parent nodes do not contain specific attribute and value
本文介绍了XPath 选择所有父节点不包含特定属性和值的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 XML 结构:
I have the following XML structure:
<root>
<Level1 IsEnabled="0"> <!-- Disabled -->
<Level2 IsEnabled="1">
<Level3 IsEnabled="1">
<Level4 IsEnabled="1">
<Child /> <!-- Don't include this one -->
</Level4>
</Level3>
</Level2>
</Level1>
<Level1 IsEnabled="1">
<Level2 IsEnabled="1">
<Level3 IsEnabled="0"> <!-- Disabled -->
<Level4 IsEnabled="1">
<Child /> <!-- Don't include this one -->
</Level4>
</Level3>
</Level2>
</Level1>
<Level1 IsEnabled="1">
<Level2 IsEnabled="1">
<Level3 IsEnabled="1">
<Level4 IsEnabled="1">
<Child /><!-- Include this one -->
</Level4>
</Level3>
</Level2>
</Level1>
</root>
我想选择其任何祖先不包含 IsEnabled="0" 的所有子节点.所以对于上面的 XML,我只想选择最后一个子节点.此外,如果祖先节点不包含 IsEnabled 属性,则仍应包含子节点.
I want to select all child nodes where any of its ancestors do not contain IsEnabled="0". So for the XML above I only want to select the last child node. In addition, if a ancestor node doesn't contain a IsEnabled attribute, then the child should still be included.
推荐答案
问:我想选择其任何祖先不包含 IsEnabled="0" 的所有子节点试试这个:
Q: I want to select all child nodes where any of its ancestors do not contain IsEnabled="0" Try this:
//Child[not(ancestor::*[@IsEnabled='0'])]
这篇关于XPath 选择所有父节点不包含特定属性和值的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文