Home

Descendantorself

Descendant-or-self refers to an XPath axis used in XML path expressions. It selects the current context node and all of its descendants in the document tree. This axis is part of XPath 1.0 and 2.0, and is commonly employed in XSLT, XQuery, and related technologies to navigate hierarchical data.

In an XPath expression, the axis is written as descendant-or-self::. The node test that follows determines which

Key distinctions include the contrast with the descendant axis, which starts from the children of the context

Common use cases include locating all relevant elements within a subtree, filtering results by type or name,

Overall, descendant-or-self is a foundational tool in XPath for subtree traversal, providing a simple way to

nodes
on
that
axis
are
included.
For
example,
descendant-or-self::node()
selects
every
node
from
the
current
node
downward,
including
the
current
node.
Using
descendant-or-self::*
selects
all
element
nodes
on
and
beneath
the
current
node.
A
concrete
usage
is
book/descendant-or-self::*
to
retrieve
the
book
element
and
all
of
its
descendant
elements.
node
and
excludes
the
context
node
itself,
and
the
self
axis,
which
selects
only
the
context
node.
The
descendant-or-self
axis
therefore
combines
both
capabilities,
enabling
concise
queries
that
must
consider
both
the
starting
node
and
all
nodes
below
it.
and
combining
with
predicates
to
narrow
results.
It
is
frequently
used
in
template
rules,
document
querying,
and
data
extraction
tasks
that
involve
recursive
tree
structures.
include
both
a
node
and
its
entire
downward
hierarchy
in
a
single
axis.