Reference

XPath Quick Reference

Every axis, node test, predicate, and function in one place. Bookmark this page — you'll come back to it. Click Open in Sandbox on any entry to try the example against real XML.

Axes

Axes are how XPath moves around the document tree. Every location step has an axis (children by default) that decides which direction to look — down into descendants, up to ancestors, sideways to siblings, or onto attributes. Master the thirteen axes and almost everything else in XPath becomes a small variation on a familiar theme.

View full Axes reference (13 entries) →

Node Tests

Node tests filter what an axis returns by node kind. Beyond plain element names, XPath gives you generic tests for any node, just text, just comments, just processing instructions, or — with the @ shorthand — attributes. They're the verbs that pair with the axis nouns to form a location step.

View full Node Tests reference (6 entries) →

Predicates & Operators

Predicates are the square-bracket filters that narrow a node-set down to the items you actually want. Combined with comparison and boolean operators, they turn XPath into a tiny query language — pick the third item, the last one, the ones whose price is over ten, the ones with a particular attribute and not another. This is where most real XPath work happens.

View full Predicates & Operators reference (7 entries) →

Shorthand

Most XPath you read in the wild is shorthand: slashes, dots, and the @ sign that expand into longer axis-and-test forms. Knowing what each abbreviation stands for makes unfamiliar expressions instantly readable. These are the five you'll see ninety percent of the time.

View full Shorthand reference (5 entries) →

String Functions

String functions let you inspect, slice, and transform text content directly inside an XPath expression — no need to pull values into a host language first. The XPath 1.0 set is small but covers the essentials: containment checks, prefix and suffix tests, substring extraction, length, whitespace normalization, and character translation.

View full String Functions reference (10 entries) →

Number Functions

Number functions handle conversion and rounding. XPath quietly converts strings to numbers when you compare or add them, but explicit conversion with number() makes intent clear. Pair these with sum() over a node-set to do quick aggregations — totals, averages, counts of things meeting a threshold — without ever leaving the expression.

View full Number Functions reference (5 entries) →

Node-Set Functions

These functions answer questions about nodes themselves: how many there are, what they're named, what namespace they belong to. count() is the workhorse inside predicates and sanity checks. name() and local-name() matter the moment you deal with namespaced documents, where element names carry a prefix you may or may not want to match.

View full Node-Set Functions reference (7 entries) →

XPath 2.0+ / 3.1

XPath 2.0 and 3.1 are a different language in scale: real conditional and iteration constructs, regular expressions, sequence joins and quantifiers, and the arrow operator for fluent chaining. If you're stuck composing something awkward in XPath 1.0, there's a good chance the modern spec has a one-liner for it. Toggle the engine to 3.1 to try these.

View full XPath 2.0+ / 3.1 reference (24 entries) →

Higher-order Functions (3.1)

XPath 3.1 treats functions as values. You can pass inline functions to built-ins like for-each, filter, fold-left, and sort to map, prune, reduce, and reorder sequences without writing a FLWOR. These six are the core of the higher-order kit — once they click, a lot of awkward 1.0 patterns collapse into one-liners.

View full Higher-order Functions (3.1) reference (6 entries) →