25.12.2013 Views

Tamino XQuery User Guide - Software AG Documentation

Tamino XQuery User Guide - Software AG Documentation

Tamino XQuery User Guide - Software AG Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The Nuts and Bolts of <strong>XQuery</strong><br />

Path Expressions<br />

<strong>XQuery</strong> uses path expressions to locate nodes in a document tree in much the same way as XPath<br />

1.0 defined it originally:<br />

let $b := input()/bib/book/author<br />

return $b/last<br />

input()/patient//type<br />

The first expression returns the last child element nodes of all author elements. The second expressions<br />

returns all type elements that are descendant nodes of the patient element. Here, // is<br />

the abbreviated syntax for /descendant-or-self::node()/.<br />

The structure of a path expression has only slightly changed with regard to XPath 1.0: A path expression<br />

consists of a sequence of steps which can be distinguished into general steps and location<br />

steps. A general step is an expression that evaluates to a node sequence, e.g. the input() function<br />

that delivers the document nodes of the current collection. It can only be the first step in a path<br />

expression. A location step consists of three parts:<br />

■ An axis, which specifies the relationship between the set of selected nodes and the context node,<br />

■ A node test, which specifies type and/or name of the set of selected nodes, and<br />

■ Zero or more predicates, which further restrict the set of selected nodes.<br />

Axes<br />

<strong>XQuery</strong> supports a number of axes. An axis originates in the context node and determines the<br />

initial node sequence that is further refined by node tests and predicates. In <strong>XQuery</strong> and XPath<br />

2.0, you can specify a path in either unabbreviated or abbreviated syntax. The following table lists<br />

each axis along with its direction (normal document order or reverse document order) and a short<br />

description. In the unabbreviated syntax, a double colon '::' follows the name of the axis.<br />

Axis<br />

Direction<br />

Meaning<br />

ancestor::<br />

attribute::<br />

child::<br />

descendant::<br />

descendant-or-self::<br />

parent::<br />

self::<br />

reverse<br />

all ancestor nodes (parent, grandparent,<br />

great-grandparent, etc.)<br />

implementation-defined attached attribute nodes<br />

normal<br />

normal<br />

normal<br />

reverse<br />

normal<br />

immediate child nodes (default axis)<br />

all descendant child nodes<br />

current node and all its descendant child nodes<br />

parent node (or attaching node for attribute and<br />

namespace nodes)<br />

the current node<br />

<strong>XQuery</strong> <strong>User</strong> <strong>Guide</strong><br />

27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!