[XQ] Meaning of substitution groups in element(ElementName,TypeName)

The following issue was identified during formal definition of
SequenceType matching.  Resolution of this issue is necessary to
complete closure of Issue 559 (New Sequence Type needs to be fully
implemented in Formal Semantics).

Current status: 

1. The XQuery type system is based on XML Schema.

2. Section 2.4.4.3 Matching an ElementTest and an Element Node, point 2
   states that:

    a. element(ElementName, TypeName) matches a given element node if
       the name of the element node matches ElementName or matches the
       name of an element in a substitution group headed by an element
       with the name ElementName [if such a head element exists]

   b. type-matches(TypeName, AT) is true, where AT is the type of the
      given element node.

3. To express a sequence type in the XQuery type system, it should
   correspond to some valid XML Schema structure.  In XML Schema
   terminology, the sequence type syntax element(ElementName,TypeName)
   represents a new local element ElementName in the substitution
   group of a global element with the *same* ElementName, and with
   type TypeName.

   In XML Schema, you might express this sequence type as:

     <xs:element name="ElementName" substitutionGroup="ElementName"
type="TypeName"/>

Problem 1: 

  XML Schema requires that all members of a substitution group be
  globally declared, therefore the above XML Schema type is invalid
  and thus there is no valid XQuery type expression that represents
  the sequence type element(ElementName, TypeName).

Problem 2: 
 
  Even if we permitted such a type in the XQuery type system, another
  problem arises.

  XML Schema (and hence the XQuery type system) requires the type name
  of a substitution group member to be derived from the type name of
  the head of the substitution group.  This constraint is not enforced
  by sequence-type matching, and therefore it is out of the scope of
  XML Schema and our type system.

  Because the current semantics of element(ElementName, TypeName)
  cannot be expressed in the XQuery type system, any example based on
  it is potentially unsound.  To illustrate, consider the following
  XML Schema structures:

  An element person of type Person: 

     define element person of type Person
     define type Person {
       element manager of type xs:string,
     }

   A type Company: 

     define type Company { 
       element ticker of type xs:string
     }
  
  and consider the sequence type:

    element(person, Company)

  There is no corresponding XML Schema or XQuery type for this
  sequence type, i.e., the following is invalid, because type Company
  is _not_ derived from type Person:

    <xs:element name="person" substitutionGroup="person"
type="Company"/>

  Consequence: we do not know how to map this sequence type into the
  XQuery type system and therefore cannot provide a static semantics
  for it.

Possible solution 1: enforce the XML Schema's type-derivation
constraint. 

Possible solution 2: treat element(person,Company) as the following
local XML Schema element:
  
  <xs:element name="person" type="Company"/>

which is simple, but excludes substitution groups from the semantics. 


-- 
Mary Fernandez <mff@research.att.com>
AT&T Labs - Research

Received on Wednesday, 4 February 2004 10:57:25 UTC