I have an XML Schema that contains the following type element:
<xs:simpleType name="value">
<xs:union memberTypes="xs:boolean xs:int xs:double xs:string"/>
</xs:simpleType>
A sample XML fragment would be:
<value>42</value>
In an XSLT transform, how do I determine which type the value has, i.e., is it a boolean, an integer, a double, or a string?
If there isn’t a schema associated with the XML document, the answer is that the type is always
xs:stringand the question isn’t too meaningful.However, the correct question is: With which of those types is this compatible (castable as) ?
This transformation shows how this can be found out. It also illustrates the elegance and power of
<xsl:next-match>:when applied on the provided XML document:
the wanted, correct result is produced: