Skip to main content

XPath Operators

While XPath's primary power comes from its ability to navigate the tree structure of an XML document, its true flexibility is unlocked through the use of operators and functions. These are the tools that allow you to move beyond simple path selection and create complex, data-driven queries. An XPath expression can do more than just select a set of nodes. By using operators, an expression can be used to filter nodes based on their content, perform mathematical calculations, manipulate strings, and return a final value that is a node-set, a string, a boolean (true/false), or a number.

Classification of XPath Operators

XPath operators and functions can be grouped into the following categories, each serving a distinct purpose in building powerful expressions.

XPath's operators and functions can be grouped into the following categories. Click on a category below to dive into detailed explanations and practical examples for each.

Operators/FunctionsDescription
Comparison OperatorsUsed within predicates [...] to filter nodes by comparing their values (e.g., price > 30).
Boolean OperatorsLogical operators (and, or, not) used to combine multiple conditions within a predicate.
Number Functions/OperatorsA suite of functions and operators for performing mathematical calculations on numeric values (e.g., sum(), round()).
String FunctionsA comprehensive set of functions for manipulating and querying string values (e.g., contains(), starts-with()).
Node Functions/OperatorsFunctions that operate on node-sets, providing information about their position, count, and relationships (e.g., last(), count()).