Home >
Online Product Documentation >
Table of Contents >
XPath Quick Reference
XPath Quick Reference
This section includes the following topics:
See also
Precedence of Query Operators.
XPath Functions Quick Reference
Table 67 lists the XPath functions you can call in a query and provides short descriptions.
Function
|
Source
|
Returns
|
|
|
Boolean value that is the result of converting an object to a Boolean value. See
Converting an Object to Boolean.
|
|
|
Number that is the smallest integer that is not less than a number you specify. See
Obtaining the Largest, Smallest, or Closest Number.
|
|
|
|
|
|
String that concatenates two or more strings you specify. See
Concatenating Strings.
|
|
|
Nodes that contain the specified string. See
Searching for Strings.
|
|
|
Number of nodes in the node-set argument. See
Determining the Number of Nodes in a Collection.
|
|
|
Node for which the current template started its operation. See
Obtaining the Current Node for the Current XSLT Template.
|
|
|
|
|
|
Boolean value that indicates whether the specified element is supported by the XSLT processor. See
Determining If Functions Are Available.
|
|
|
|
|
|
Number that is the largest integer that is not greater than a number you specify. See
Obtaining the Largest, Smallest, or Closest Number.
|
|
|
Boolean value that indicates whether the specified function is supported by the XPath processor. See
Determining If Functions Are Available.
|
|
|
String that uniquely, temporarily, identifies a node. See
Generating Temporary IDs for Nodes.
|
|
|
Element whose
id attribute value matches the specified value. See
Finding an Element with a Particular ID.
|
|
|
Node whose
key value matches the specified key. See
Finding an Element with a Particular Key.
|
|
|
Boolean value that indicates whether the language of the node is the language you expect. See
Determining the Context Node Language.
|
|
|
|
|
|
Local portion of the node name, excluding the prefix. See
Obtaining Namespace Information.
|
|
|
String that contains the tag name of the node, including namespace information, if any. See
Obtaining Namespace Information.
|
|
|
URI for the namespace of the node. See
Obtaining Namespace Information.
|
|
|
|
|
|
String without leading or trailing white space. See
Normalizing Strings.
|
|
|
Boolean value that indicates the opposite of the specified Boolean value. See
Obtaining Boolean Values.
|
|
|
Number that is the result of converting the specified argument to a number. See
Converting an Object to a Number.
|
|
|
Position number of the node relative to the context node set. See
Finding a Particular Node.
|
|
|
Processing instruction nodes. If you specify a literal argument, this function returns a processing instruction if its name matches the literal you specify. See
Obtaining Particular Types of Nodes By Using Node Tests.
|
|
|
Number that is the closest to the argument and is an integer. See
Obtaining the Largest, Smallest, or Closest Number.
|
|
|
Boolean value that indicates if a string starts with a particular string. See
Finding Strings That Start with a Particular String.
|
|
|
String that is the result of converting some object to a string. See
Converting Objects to Strings.
|
|
|
Number of characters in a string you specify. See
Determining the Number of Characters in a String.
|
|
|
Substring that is in a particular position within its string. See
Finding Substrings by Position.
|
|
|
Substring that appears before a string you specify. See
Finding Substrings That Appear Before Strings You Specify.
|
|
|
Substring that appears after a string you specify. See
Finding Substrings That Appear After Strings You Specify.
|
|
|
Number that is the sum of the values of the nodes in the specified set. See
Obtaining the Sum of the Values in a Node Set.
|
|
|
Object that represents the specified property. See
Obtaining System Properties.
|
|
|
String with some characters replaced by other characters. See
Replacing Characters in Strings with Characters You Specify.
|
|
|
|
|
|
URI of an unparsed entity with the specified name. See
Obtaining the URI for an Unparsed Entity.
|
Table 67. XPath Function Quick Reference
XPath Syntax Quick Reference
This topic provides a quick reference for XPath expression syntax.
Axes
XPath provides the following axes:
-
ancestor
-
ancestor-or-self
-
attribute
-
child
-
descendant
-
descendant-or-self
-
following
-
following-sibling
-
namespace
-
parent
-
preceding
-
preceding-sibling
-
self
Node Tests
XPath provides the following node tests:
-
*
selects all nodes of the specified name. For the
attribute
axis, attributes are selected. For the
namespace
axis, namespace nodes are selected. For all other axes, element nodes are selected.
-
comment()
selects all comment nodes.
- element_name selects all element_name nodes.
-
node()
selects all nodes.
-
processing-instruction(["
some_literal
"])
selects all processing instructions. If some_literal is specified,
processing-instruction()
selects all processing instructions with some_literal as their name.
-
text()
selects all text nodes.
Filters
A filter specifies a constraint on a node set with respect to an axis to produce a new node set.
Location Steps
A location step has the following format:
XPath Expression
An XPath expression has one of the following formats:
A function call or an XPath expression in parentheses can appear only at the very beginning of an XPath expression. An expression in parentheses always returns a node set. Any function that appears at the beginning of an XPath location step expression must return a node set.
XPath Abbreviations Quick Reference
Table 68 defines the abbreviations you can use in XPath expressions:
Abbreviation
|
Description
|
No axis is specified in a location step.
|
The
child axis is assumed. For example, the following two XPath expressions both return the
para children of
chapter children of the context node:
|
@
|
The
attribute axis. For example, the following two XPath expressions both return
para children of the context node that have
type attributes with a value of
warning :
|
//
|
The
descendant-or-self axis. For example, the following two XPath expressions both return all
para descendants of the context node:
However, it is important to note that the following two expressions are
not equivalent:
The first expression selects the first
para element that is a descendant of the context node. The second expression selects each
para descendant that is the first
para child of its parent.
|
.
|
A single dot is the abbreviation for
self::node() . This selects the context node. For example, the following two XPath expressions both return all
para descendants of the context node:
|
..
|
A double dot is the abbreviation for
parent::node() . This selects the parent of the context node. For example, the following two XPath expressions both return the
title children of the parent of the context node:
|
Table 68. XPath Abbreviations Quick Reference
Table 69 shows examples of abbreviations in XPath expressions
Example
|
Description
|
para
|
Selects the
para children of the context node
|
*
|
Selects all element children of the context node
|
node_test
|
Evaluates all children of the context node and returns those that test
true for the particular node_test
|
*/para
|
Selects all
para grandchildren 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
|
/doc/chapter[5]/section[2]
|
Selects the second
section of the fifth
chapter of the
doc child of the context node
|
para[@type="warning"]
|
Selects
para children of the context node that have
type attributes with a value of
warning
|
para[@type="warning"][5]
|
Selects the fifth
para child of the context node that has a
type attribute with a value of
warning
|
para[5][@type="warning"]
|
Selects the fifth
para child of the context node if that child has a
type attribute with a value of
warning
|
chapter[title]
|
Selects the
chapter children of the context node that have one or more
title children
|
//para
|
Selects all
para descendants of the document root
|
chapter//para
|
Selects all
para descendants of
chapter children of the context node
|
//olist/item
|
Selects all
item elements that have
olist parents
|
.
|
Selects the context node
|
.//para
|
Selects the
para descendants of the context node
|
..
|
Selects the parent of the context node
|
@*
|
Selects all attributes of the context node
|
@name
|
Selects the
name attribute of the context node
|
../@name
|
Selects the
name attribute of the parent of the context node
|
Table 69. Abbreviations in XPath Expressions