Boolean operators and parenthesis
- Last UpdatedJan 28, 2025
- 2 minute read
&& (And)
This operator is used to check whether two Boolean expressions are both true.
left-expression && right-expression
|
Arguments |
Description |
|---|---|
|
left-expression |
An arbitrary Boolean expression, which resulting value will be compared with the value from right-expression |
|
right-expression |
An arbitrary Boolean expression, which resulting value will be compared with the value from left-expression |
Examples:
./@id ==? ‘CL’ && ./@name == ‘MOTOR’
Assuming the value of @id is "CL001" and the value of @name is "MOTOR", the result of the above example will be true.
./@name ==? ‘Electric’ && ./@name ?== ‘MOTOR’
Assuming the value of @name is "ELECTRIC MOTOR", or "Electrical Motor", the result of the above example will be true.
|| (Or)
This operator is used to check whether at least one out of two Boolean expressions are true.
left-expression || right-expression
|
Arguments |
Description |
|---|---|
|
left-expression |
An arbitrary Boolean expression, which resulting value will be compared with the value from right-expression |
|
right-expression |
An arbitrary Boolean expression, which resulting value will be compared with the value from left-expression |
Examples:
./@name == ‘Pump’ || ./@extends == ‘Pump’
The result of the above example will be true if either the value of @name is "Pump", or the value of @extends is "Pump" (or if both is "Pump").
?: (If-Else)
This operator is used to pick one out of two values, depending on a condition.
condition-expression ? true-expression : false-expression
|
Arguments |
Description |
|---|---|
|
condition-expression |
An arbitrary Boolean expression, which decides whether to pick the true-expression or the false-expression |
|
true-expression |
The expression to use if condition-expression resolves to true |
|
false-expression |
The expression to use if condition-expression resolves to false |
Examples:
./@obsolete ? ‘Obsolete’ : ‘Active’
The result of the above example will be ‘Obsolete’ if the current context node is obsolete, else it will be ‘Active’.
./@name == ‘Pump’ ? ‘X’ : ‘O’
The result of the above example will be ‘X’ if the @name of current context node equals Pump, else the result will be ‘O’.
Note: If the condition-expression is a complex expression, to ensure expected result, you should enclose the expression syntax in parentheses:
(‘Pump’ == ./@name ?? ./@id) ? ‘X’ : ‘O’
Combining Boolean expressions with parenthesis
In more complex Boolean expressions, parenthesis can be used to group expressions logically together.
Examples:
(./@name == ‘Pump’ || ./@extends == ‘Pump’) && (./@abstract !== true)
The result of the above example will be true if either the value of @name is "Pump", or the value of @extends is "Pump" (or if both is "Pump") and the value of @abstract is not "true".
! (Not)
This operator is used to negate a Boolean expression.
Examples:
!./@abstract
The result of the above example will be true if @abstract is false, and vice versa.
!(./@abstract || ./@obsolete)
The result of the above example will be true if both @abstract and @obsolete is false, and vice versa.