XSLT and XPath function reference in alphabetical order
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)
Functions for sequences
A sequence; the input sequence in case it consists of zero or one item.
An input sequence consisting of, in principle, any number of items which, however, is rejected by the function in case it does not consist of zero (the empty sequence) or of one item. In all the other cases (more than one item), an error is reported. This corresponds to the testing of the input sequence for cardinality »?«, which means »zero or one« item.
Purpose of use:
The function enforces the output of the empty sequence or of a sequence consisting of one item by rejecting all those sequences which do not cope with this constraint.
The function can be used wherever sequences of exactly one item (singleton sequences) or the empty sequence are absolutely required and the processing has to be terminated if this is not the case. The empty sequence and sequences consisting of one item are passed on unchanged by the function.
Example 1 – call with a too great a number of items in the input sequence:
fn:zero-or-one( (1, 2, 3)
results in the error message: »fn:zero-or-one called with a sequence containing more than one item« (err:FORG0003).
Example 2 – call with exactly one item in the input sequence:
fn:zero-or-one( (1) )
returns the sequence passed on (1).
Example 3 – call with the empty sequence:
fn: zero-or-one( () )
returns the empty sequence ().
The function is not available.
fn:zero-or-one($arg as item()*) as item()?
|<< back||next >>|
Copyright © Galileo Press, Bonn 2008
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSLT 2.0 & XPath 2.0" 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.
Galileo Press, Rheinwerkallee 4, 53227 Bonn, Germany