[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Pure Union Type

Subject: Re: Pure Union Type
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 4 May 2014 13:32:24 -0000
Re:  Pure Union Type
The cause of the problem here is that your numeric type does not include
xs:decimal as one of its member types; it only includes an anonymous type
derived from decimal by restriction. The number 3.3 is not an instance of this
anonymous type, and therefore it is not an instance of the union.

My first thought was to define the union as

                <xs:simpleType ref="xs:decimal"/>
                <xs:simpleType ref="xs:integer"/>
                <xs:simpleType ref="xs:float"/>
                <xs:simpleType ref="xs:double"/>

But for some reason XSD doesn't allow this; it has to be

            <xs:union memberTypes="xs:decimal xs:integer xs:float

This should now work, but it hits a Saxon bug:

java.lang.ClassCastException: com.saxonica.ee.schema.UserUnionType cannot be
cast to net.sf.saxon.type.AtomicType

The type checking code for arithmetic expressions isn't allowing for the
statically-inferred type of the argument to be a union type. I will fix this.

Unless you have any objections I will add your test case as import-schema-193
to the W3C XSLT 3.0 test suite.

Michael Kay

On 4 May 2014, at 05:31, Dimitre Novatchev dnovatchev@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> <xsl:stylesheet version="3.0"
> xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="my:my"
> exclude-result-prefixes="xs my">
> <xsl:output method="text"/>
> <xsl:import-schema>
>     <xs:schema xsl:validation="strict">
>         <xs:simpleType name="numeric">
>             <xs:union>
>                 <xs:simpleType>
>                     <xs:restriction base="xs:decimal"/>
>                 </xs:simpleType>
>                 <xs:simpleType>
>                     <xs:restriction base="xs:integer"/>
>                 </xs:simpleType>
>                 <xs:simpleType>
>                     <xs:restriction base="xs:float"/>
>                 </xs:simpleType>
>                 <xs:simpleType>
>                     <xs:restriction base="xs:double"/>
>                 </xs:simpleType>
>             </xs:union>
>         </xs:simpleType>
>     </xs:schema>
> </xsl:import-schema>
> <xsl:template match="/">
>     <xsl:sequence select="3 castable as numeric"/>
>     =============================================
>     <xsl:sequence select="my:add(3.3 cast as numeric, 5.787 cast as
> </xsl:template>
> <xsl:function name="my:add" as="numeric">
>     <xsl:param name="pLeft" as="numeric"/>
>     <xsl:param name="pRight" as="numeric"/>
>     <xsl:sequence select="($pLeft + $pRight) cast as numeric"/>
> </xsl:function>
> </xsl:stylesheet>

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.