<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>7860</bug_id>
          
          <creation_ts>2009-10-09 15:17:42 +0000</creation_ts>
          <short_desc>[XPath 2.1] Union type as declared function argument</short_desc>
          <delta_ts>2013-06-19 07:52:09 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XPath 3.0</component>
          <version>Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Kay">mike</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>jim.melton</cc>
    
    <cc>zongaro</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>28169</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2009-10-09 15:17:42 +0000</bug_when>
    <thetext>This requirement arises because there are various functions in XSLT, such as key() and format-number(), which take a lexical QName as an argument, and we have been considering how to allow them to take a value of type xs:QName instead. We want to do this for a number of reasons, one of which is the introduction of an xsl:evaluate instruction to allow dynamic construction of XPath expressions: it is desirable that such expressions should have no dependencies on the in-scope namespace prefixes. We discussed this in the XSL WG on 2009-10-08 and I am raising the requirement here as a result of an action from that meeting.

We could change these functions to declare the argument as xs:anyAtomicType, but that reduces type safety unnecessarily. The prefered solution is to declare the type as a union of xs:string and xs:QName.

This is of course a general requirement for user applications, it is not specific to these functions. It arises for two reasons: (a) users want to define a function to accept arguments of more than one type (as here), or (b) users have types defined in their schema as union types, and want to manipulate values of these types using function calls. For example, I have seen schemas that contain a type defined as a union of xs:date and xs:gYearMonth, and it would be convenient to write functions that accept instances of that union type.

The general idea is that it should be possible in a function signature to declare the required type of an argument as being a union type, and the supplied value then matches this type if it is an instance of one of the member types of the union.

To avoid complications, it is proposed to restrict this to &quot;basic unions&quot;, defined as a simple type of variety union whose base type is xs:anySimpleType and whose member types are all either atomic or (in XSD 1.1 only) basic union types. That is, it excludes unions derived by restriction from other unions (for which the substitutability rules are complex, and buggy in XSD 1.0).

I would propose that we only allow use a named union type defined in the schema. It would be possible to define SequenceType syntax to define an inline union type, but this is probably overkill. XSLT already allows the definition of types locally to a stylesheet by means of an inline schema document.

Sequence type matching works if the supplied value after atomization is an instance of one of the member types of the union (transitive membership in the case of XSD 1.1). If an untypedAtomic value is supplied, then it is converted to the union type by a process analogous to schema validation (try each of the member types in turn.) 

Static typing works in the obvious way, and is not really different from the current rules for types element(*, U) and attribute(*, U) where U is a union type, which we already allow.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>29610</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2009-11-17 13:59:16 +0000</bug_when>
    <thetext>A proposal to address this problem (along with bug 7749) is at

http://lists.w3.org/Archives/Member/w3c-xsl-query/2009Oct/0133.html

(member-only)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>32300</commentid>
    <comment_count>2</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2010-02-17 22:30:44 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; A proposal to address this problem (along with bug 7749) is at
&gt; 
&gt; http://lists.w3.org/Archives/Member/w3c-xsl-query/2009Oct/0133.html
&gt; 
&gt; (member-only)
&gt; 

The WG has adopted this proposal (http://lists.w3.org/Archives/Member/w3c-xsl-query/2010Jan/0081.html):

I think the changes to our specification needed to plug this usability gap
are very modest. Define the construct AType to be an atomic type or a union
type that does not impose any restrictions beyond those imposed by its
member types (for a way of saying this more formally, see Type Derivation OK
(Simple) in XSD 1.1). Then we allow an AType to be used as an ItemType in
the SequenceType production (in place of the current AtomicType), and in
2.5.4.2 we say that when the AType is a union type, then it matches an
atomic value if and only if one of its member types matches that atomic
value.

I will add this to the internal working draft.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>42395</commentid>
    <comment_count>3</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2010-11-10 21:43:22 +0000</bug_when>
    <thetext>I&apos;m tempted to use the existing AtomicType production, modifying the semantics to match the proposed semantics for AType.

That&apos;s editorial - it doesn&apos;t affect the language - but I&apos;m stating this here so anyone who wants to provide feedback has a head&apos;s up.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>42433</commentid>
    <comment_count>4</comment_count>
    <who name="Henry Zongaro">zongaro</who>
    <bug_when>2010-11-11 14:11:15 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; I&apos;m tempted to use the existing AtomicType production, modifying the semantics
&gt; to match the proposed semantics for AType.

So, you&apos;re musing about something like this.  Leaving this production as it is:

[172]    AtomicType ::=  EQName

and changing the following sentence in section 2.5.4.2 to replace &quot;defined as an atomic type&quot; to &quot; defined as an atomic type or a union type&quot;?

&quot;An ItemType consisting simply of an EQName is interpreted as an AtomicType. An AtomicType AtomicType matches an atomic value whose actual type is AT if derives-from( AT, AtomicType ) is true. If the expanded QName of an AtomicType is not defined as an atomic type in the in-scope schema types, a static error is raised [err:XPST0051].&quot;


If I&apos;ve understood you correctly, I think that as a reader I would find it quite confusing to have to read &quot;AtomicType&quot; as meaning &quot;atomic type or union type,&quot; but &quot;atomic type&quot; as meaning &quot;atomic type.&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>42438</commentid>
    <comment_count>5</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2010-11-11 16:02:37 +0000</bug_when>
    <thetext>(In reply to comment #4)

&gt; If I&apos;ve understood you correctly, I think that as a reader I would find it
&gt; quite confusing to have to read &quot;AtomicType&quot; as meaning &quot;atomic type or union
&gt; type,&quot; but &quot;atomic type&quot; as meaning &quot;atomic type.&quot;

True. 

Perhaps AtomicOrUnionType would be better ... a bit long.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>42455</commentid>
    <comment_count>6</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2010-11-11 21:47:19 +0000</bug_when>
    <thetext>The proposal says this:

&gt; We could also extend casting to allow casting to a union type, 
&gt; but I don&apos;t think that&apos;s essential.

The minutes do not state whether we decided to allow this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>42552</commentid>
    <comment_count>7</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2010-11-15 23:04:11 +0000</bug_when>
    <thetext>*** Bug 10568 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>42910</commentid>
    <comment_count>8</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2010-11-30 16:57:39 +0000</bug_when>
    <thetext>The Working Group decided that we will support casts and constructor functions.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>