XML/XSLT stylesheet/instance of
instance of element()
File: Data.xml
<?xml version="1.0"?>
<addressbook>
<address>
<street>1234 Main Street</street>
<city>Z</city>
<state>WI</state>
<zip>48392</zip>
</address>
</addressbook>
File: Transform.xslt
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:variable name="cities" as="item()*">
<xsl:sequence select="addressbook/address/city"/>
<xsl:sequence select="("A", "B", "C")"/>
<xsl:sequence select="("D", "E", "F")"/>
</xsl:variable>
<xsl:text>Our customers live in these cities:

</xsl:text>
<xsl:for-each select="$cities">
<xsl:choose>
<xsl:when test=". instance of element()">
<xsl:text> Node: </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>Atomic value: </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output:
Our customers live in these cities:
Node: Z
Atomic value: A
Atomic value: B
Atomic value: C
Atomic value: D
Atomic value: E
Atomic value: F
Some tests of the "instance of" operator
File: Data.xml
File: Transform.xslt
<?xml version="1.0"?>
<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>
Some tests of the "instance of" operator:</xsl:text>
<xsl:text>

 "1995-04-21" instance of xs:date: </xsl:text>
<xsl:value-of select=""1995-04-21" instance of xs:date"/>
<xsl:text>
 xs:date("1995-04-21") instance of xs:date: </xsl:text>
<xsl:value-of select="xs:date("1995-04-21") instance of xs:date"/>
<xsl:text>

 3 instance of xs:integer: </xsl:text>
<xsl:value-of select="3 instance of xs:integer"/>
<xsl:text>
 "3" instance of xs:integer: </xsl:text>
<xsl:value-of select=""3" instance of xs:integer"/>
<xsl:text>
 number("3") instance of xs:integer: </xsl:text>
<xsl:value-of select="number("3") instance of xs:integer"/>
<xsl:text>
 number("3") instance of xs:double: </xsl:text>
<xsl:value-of select="number("3") instance of xs:double"/>
<xsl:text>
 xs:integer("3") instance of xs:integer: </xsl:text>
<xsl:value-of select="xs:integer("3") instance of xs:integer"/>
<xsl:text>
 "3" cast as xs:integer instance of xs:integer: </xsl:text>
<xsl:value-of select=""3" cast as xs:integer instance of xs:integer"/>
<xsl:text>
 "e" instance of xs:integer: </xsl:text>
<xsl:value-of select=""e" instance of xs:integer"/>
</xsl:template>
</xsl:stylesheet>
Output:
Some tests of the "instance of" operator:
"1995-04-21" instance of xs:date: false
xs:date("1995-04-21") instance of xs:date: true
3 instance of xs:integer: true
"3" instance of xs:integer: false
number("3") instance of xs:integer: false
number("3") instance of xs:double: true
xs:integer("3") instance of xs:integer: true
"3" cast as xs:integer instance of xs:integer: true
"e" instance of xs:integer: false