[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: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 4 May 2014 15:49:25 -0000
Re:  Pure Union Type
Thank you for the precise explanation, Michael.

I would be glad if you add this test-case to the W3C XSLT 3.0 test suite.


On Sun, May 4, 2014 at 6:32 AM, Michael Kay mike@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> 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:union>
>                 <xs:simpleType ref="xs:decimal"/>
>                 <xs:simpleType ref="xs:integer"/>
>                 <xs:simpleType ref="xs:float"/>
>                 <xs:simpleType ref="xs:double"/>
>             </xs:union>
> 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
> Saxonica
> 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>

Dimitre Novatchev
Truly great madness cannot be achieved without significant intelligence.
To invent, you need a good imagination and a pile of junk
Never fight an inanimate object
To avoid situations in which you might make mistakes may be the
biggest mistake of all
Quality means doing it right when no one is looking.
You've achieved success in your field when you don't know whether what
you're doing is work or play
To achieve the impossible dream, try going to sleep.
Facts do not cease to exist because they are ignored.
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
I finally figured out the only reason to be alive is to enjoy it.

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.