• |
Location Steps |
Page •
of • |
- | node-set (an unordered collection of nodes without duplicates) | |
- | boolean (true or false) | |
- | number (a floating-point number) | |
- | string (a sequence of UCS characters) |
- | ||
- | ||
- | a set of variable bindings | |
- | a function library | |
- | the set of namespace declarations in scope for the
expression |
• | child::para selects the
para element children of the context node | |
• | child::* selects all element
children of the context node | |
• | child::text() selects all text
node children of the context node | |
• | child::node() selects all the
children of the context node, whatever their node type | |
• | attribute::name selects the
name attribute of the context node | |
• | attribute::* selects all the
attributes of the context node | |
• | descendant::para selects the
para element descendants of the context node | |
• | ancestor::div selects all div
ancestors of the context node | |
• | ancestor-or-self::div selects the
div ancestors of the context node and, if the context node is a
div element, the context node as well | |
• | descendant-or-self::para selects the
para element descendants of the context node and, if the context node is
a para element, the context node as well | |
• | self::para selects the context node if it is a
para element, and otherwise selects nothing | |
• | child::chapter/descendant::para
selects the para element descendants of the
chapter element children of the context node | |
• | child::*/child::para selects
all para grandchildren of the context node | |
• | / selects the document root (which is
always the parent of the document element) | |
• | /descendant::para selects all the
para elements in the same document as the context node | |
• | /descendant::olist/child::item selects all the
item elements that have an olist parent and
that are in the same document as the context node | |
• | child::para[position()=1] selects the first
para child of the context node | |
• | child::para[position()=last()] selects the last
para child of the context node | |
• | child::para[position()=last()-1] selects
the last but one para child of the context node | |
• | child::para[position()>1] selects all
the para children of the context node other than the
first para child of the context node | |
• | following-sibling::chapter[position()=1]
selects the next chapter sibling of the context node | |
• | preceding-sibling::chapter[position()=1]
selects the previous chapter sibling of the context
node | |
• | /descendant::figure[position()=42] selects
the forty-second figure element in the
document | |
• | /child::doc/child::chapter[position()=5]/child::section[position()=2]
selects the second section of the fifth
chapter of the doc document
element | |
• | child::para[attribute::type="warning"]
selects all para children of the context node that have a
type attribute with value warning | |
• | child::para[attribute::type='warning'][position()=5]
selects the fifth para child of the context node that has
a type attribute with value
warning | |
• | child::para[position()=5][attribute::type="warning"]
selects the fifth para child of the context node if that
child has a type attribute with value
warning | |
• | child::chapter[child::title='Introduction']
selects the chapter children of the context node that
have one or more title children with string-value equal to
Introduction | |
• | child::chapter[child::title] selects the
chapter children of the context node that have one or
more title children | |
• | child::*[self::chapter or self::appendix]
selects the chapter and appendix children of
the context node | |
• | child::*[self::chapter or
self::appendix][position()=last()] selects the last
chapter or appendix child of the context
node |
[1] | LocationPath | ::= | ||
[2] | AbsoluteLocationPath | ::= | '/' RelativeLocationPath? | |
[3] | RelativeLocationPath | ::= | ||
| RelativeLocationPath '/' Step | ||||
• | an axis, which specifies the tree relationship between the
nodes selected by the location step and the context node, | |
• | a node test, which specifies the node type and expanded-name of the nodes selected
by the location step, and | |
• | zero or more predicates, which use arbitrary expressions to
further refine the set of nodes selected by the location
step. |
[4] | Step | ::= | ||
[5] | AxisSpecifier | ::= | AxisName '::' | |
• | the child axis contains the children of the
context node | |
• | the descendant axis contains the descendants of
the context node; a descendant is a child or a child of a child and so
on; thus the descendant axis never contains attribute or namespace
nodes | |
• | the parent axis contains the parent of the context node, if there is
one | |
• | the ancestor axis contains the ancestors of the
context node; the ancestors of the context node consist of the
parent of context node and the
parent's parent and so on; thus, the ancestor axis will always include
the root node, unless the context node is the root node | |
• | the following-sibling axis contains all the
following siblings of the context node; if the
context node is an attribute node or namespace node, the
following-sibling axis is empty | |
• | the preceding-sibling axis contains all the
preceding siblings of the context node; if the context node is an
attribute node or namespace node, the preceding-sibling
axis is empty | |
• | the following axis 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 | |
• | the preceding axis 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 | |
• | the attribute axis contains the attributes of
the context node; the axis will be empty unless the context node is an
element | |
• | the namespace axis contains the namespace nodes
of the context node; the axis will be empty unless the context node
is an element | |
• | the self axis contains just the context node
itself | |
• | the descendant-or-self axis contains the context
node and the descendants of the context node | |
• | the ancestor-or-self axis contains the context
node and the ancestors of the context node; thus, the ancestor axis
will always include the root node |
[6] | AxisName | ::= | 'ancestor' | |
| 'ancestor-or-self' | ||||
| 'attribute' | ||||
| 'child' | ||||
| 'descendant' | ||||
| 'descendant-or-self' | ||||
| 'following' | ||||
| 'following-sibling' | ||||
| 'namespace' | ||||
| 'parent' | ||||
| 'preceding' | ||||
| 'preceding-sibling' | ||||
| 'self' | ||||
- | For the attribute axis, the principal node type is attribute. | |
- | For the namespace axis, the principal node type is namespace. | |
- | For other axes, the principal node type is element. |
[8] | Predicate | ::= | '[' PredicateExpr ']' | |
[9] | PredicateExpr | ::= | ||
• | para selects the para element children of
the context node | |
• | * 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 | |
• | @* selects all the attributes of the
context node | |
• | para[1] selects the first para child of
the context node | |
• | para[last()] selects the last para child
of the context node | |
• | */para selects all para grandchildren of
the context node | |
• | /doc/chapter[5]/section[2] selects the second
section of the fifth chapter of the
doc | |
• | chapter//para selects the para element
descendants of the chapter element children of the
context node | |
• | //para selects all the para descendants of
the document root and thus selects all para elements in the
same document as the context node | |
• | //olist/item selects all the item
elements in the same document as the context node that have an
olist parent | |
• | . selects the context node | |
• | .//para selects the para element
descendants of the context node | |
.. selects the parent of the context node | ||
• | ../@lang selects the lang attribute
of the parent of the context node | |
• | para[@type="warning"] selects all para
children of the context node that have a type attribute with
value warning | |
• | para[@type="warning"][5] selects the fifth
para child of the context node that has a type
attribute with value warning | |
• | para[5][@type="warning"] selects the fifth
para child of the context node if that child has a
type attribute with value warning | |
• | chapter[title="Introduction"] selects the
chapter children of the context node that have one or
more title children with string-value equal to
Introduction | |
• | chapter[title] selects the chapter
children of the context node that have one or more title
children | |
• | employee[@secretary and @assistant] selects all
the employee children of the context node that have both a
secretary attribute and an assistant
attribute |
self::node()/descendant-or-self::node()/child::para
[10] | AbbreviatedAbsoluteLocationPath | ::= | '//' RelativeLocationPath | |
[11] | AbbreviatedRelativeLocationPath | ::= | RelativeLocationPath '//' Step | |
[12] | AbbreviatedStep | ::= | '.' | |
| '..' | ||||
[13] | AbbreviatedAxisSpecifier | ::= | '@'? | |
[16] | FunctionCall | ::= | ||
[17] | Argument | ::= | ||
☞ | The meaning of a Predicate
depends crucially on which axis applies. For example,
preceding::foo[1] returns the first foo
element in reverse document order, because the axis that
applies to the [1] predicate is the preceding axis; by
contrast, (preceding::foo)[1] returns the first
foo element in document order, because the
axis that applies to the [1] predicate is the child
axis. |
[18] | UnionExpr | ::= | ||
[19] | PathExpr | ::= | ||
| FilterExpr '//' RelativeLocationPath | ||||
[20] | FilterExpr | ::= | ||
[21] | OrExpr | ::= | ||
[22] | AndExpr | ::= | ||
| AndExpr 'and' EqualityExpr | ||||
[23] | EqualityExpr | ::= | ||
| EqualityExpr '=' RelationalExpr | ||||
| EqualityExpr '!=' RelationalExpr | ||||
[24] | RelationalExpr | ::= | ||
| RelationalExpr '<' AdditiveExpr | ||||
| RelationalExpr '>' AdditiveExpr | ||||
| RelationalExpr '<=' AdditiveExpr | ||||
| RelationalExpr '>=' AdditiveExpr | ||||
☞ | Since XML allows - in names, the -
operator typically needs to be preceded by whitespace. For example,
foo-bar evaluates to a node-set containing the child
elements named foo-bar; foo - bar evaluates
to the difference of the result of converting the string-value of the first
foo child element to a number and the result of
converting the string-value
of the first bar child to a number. |
• | 5 mod 2 returns 1 | |
• | 5 mod -2 returns 1 | |
• | -5 mod 2 returns -1 | |
• | -5 mod -2 returns -1 |
☞ | This is the same as the % operator in Java and
ECMAScript. |
☞ | This is not the same as the IEEE 754 remainder operation, which
returns the remainder from a rounding division. |
[25] | AdditiveExpr | ::= | ||
[26] | MultiplicativeExpr | ::= | ||
| MultiplicativeExpr 'div' UnaryExpr | ||||
| MultiplicativeExpr 'mod' UnaryExpr | ||||
[27] | UnaryExpr | ::= | ||
| '-' UnaryExpr | ||||
☞ | It is possible in Unicode for there to be two strings that
should be treated as identical even though they consist of the
distinct sequences of Unicode abstract characters. For example, some
accented characters may be represented in either a precomposed or
decomposed form. Therefore, XPath expressions may return unexpected
results unless both the characters in the XPath expression and in the
XML document have been normalized into a canonical form. See [Character Model]. |
• | If there is a preceding token and the preceding token is not
one of @, ::, (,
[, , or an Operator, then a * must be
recognized as a MultiplyOperator
and an NCName must be
recognized as an OperatorName. | |
• | If the character following an NCName (possibly after intervening
ExprWhitespace) is (,
then the token must be recognized as a NodeType or a FunctionName. | |
• | If the two characters following an NCName (possibly after intervening
ExprWhitespace) are ::,
then the token must be recognized as an AxisName. | |
• | Otherwise, the token must not be recognized as a MultiplyOperator, an OperatorName, a NodeType, a FunctionName, or an AxisName. |
[28] | ExprToken | ::= | '(' | ')' | '[' | ']' | '.' | '..' | '@' | ',' | '::' | |
| NameTest | ||||
| NodeType | ||||
| Operator | ||||
| AxisName | ||||
| Literal | ||||
| Number | ||||
[29] | Literal | ::= | '"' [^"]* '"' | |
| "'" [^']* "'" | ||||
[30] | Number | ::= | ||
| '.' Digits | ||||
[31] | Digits | ::= | [0-9]+ | |
[32] | Operator | ::= | ||
| '/' | '//' | '|' | '+' | '-' | '=' | '!=' | '<' | '<=' | '>' | '>=' | ||||
[33] | OperatorName | ::= | 'and' | 'or' | 'mod' | 'div' | |
[34] | MultiplyOperator | ::= | '*' | |
[35] | FunctionName | ::= | ||
[36] | VariableReference | ::= | '$' QName | |
[37] | NameTest | ::= | '*' | |
| NCName ':' '*' | ||||
| QName | ||||
[38] | NodeType | ::= | 'comment' | |
| 'text' | ||||
| 'processing-instruction' | ||||
| 'node' | ||||
[39] | ExprWhitespace | ::= | ||
• | id("foo") selects the element with unique ID
foo | |
• | id("foo")/child::para[position()=5] selects
the fifth para child of the element with unique ID
foo |
☞ | The string returned by the
namespace-uri function will be empty except for
element nodes and attribute nodes. |
☞ | The string returned by the name function
will be the same as the string returned by the
local-name function except for element nodes and
attribute nodes. |
• | A node-set is converted to a string by returning the string-value of the node in the
node-set that is first in document
order. If the node-set is empty, an empty string is
returned. | ||||||||||||||||||||||
• | A number is converted to a string as follows
| ||||||||||||||||||||||
• | The boolean false value is converted to the string
false. The boolean true value is converted to the
string true. | ||||||||||||||||||||||
• | An object of a type other than the four basic types is
converted to a string in a way that is dependent on that
type. |
☞ | The string function is not intended for
converting numbers into strings for presentation to users. The
format-number function and xsl:number
element in [XSLT] provide this
functionality. |
☞ | This differs from Java and ECMAScript, in which the
String.substring method treats the position of the first
character as 0. |
• | substring("12345", 1.5, 2.6) returns
"234" | |
• | substring("12345", 0, 3) returns
"12" | |
• | substring("12345", 0 div 0, 3) returns
"" | |
• | substring("12345", 1, 0 div 0) returns
"" | |
• | substring("12345", -42, 1 div 0) returns
"12345" | |
• | substring("12345", -1 div 0, 1 div 0) returns
"" |
☞ | The translate function is not a sufficient
solution for case conversion in all languages. A future version of
XPath may provide additional functions for case conversion. |
• | a number is true if and only if it is neither positive or
negative zero nor NaN | |
• | a node-set is true if and only if it is non-empty | |
• | a string is true if and only if its length is non-zero | |
• | an object of a type other than the four basic types is
converted to a boolean in a way that is dependent on that
type |
<para xml:lang="en"/> <div xml:lang="en"><para/></div> <para xml:lang="EN"/> <para xml:lang="en-us"/>
• | a string that consists of optional whitespace followed by an
optional minus sign followed by a Number
followed by whitespace is converted to the IEEE 754 number that is
nearest (according to the IEEE 754 round-to-nearest rule)
to the mathematical value represented by the string; any other
string is converted to NaN | |
• | boolean true is converted to 1; boolean false is converted to
0 | |
• | a node-set is first converted to a string as if by a call to the
string function and then converted in the same way as a
string argument
| |
• | an object of a type other than the four basic types is
converted to a number in a way that is dependent on that
type |
☞ | The number function should not be used
for conversion of numeric data occurring in an element in an XML
document unless the element is of a type that represents numeric data
in a language-neutral format (which would typically be transformed
into a language-specific format for presentation to a user). In
addition, the number function cannot be used
unless the language-neutral format used by the element is consistent
with the XPath syntax for a Number. |
☞ |
• | root nodes | |
• | element nodes | |
• | text nodes | |
• | attribute nodes | |
• | namespace nodes | |
• | processing instruction nodes | |
• | comment nodes |
☞ | For element nodes and root nodes, the string-value of a node
is not the same as the string returned by the DOM
nodeValue method (see [DOM]). |
☞ | In the notation of Appendix A.3 of [XML Names],
the local part of the expanded-name corresponds to the
type attribute of the ExpEType element; the
namespace URI of the expanded-name corresponds to the ns
attribute of the ExpEType element, and is null if the
ns attribute of the ExpEType element is
omitted. |
☞ | If a document does not have a DTD, then no element in the
document will have a unique ID. |
☞ | This is different from the DOM, which does not treat the
element bearing an attribute as the parent of the attribute (see
[DOM]). |
☞ | The = operator tests whether two nodes have the
same value, not whether they are the same node. Thus
attributes of two different elements may compare as equal using
=, even though they are not the same node. |
☞ | In the notation of Appendix A.3 of [XML Names],
the local part of the expanded-name corresponds to the
name attribute of the ExpAName element; the
namespace URI of the expanded-name corresponds to the ns
attribute of the ExpAName element, and is null if the
ns attribute of the ExpAName element is
omitted. |
☞ | It is possible for default attributes to be declared in an
external DTD or an external parameter entity. The XML Recommendation
does not require an XML processor to read an external DTD or an
external parameter unless it is validating. A stylesheet or other facility that assumes
that the XPath tree contains default attribute values declared in an
external DTD or parameter entity may not work with some non-validating
XML processors. |
• | for every attribute on the element whose name starts with
xmlns:; | |||
• | for every attribute on an ancestor element whose name starts
xmlns: unless the element itself or a nearer ancestor
redeclares the prefix; | |||
• | for an xmlns attribute, if the element or some
ancestor has an xmlns attribute, and the value of the
xmlns attribute for the nearest such element is
non-empty
|
☞ | The XML declaration is not a processing instruction.
Therefore, there is no processing instruction node corresponding to the
XML declaration. |
☞ | When a text node that contains a < character
is written out as XML, the < character must be escaped
by, for example, using <, or including it in a
CDATA section. |
☞ | A new version of the XML Information Set Working Draft, which
will replace the May 17 version, was close to completion at the time
when the preparation of this version of XPath was completed and was
expected to be released at the same time or shortly after the release
of this version of XPath. The mapping is given for this new version
of the XML Information Set Working Draft. If the new version of the
XML Information Set Working has not yet been released, W3C members may
consult the internal Working Group version
http://www.w3.org/XML/Group/1999/09/WD-xml-infoset-19990915.html
(members
only). |
• | The root node comes from the document information item. The
children of the root node come from the children and children - comments
properties. | |
• | An element node comes from an element information item. The
children of an element node come from the children and children - comments properties. The
attributes of an element node come from the attributes property. The namespaces
of an element node come from the in-scope namespaces property. The
local part of the expanded-name of the element node
comes from the local name
property. The namespace URI of the expanded-name of the element node
comes from the namespace URI
property. The unique ID of the element node comes from the children property of the attribute
information item in the attributes property that has an attribute type property equal to
ID. | |
• | An attribute node comes from an attribute information item.
The local part of the expanded-name of the attribute node
comes from the local name
property. The namespace URI of the expanded-name of the attribute node
comes from the namespace URI
property. The string-value of
the node comes from concatenating the character code property of each member
of the children
property. | |
• | A text node comes from a sequence of one or more consecutive
character information items. The string-value of the node comes from
concatenating the character code
property of each of the character information items. | |
• | A processing instruction node comes from a processing
instruction information item. The local part of the expanded-name of the node comes from
the target property. (The
namespace URI part of the expanded-name of the node is null.)
The string-value of the node
comes from the content
property. There are no processing instruction nodes for processing
instruction items that are children of document type declaration
information item. | |
• | A comment node comes from a comment information item. The
string-value of the node
comes from the content property.
There are no comment nodes for comment information items that are
children of document type declaration information item. | |
• | A namespace node comes from a namespace declaration
information item. The local part of the expanded-name of the node comes from
the prefix property. (The
namespace URI part of the expanded-name of the node is null.)
The string-value of the node
comes from the namespace URI
property. |