XML technologies / XSLT / Introduction to XSLT 2.0 / Getting started with XSLT and XPath / A comparison: expression vs. instruction / Nothing inside: The empty sequence

(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 1.)

What happens when an expression produces no result, for example because no matching node exists at the position described by a path? It returns an empty sequence, indicating that no information is available, roughly comparable to the null value in a database.

An empty sequence is represented by empty parentheses: ()

Here the second expression produces an empty sequence:

(ausdruck_a, ausdruck_b, ausdruck_c) gives (wert_a, (), wert_c)

The empty sequence is no special case when nesting sequences, but its length is zero. It therefore disappears when included in another sequence:

(wert_a, (), wert_c) gives (wert_a, wert_c)

Much ado about nothing? Not quite. Empty sequences have a purpose: they are chameleon-like, completely neutral values accepted as input by all functions and instructions. An empty sequence causes no error because no processing occurs. An empty string, however, might cause a type error even though it also contains nothing!

An instruction receiving an empty sequence simply does nothing. Functions usually return another empty sequence.

   

back to top