XPath WD 2003 Syntax

This document includes material copied from or derived from the XPath specifications. Copyright © 1999-2017 W3C® (MIT, ERCIM, Keio, Beihang).

Abstract

This document describes the XPath 2.0 working draft (WD) syntax in terms of the finalised recommendation (REC) syntax. This syntax is supported in older versions of XQuery processors.

Table of Contents

A XPath Grammar

A.1 EBNF

REC WD Symbol   Expression
[1] [15] XPath ::= Expr?
[9] [23] AndExpr ::= InstanceofExpr ( "and" InstanceofExpr )*
[13] [31] MultiplicativeExpr ::= UnaryExpr ( ("*" | "div" | "idiv" | "mod") UnaryExpr )*
[20] [32] UnaryExpr ::= ("-" | "+")* UnionExpr
[15] [34] IntersectExceptExpr ::= ValueExpr ( ("intersect" | "except") ValueExpr )*
[24] [45-46] NodeComp ::= "is" | "isnot" | "<<" | ">>"
[31] [49] AbbreviatedForwardStep ::= ("@" NameTest) | NodeTest
[50] [61] SequenceType ::= ("empty" "(" ")") | (ItemType OccurrenceIndicator?)
[54] [64] KindTest ::= DocumentTest | ElementTest | AttributeTest | PITest | CommentTest | TextTest | AnyKindTest
[56] [68] DocumentTest ::= "document-node" "(" ElementTest? ")"
[59] [67] PITest ::= "processing-instruction" "(" StringLiteral? ")"
[60] [66] AttributeTest ::= "attribute" "(" ((SchemaContextPath "@" LocalName) | ("@" NodeName ("," TypeName)?))? ")"
[64] [65] ElementTest ::= "element" "(" ((SchemaContextPath LocalName) | (NodeName ("," TypeName "nillable"?)?))? ")"
  [72] SchemaContextPath ::= SchemaGlobalContext "/" SchemaContextStep "/"*
  [73] LocalName ::= QName
  [74] NodeName ::= QName | "*"
  [75] TypeName ::= QName | "*"

A.2 Terminal Symbols

REC WD Symbol   Expression
  [7] SchemaGlobalTypeName ::= "type" "(" QName ")"
  [8] SchemaGlobalContext ::= QName | SchemaGlobalTypeName
  [9] SchemaContextStep ::= QName

B References

B.1 W3C References

Core Specifications

C Differences Between WD and REC

The working draft syntax of XPath 2.0 has the following differences compared to the recommendation syntax.

  1. XPath expression is optional.
  2. Precedence order from AndExpr, MultiplicativeExpr, UnaryExpr, and IntersectExceptExpr.
  3. NodeComp has an extra isnot comparison operator.
  4. AbbreviatedForwardStep restricts attributes to name tests.
  5. SequenceType uses empty instead of empty-sequence for the empty sequence type.
  6. KindTest does not support SchemaElementTest and SchemaAttributeTest.
  7. ElementTest and AttributeTest kind tests support a schema path.
  8. PITest does not support using NCNames.