June 2008
Intermediate to advanced
986 pages
27h 8m
English
As you would expect, a language that supports datatypes
and constructors also has operators to convert a value from one type
to another. XPath 2.0 provides four operators: instance of, castable as, cast
as, and treat as. We’ll
cover those here.
The instance of
operator lets us see whether a value is an instance of a
particular datatype. Here are some examples:
<?xml version="1.0"?>
<!-- instance-of.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>
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 ...Read now
Unlock full access