xsl-list
[Top] [All Lists]

Re: [xsl] Pure Union Type

2014-05-04 10:49:35
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.

Cheers,
Dimitre

On Sun, May 4, 2014 at 6:32 AM, Michael Kay mike(_at_)saxonica(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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 xs:double"/>

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(_at_)gmail(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

<xsl:stylesheet version="3.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
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 
numeric)"/>
</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>




-- 
Cheers,
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.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>