June 2008
Intermediate to advanced
986 pages
27h 8m
English
[2.0] empty()
Given a sequence, returns true if the argument is the empty
sequence, false
otherwise.
xs:booleanempty(item()*)
A sequence of items.
true if the argument is
the empty sequence; false
otherwise. Although empty($sequence) and count($sequence) = 0 are logically
equivalent, empty() is
likely to be more efficient.
XQuery 1.0 and XPath 2.0 Functions and Operators section 15.1, “General Functions and Operators on Sequences.”
This stylesheet illustrates the empty() function:
<?xml version="1.0"?> <!-- empty.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:variable name="emptySequence" as="item()*"> <xsl:sequence select="()"/> </xsl:variable> <xsl:variable name="singleton" as="item()*"> <xsl:sequence select="(3)"/> </xsl:variable> <xsl:variable name="longSequence" as="item()*"> <xsl:sequence select="(3, 4, 5, current-date(), current-time(), 8, 'blue', 'red', xs:float(3.14), 42, xs:date('1995-04-21'))"/> </xsl:variable> <xsl:text>
Here are some tests of the empty() </xsl:text> <xsl:text>function:
</xsl:text> <xsl:text>
 Our first sequence is:

 </xsl:text> <xsl:value-of select="$emptySequence" separator="
 "/> <xsl:text>

</xsl:text> <xsl:value-of select="if (empty($emptySequence)) then 'This is the empty sequence!' else 'This is not the empty sequence!'"/> <xsl:text>

</xsl:text> ...
Read now
Unlock full access