June 2008
Intermediate to advanced
986 pages
27h 8m
English
[2.0] exists()
Returns true if
the input sequence is nonempty; false otherwise.
xs:booleanexists(item()*)
A sequence of items.
If the sequence of items is not empty, exists() returns true; otherwise, it returns false.
XQuery 1.0 and XPath 2.0 Functions and Operators section 15.1, “General Functions and Operators on Sequences.”
This simple stylesheet uses the exists() function against three
sequences. The first sequence is the empty sequence, the second is
a singleton, and the third is a longer sequence:
<?xml version="1.0"?> <!-- exists.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:text>
Here is a test of the exists() </xsl:text> <xsl:text>function:

 </xsl:text> <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:choose> <xsl:when test="exists($emptySequence)"> <xsl:text>The empty sequence does exist!</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>The empty sequence doesn't exist!</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:text>
 </xsl:text> <xsl:value-of select="if ...
Read now
Unlock full access