Xpath Reference: by Keimoon
Xpath Reference: by Keimoon
By KeiMOon
Table of contents
1. Data model
2. Location paths
3. Expressions
4. Core functions
Data model
Node type
Root node:
string value = concatenation of all string value
Element node
string value = concatenation of all string value
Attribute node
string value = text
has element node as its parent, but is not a child.
Data model
Node type (cont)
Namespace node
string value is the URI
Processing instruction node
Comment node
Text node
Must be a child of a element node
Will have no sibling
Location paths
Location path
LocationPath ::= RelativeLocationPath |
AbsoluteLocationPath
AbsoluteLocationPath ::= '/' RelativeLocationPath? |
AbbreviatedAbsoluteLocationPath
RelativeLocationPath ::= Step | RelativeLocationPath '/'
Step | AbbreviatedRelativeLocationPath
Location Paths
Location step
Step ::= AxisSpecifier NodeTest Predicate* |
AbbreviatedStep
AxisSpecifier ::= AxisName '::’ |
AbbreviatedAxisSpecifier
Location paths
Axis name
AxisName ::= 'ancestor | 'ancestor-or-self’ | 'attribute’|
'child’ | 'descendant’ | 'descendant-or-self’ |
'following’ | 'following-sibling’ | 'namespace’ |
'parent’ | 'preceding’ | 'preceding-sibling’| 'self'
Location Paths
Axis Name (cont)
child : contains the children of the context node
descendant : contains the descendants of the context
node
parent : contains the parent of the context node
ancestor : contains the ancestors of the context node
following-sibling : contains all the following siblings of
the context node
preceding-sibling : contains all the preceding siblings of
the context node
Location Paths
Axis name (cont)
following : contains all nodes in the same document as
the context node that are after the context node in
document order, excluding any descendants and
excluding attribute nodes and namespace nodes
preceding : contains all nodes in the same document as
the context node that are before the context node in
document order, excluding any ancestors and excluding
attribute nodes and namespace nodes
Location Paths
Axis name
attribute : contains the attributes of the context node
namespace : contains the namespace nodes of the
context node
self : contains just the context node itself
descendant-or-self : contains the context node and the
descendants of the context node
ancestor-or-self : contains the context node and the
ancestors of the context node
Location Paths
Node test
NodeTest ::= NameTest | NodeType '(' ')’ |
'processing-instruction' '(' Literal ')'
Location paths
Predicates
Predicate ::= '[' PredicateExpr ']'
PredicateExpr ::= Expr
Location paths
Abbreviations
* selects all element children of the context node
text() selects all text node children of the context node
@name selects the name attribute of the context node
// is short for /descendant-or-self::node()/
. is short for self::node()
.. is short for parent::node()
Expressions
Basics
Expr ::= OrExpr
PrimaryExpr ::= VariableReference | '(' Expr ')’ | Literal |
Number | FunctionCal
Function calls
FunctionCall ::= FunctionName '(' ( Argument ( ','
Argument )* )? ')'
Argument ::= Expr
Expressions
Node sets
UnionExpr ::= PathExpr | UnionExpr '|' PathExpr
PathExpr ::= LocationPath | FilterExpr | FilterExpr '/’
RelativeLocationPath| FilterExpr '//' RelativeLocationPath