Boolean, Comparison, and Set Expressions
Filter patterns can contain Boolean expressions, comparison expressions, and set expressions. Shortcuts listed in the following table represent alternative symbols that are provided in this XSL Transformations (XSLT) implementation. This article discusses these expression operators.
|and||Logical-and||price>9.00 and price<9.90|
author[degree and award]
|or||Logical-or||price=9.80 or price=9.70|
author[last-name = "Bob"]
degree[@from != "Harvard"]
|< *||Less than||price < 9.80|
|<= *||Less than or equal||price <= 9.80|
book[position() <= 3]
|> *||Greater than||price > 9.80|
|>= *||Greater than or equal||price >= 9.80|
||||Set operation; returns the union of two sets of nodes||//book | //cd|
Returns a node-set with all book and cd elements
Operators and Special Characters
XPath expressions are constructed using the operators and special characters shown in the following table.
|/||Child operator; selects immediate children of the left-side collection. When this path operator appears at the start of the pattern, it indicates that children should be selected from the root node.||/bookstore|
The document element (<bookstore>) of this document.
|//||Recursive descent; searches for the specified element at any depth. When this path operator appears at the start of the pattern, it indicates recursive descent from the root node.||//author|
All <author> elements in the document.
|.||Indicates the current context.||./first-name|
All <first-name> elements in the current context node. Note that this is equivalent to the expression in the next row.
|..||The parent of the current context node.||author[last-name = “Bob” and ../price > 50]|
All <author> elements that contain a <last-name> child element whose value is Bob, and a <price> sibling element whose value is greater than 50.
|*||Wildcard; selects all elements regardless of the element name.||author/*|
All element children of <author> elements
|@||Attribute; prefix for an attribute name.||price/@exchange|
The exchange attribute of <price> elements within the current context.
|@*||Attribute wildcard; selects all attributes regardless of name.|
|:||Namespace separator; separates the namespace prefix from the element or attribute name.||my:book|
The <book> element from my namespace.
|( )||Groups operations to explicitly establish precedence.|
|[ ]||Applies a filter pattern.|
|+||Performs addition.||6 + 4 results in 10|
|–||Performs subtraction.||6 – 4 results in 2|
|div||Performs floating-point division according to IEEE 754.||8 div 4 results in 2|
|*||Performs multiplication.||6 * 4 results in 24|
|mod||Returns the remainder from a truncating division.||5 mod 2 results in 1|