AbbreviatedStep

Select context, parent, or attribute node using abbreviated syntax.


Syntax

AbbreviatedStep

graphics/AbbreviatedStep.png

NameTest StepQualifiers

Description

An AbbreviatedStep selects the context node, its parent node or some attribute node by using abbreviated syntax. The symbol .. is short for parent::node(). The symbol . is short for self::node() if it is prepended by a path expression, otherwise it is short for the context item. Similarly, @ refers to the attribute axis and is the abbreviation for attribute::. It is followed by a name test and zero or more predicate expressions, since the corresponding rule (StepQualifiers) allows an empty predicate. The child axis is the default axis, so that you can simply omit the axis name in front of the element name

Examples

  • Select all books published after 1990.

    input()/bib/book[./@year > 1990]

    This is short for input()/child::bib/child::book[self::node()/attribute::year > 1990]. Using "." to select the context node is not necessary here, but merely emphasizes that it is the element node book, where an attribute satisfying the predicate is looked for.

  • Select all nodes that are parent of an element node name.

    input()//name/..

    This is short for input()/descendant-or-self::node/child::name/parent::node(). For the patient database this retrieves all patient, nextofkin and doctor nodes, since they all have name as an element child node.

  • Select all doctors with a pager.

    input()//doctor[@pager]

    This is short for input()/descendant-or-self::node/child::doctor[attribute::pager]. The abbreviated step uses @ to select the attribute axis and then checks for an attribute with the name pager () and selects all doctor elements that have an attribute node with the name pager (NameTest with empty StepQualifiers).

  • Select all attribute nodes of all doctypes in the current collection.

    input()//@*

    Here, the name test following the "@" is a wildcard expression matching all of the selected kind of node.

  • Sort a sequence of numbers:

    (3, 1, 2) sort by (.)

    In this example . selects the context item.

Related Syntax Constructs

The following construct(s) refer to this construct:

This construct is also related to the following construct(s):

NameTest StepQualifiers