xml xpath 以选择按属性值列表排除的节点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11499946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
xpath to select nodes excluding by attribute value list
提问by Aitorito
I would like to know if there is shorter approach to selecting a list of nodes ignoring the ones that have an attribute value specified in a list
我想知道是否有更短的方法来选择节点列表,而忽略那些在列表中指定了属性值的节点
Working example:
工作示例:
/item[not(@uid='id1') and not(@uid='id2')]
Desired alternative:
期望的替代方案:
/item[not(@uid in('id1','id2'))]
回答by Arne
You can either use regex - if your xpath implementation supports it - or write
您可以使用正则表达式 - 如果您的 xpath 实现支持它 - 或者写
/item[not(@uid='id1' or @uid='id2')]
which might be a bit shorter.
这可能会短一点。
回答by Dimitre Novatchev
If the list of attribute names is very long, the following is a good way to handle this situation:
如果属性名称列表很长,以下是处理这种情况的好方法:
//item[not(contains('|attr1|attr2|attr3|attr4|attr5|attr6|attrN|',
concat('|', @uid, '|')
)
)]
回答by VSP
Maybe something like this??
也许像这样??
/item[not(contains('id1 id2', @uid))]
回答by BeniBela
At least in Xpath 2 general comparisons on sequences are performed pairwise and existentially, so you can write:
至少在 Xpath 2 中,对序列的一般比较是成对和存在地执行的,因此您可以编写:
/item[not(@uid = ('id1','id2'))]

