Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath logical operator precedence of AND and OR, without parenthesis

I'm writing an xpath expression to achieve this:

//parent[(childA[contains(.,"foo")] or childB[contains(.,"foo")]) AND (childA[contains(.,"bar")] or childB[contains(.,"bar")])]

which is to select a parent whose children (childA or childB or both childA and childB together) contain both the strings "foo" and "bar".

I'm not sure whether parenthesis before and after AND is correctly used. Can xpath have parenthesis like this?

Thanks in advance!!

like image 963
Luke Chen Avatar asked Mar 19 '14 01:03

Luke Chen


1 Answers

See http://www.w3.org/TR/xpath/#section-Expressions. In particular:

Parentheses may be used for grouping.

and

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. 
like image 67
keshlam Avatar answered Nov 26 '22 13:11

keshlam