XPath (XML Path Language)

XPath, the XML Path Language, is a language for addressing parts of an XML document. The W3C Recommendation describes it concisely: “XPath is a language for addressing parts of an XML document, designed to be used by both XSLT and XPointer.” Rather than transforming or producing documents, XPath does one thing well: given an XML document modeled as a tree of nodes, it selects the nodes that match a given expression. This focused role makes it a building block that other XML technologies rely on.

XPath 1.0 was published as a W3C Recommendation on 16 November 1999, alongside XSLT 1.0. It was created to serve the common addressing needs of XSLT and XPointer, which had each been developing their own path syntaxes; factoring that shared functionality into a single language avoided duplication and gave both a common foundation. Later versions broadened the language considerably: XPath 2.0 and XPath 3.1 (the latter reaching Recommendation on 21 March 2017) added a richer type system and shared a data model with XQuery, making XPath a fuller expression language rather than only a node-selection notation.

The syntax that gives XPath its name is path-based and deliberately compact, resembling the slash-separated paths of a filesystem. An expression describes a route through the document tree — from a context node, along an axis such as child or ancestor, selecting nodes by name, position, or predicate. Predicates in square brackets filter a selection by conditions, and a small library of functions supports string, numeric, and boolean operations. The result of an XPath 1.0 expression is one of four basic types: a node-set, a string, a number, or a boolean.

XPath’s primary consumer is XSLT, where every template match pattern and value-selection is an XPath expression; without XPath, XSLT would have no way to say which parts of the source document a rule applies to. Beyond XSLT, XPath is embedded in XQuery, in XML Schema identity constraints, in XPointer, and in the DOM and countless programming-language libraries that let code query XML documents directly. This reuse made XPath one of the most widely embedded of the XML standards.

Because it offers a standardized, declarative way to point at exactly the data you want inside a hierarchical document, XPath outlived many of its sibling technologies’ specific use cases. Its path-and-predicate model influenced later query and selection languages, and even today XPath expressions are a common way to locate elements in XML and in HTML documents across tools, test frameworks, and data-processing pipelines.

Sources

Last verified June 8, 2026