2014-03-19 10 views
5

Ich bin ein XPath-Ausdruck zu schreiben, dies zu erreichen:XPath logischer Operator Vorrang von AND und OR, ohne Klammer

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

, die einen Elternteil, dessen Kinder (Childa oder childB oder beide Childa und childB zusammen zu wählen ist) enthalten beide Strings "foo" und "bar".

Ich bin nicht sicher, ob Klammern vor und nach UND korrekt verwendet wird. Kann xpath Klammern haben?

Vielen Dank im Voraus!

Antwort

7

Siehe http://www.w3.org/TR/xpath/#section-Expressions. Insbesondere gilt Folgendes:

Parentheses may be used for grouping. 

und

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. 
+0

Re 3> 2> 1, das ist nur wahr für XPath 1.0. In XPath 2.0 ist dieser Ausdruck nicht mehr zulässig. (Die Frage bezog sich nicht speziell auf XPath 1.0). –