Appendix A. XPath 1.0 Grammar

This appendix contains the entire grammar for the syntax of XPath 1.0. Refer to this section to remove any doubt about what is a syntactically valid expression.

Productions from XPath 1.0

Table A-1 through Table A-12 list the entire grammar of XPath 1.0, extracted from the XPath 1.0 Recommendation at http://www.w3.org/TR/xpath.

Table A-1. Location paths

[1]

LocationPath

RelativeLocationPath
| AbsoluteLocationPath

[2]

AbsoluteLocationPath

'/' RelativeLocationPath?
| AbbreviatedAbsoluteLocationPath

[3]

RelativeLocationPath

Step
| RelativeLocationPath '/' Step
| AbbreviatedRelativeLocationPath

Table A-2. Location steps

[4]

Step

AxisSpecifier NodeTest Predicate*
| AbbreviatedStep

[5]

AxisSpecifier

AxisName '::'
| AbbreviatedAxisSpecifier

Table A-3. Axes

[6]

AxisName

'ancestor'
| 'ancestor-or-self'
| 'attribute'
| 'child'
| 'descendant'
| 'descendant-or-self'
| 'following'
| 'following-sibling'
| 'namespace'
| 'parent'
| 'preceding'
| 'preceding-sibling'
| 'self'

Table A-4. Node tests

[7]

NodeTest

NameTest
| NodeType '(' ')'
| 'processing-instruction'
  '(' Literal ')'

Table A-5. Predicates

[8]

Predicate

'[' PredicateExpr ']'

[9]

PredicateExpr

Expr

Table A-6. Abbreviations

[10]

AbbreviatedAbsoluteLocation-Path

'//'
RelativeLocation-Path

[11]

AbbreviatedRelativeLocation-Path

RelativeLocation-Path
'//' Step

[12]

AbbreviatedStep

'.'
| '..'

[13]

AbbreviatedAxisSpecifier

'@'?

Table A-7. Expressions

[14]

Expr

OrExpr

[15]

PrimaryExpr

VariableReference | '(' Expr ')' | Literal | Number | FunctionCall ...

Get XSLT 1.0 Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.