我正在写一个xpath表达式来实现这个目的:
//parent[(childA[contains(.,"foo")] or childB[contains(.,"foo")]) AND (childA[contains(.,"bar")] or childB[contains(.,"bar")])]
用于选择其子项(childA或childB或childA和childB一起)包含字符串“foo”和“bar”的父项。
我不确定是否正确使用了AND之前和之后的括号。 xpath可以有这样的括号吗?
提前致谢!!
答案 0 :(得分:7)
见http://www.w3.org/TR/xpath/#section-Expressions。特别是:
Parentheses may be used for grouping.
和
NOTE: The effect of the above grammar is that the order of precedence is
(lowest precedence first):
or
and
=, !=
<=, <, >=, >
and the operators are all left associative. For example, 3 > 2 > 1 is
equivalent to (3 > 2) > 1, which evaluates to false.