1 Introduction

The primary purpose of XPath is to address the nodes of XML trees and JSON trees. XPath gets its name from its use of a path notation for navigating through the hierarchical structure of an XML document. XPath uses a compact, non-XML syntax to facilitate use of XPath within URIs and XML attribute values. XPath 4.0 adds a similar syntax for navigating JSON trees.

[Definition: XPath 4.0 operates on the abstract, logical structure of an XML document or JSON object, rather than its surface syntax. This logical structure, known as the data model, is defined in [XQuery and XPath Data Model (XDM) 3.1].]

XPath is designed to be embedded in a host language such as [XSL Transformations (XSLT) Version 3.0] or [XQuery 3.1: An XML Query Language]. [Definition: A host language for XPath is a language or specification that incorporates XPath as a sublanguage and that defines how the static and dynamic context for evaluation of XPath expressions are to be established.]

XPath 4.0 is a subset of XQuery 4.0. In general, any expression that is syntactically valid and executes successfully in both XPath 4.0 and XQuery 4.0 will return the same result in both languages. There are a few exceptions to this rule:

Because these languages are so closely related, their grammars and language descriptions are generated from a common source to ensure consistency, and the editors of these specifications work together closely.

XPath 4.0 also depends on and is closely related to the following specifications:

This document specifies a grammar for XPath 4.0, using the same basic EBNF notation used in [XML 1.0]. Unless otherwise noted (see A.2 Lexical structure), whitespace is not significant in expressions. Grammar productions are introduced together with the features that they describe, and a complete grammar is also presented in the appendix [A XPath 4.0 Grammar]. The appendix is the normative version.

In the grammar productions in this document, named symbols are underlined and literal text is enclosed in double quotes. For example, the following productions describe the syntax of a static function call:

[79]    FunctionCall    ::=    EQName ArgumentList /* xgc: reserved-function-names */
/* gn: parens */
[61]    ArgumentList    ::=    "(" ((PositionalArguments ("," KeywordArguments)?) | KeywordArguments)? ")"

The productions should be read as follows: A function call consists of an EQName followed by an ArgumentList. The argument list consists of an opening parenthesis, an optional list of one or more arguments (separated by commas), and a closing parenthesis.

This document normatively defines the static and dynamic semantics of XPath 4.0. In this document, examples and material labeled as "Note" are provided for explanatory purposes and are not normative.

Certain aspects of language processing are described in this specification as implementation-defined or implementation-dependent.

A language aspect described in this specification as implementation-defined or implementation dependent may be further constrained by the specifications of a host language in which XPath is embedded.