Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Testing for Vendor Extensions
The previous example also demonstrates a second way of using the function, namely to test for vendor or third-party extensions. If you know that a particular extension instruction is present in some implementations and not others, you can use the
element-available()
test to see whether it is present, and again use either
split.xsl
used this technique to test whether the
An alternative to using the
element-available()
function is to use the
See Also
function-available()
on page 792
system-property()
on page 890
type-available()
on page 899
empty
The
empty()
function returns true if and only if the argument is an empty sequence.
For example, the expression
empty(//a)
returns true if the context document contains no
elements.
Signature
Argument | Type | Meaning |
sequence | item()* | The input sequence |
Result | xs:boolean | true if the input sequence is empty, otherwise false |
Effect
The function returns true if and only if the supplied sequence is empty.
Examples
Assume the source document:
Expression | Result |
empty(/para) | false |
empty(/para/a) | false |
empty(/para/a/@style) | false |
empty(/para/b) | true |
empty(/para/a[2]) | true |
Usage
Note that
empty()
is used only to test whether the number of items in a sequence is zero. As the examples above illustrate, it is
not
used to test whether a node is empty, in the sense of an element that has no children, or an attribute whose string value is a zero-length string.
To test whether an element
$E
has no element or text node children (or comments or processing instructions), you can write
if (empty($E/node()) ...
.
To test whether the string value of a node
$N
is the zero-length string, you can write
if (string($N) eq “”) ...
.
Remember also that a test on any value in the condition of an
if
expression is done by taking the effective boolean value of the expression, as defined under the
boolean()
function on page 721. For example, if the expression is a path expression then the condition is true if the path expression selects one or more nodes; if it is a string, then the condition is true if the string is not zero-length. So, for example:
if (not(*)) then X else Y
has the same effect as:
if (empty(*)) then X else Y
and similarly, if
@a
refers to a list-valued attribute, then:
if (normalize-space(@a)) then X else Y
is equivalent to:
if (empty(data(@a))) then Y else X
See Also
boolean()
on page 721
exists()
on page 778
not()
on page 850
encode-for-uri
The
encode-for-uri()
function is used to apply percent-encoding to special characters in a string when the string is intended to be used as part of a URI.
For example,
concat(‘http://www.wikipedia.org/’, encode-for-uri(‘Gerhard Schröder’))
returns
http://www.wikipedia.org/Gerhard%20Schr%C3%B6der
.