Set unions of node sets

Up to now we have determined in each expression only one single node test. But often there are applications where several node tests shall be united.

Example: All titles of the style pop and all labels shall be selected.

//TITLE[@style="Pop"] | //LABEL

XPath functions

Functions are used for extended operations and queries on node sets and for string analyses of text nodes and attribute values. XPath functions can be used in XPath expressions as well as in predicates, as shown by the following example:

Example: count(//SONG)

Functions may get an argument and they always return a value! In the first example the "count" function gets a node set as an argument and submits a node set as return value.

Examples for functions on node volumes are:

local-name(..) Returns the name of the parent element as a string.
//SONG[position()=5]  (short notation [5]) Output of all songs having the fifth position within other songs.
//SONG[position()=last()] Output of all songs having the last position within other songs.

Examples for string functions are:

//ALBUM[string-length(TITLE) > 20 ] Selection of all albums whose title texts have more than 20 characters.
//ALBUM[starts-with(INTERPRETER,'M')] Selection of all albums whose interpreters begin with the letter "M".

One example for a very often used and powerful function is the general "not()" function. This function negates a Boolean expression. The following example demonstrates the use of this function:

//ALBUM[not(SONG)] Selection of all albums which do not contain a song as a direct child.
<< back  

Copyright © dpunkt.verlag GmbH 2007
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "Professionelle XML-Verarbeitung mit Word" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, fon 06221-14830, fax 06221-148399, hallo(at)