I'm trying to find every reference to a node (report) that does not have a child node (property) with a specific attributes values.
我正在尝试查找对没有具有特定属性值的子节点(属性)的节点(报告)的每个引用。
My xml is:
我的xml是:
<report xmlns="http://www.eclipse.org/birt/2005/design">
<property name="comments">comment</property>
<property name="test">sdcs</property>
<property name="eventHandlerClass">sdcs</property>
</report>
and my XPath is:
我的XPath是:
/*[local-name()='report'][not(/*[local-name()='property'][@name='eventHandlerClass'])]
Problem is, it is returning the report when I'm looking for it to not return anything.
问题是,当我正在寻找不返回任何内容时,它会返回报告。
Any idea's on the best way to do this?
有什么想法是最好的方法吗?
2 个解决方案
#1
1
The problem is that your report contains a property that is not an evenHandlerClass. You want to say there is no such child, which could be done by counting such children and getting zero:
问题是您的报告包含的属性不是evenHandlerClass。你想说没有这样的孩子,这可以通过计算这些孩子并获得零来完成:
/*[local-name()='report'][count(*[(local-name()='property' and @name="eventHandlerClass")])=0]
#2
0
Please register a namespace before you execute your XPath.
请在执行XPath之前注册命名空间。
Using local-name()
works but it produces very inelegant (and inefficient) XPath.
使用local-name()可以工作,但它会产生非常不优雅(且效率低下)的XPath。
Supposing you have registered "http://www.eclipse.org/birt/2005/design"
as birt
:
假设您已将“http://www.eclipse.org/birt/2005/design”注册为birt:
//birt:report[not(birt:property[@name='eventHandlerClass'])]
If for some reason you cannot register a namespace, use (wrapped for legibility)
如果由于某种原因您无法注册命名空间,请使用(包装为易读性)
//*[
local-name() = 'report'
and not(
*[@local-name() = 'property' and @name='eventHandlerClass']
)
]
#1
1
The problem is that your report contains a property that is not an evenHandlerClass. You want to say there is no such child, which could be done by counting such children and getting zero:
问题是您的报告包含的属性不是evenHandlerClass。你想说没有这样的孩子,这可以通过计算这些孩子并获得零来完成:
/*[local-name()='report'][count(*[(local-name()='property' and @name="eventHandlerClass")])=0]
#2
0
Please register a namespace before you execute your XPath.
请在执行XPath之前注册命名空间。
Using local-name()
works but it produces very inelegant (and inefficient) XPath.
使用local-name()可以工作,但它会产生非常不优雅(且效率低下)的XPath。
Supposing you have registered "http://www.eclipse.org/birt/2005/design"
as birt
:
假设您已将“http://www.eclipse.org/birt/2005/design”注册为birt:
//birt:report[not(birt:property[@name='eventHandlerClass'])]
If for some reason you cannot register a namespace, use (wrapped for legibility)
如果由于某种原因您无法注册命名空间,请使用(包装为易读性)
//*[
local-name() = 'report'
and not(
*[@local-name() = 'property' and @name='eventHandlerClass']
)
]