functx:if-absent

The first argument if it is not empty, otherwise the second argument

Description

The functx:if-absent function is useful for providing default values in case a data item is absent. It checks if the $arg argument is the empty sequence, and if it is, it returns the value $value. Otherwise, it returns the typed value of $arg itself. Note that an element or attribute is not considered “absent” if it contains a zero-length string; only if it does not exist at all.

Note: This function is similar to the eg:if-absent function provided in the XQuery 1.0 and XPath 2.0 Functions and Operators document. However, this function differs in that it supports attribute nodes and atomic values.

Parameters

Description

arg:item()

the item(s) that may be absent

value:item()

the item(s) to use if the item is absent

Examples

XPath

Results

data(functx:if-absent($in-xml//price[1]/@discount, 0))

10.00

data(functx:if-absent($in-xml//price[3]/@discount, 0))

0

data(functx:if-absent($in-xml//price[4]/@discount, 0))

zero-length untyped value

See Also