PathExpr

Select a set of nodes along a path.


Syntax

PathExpr

LocationPath | FilterExpr | Filter Expr / RelativeLocationPath | FilterExpr // RelativeLocationPath

Description

Starting from a given point in a document tree, a PathExpr selects a node-set by following a location path. A path expression can be one of the following:

  • a location path, selecting a set of nodes by following location steps, starting either at the document root (absolute location path) or at the context node (relative location path),

  • a filter expression selecting a set of nodes e.g. as a result to a function call or an expression enclosed in parentheses, possibly followed by one or more predicates,

  • a filter expression followed by the path operator /, followed by a relative location path which starts with the set of nodes resulting from the filter expression,

  • a filter expression followed by the path operator //, followed by a relative location path which starts anywhere inside the set of nodes resulting from the filter expression

Compatibility

It corresponds to the expression PathExpr defined in XPath, Section 3.3, Rule 19.

Examples

  • Select all patients (a relative LocationPath starting at the context node which is the doctype element node patient in our example):

    patient
  • Select the answer to all questions (a simple FilterExpr can be just a PrimaryExpr which is basically an expression without operator such as a Number):

    42
  • Get the number of all patients (a FilterExpr that identifies a node-set which results from calling the standard XPath function count() with all patient nodes as argument):

    count(patient)
  • Get the number of all patients who died (a FilterExpr that identifies a node-set which results from calling the standard XPath function count(); the argument is the set of all patient nodes that have a descendant node deceased):

    count(patient[//deceased])
  • Select the names of all doctors who have discharged patients or had to register a patient's death provided that the doctor's surname begins with "G" (a FilterExpr enclosed in a parenthesized PrimaryExpr followed by a Predicate: select the union of the set of any descendant result/discharged nodes and result/deceased nodes; from this node set select all descendant name nodes that have an immediate child element node surname whose value contains a word beginning with "G"):

    ((//result/discharged | //result/deceased)//name)[surname ~= 'G*']

Related Expressions

Location Path
FilterExpr
SetExpr