This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 4767 - New feature: xs:override
Summary: New feature: xs:override
Status: CLOSED FIXED
Alias: None
Product: XML Schema
Classification: Unclassified
Component: Structures: XSD Part 1 (show other bugs)
Version: 1.1 only
Hardware: PC Windows XP
: P2 enhancement
Target Milestone: ---
Assignee: C. M. Sperberg-McQueen
QA Contact: XML Schema comments list
URL:
Whiteboard:
Keywords: resolved
Depends on:
Blocks:
 
Reported: 2007-06-26 21:50 UTC by Michael Kay
Modified: 2008-06-07 07:49 UTC (History)
2 users (show)

See Also:


Attachments

Description Michael Kay 2007-06-26 21:50:38 UTC
xs:override
========

Encouraged by a requirement from Eliot Kimber, and spurred on by Henry Thompson, I offer the following proposal for a new feature in XML Schema 1.1

The requirement this addresses is one that xsl:redefine fails to meet - the requirement to define a variant of a schema in which there is no constraint that instances of the new schema should be valid instances of the old schema. This requirement is common in customizing "industry-standard" schemas, in defining successive versions of a schema, or in defining a family of messages that include some components in common but differ in other significant details. Examples of the variations that are possible include: changing an enumerated code list by adding or removing values; making a required element optional; adding a new element to the middle of a sequence; changing an attribute from xs:double to xs:decimal, changing the "body" of an envelope structure to be a specific required element. All of these changes can of course be achieved by "copy and paste" modification, but this makes change management much more difficult when the base schema changes.

The feature has strong similarities to XSLT's import feature, which allows arbitrary redefinition of top-level templates, variables, functions, and other declarations.

Proposed syntax
============

A new element xs:override is introduced, valid in the same places as xs:redefine. Its content model is

<xs:override schemaLocation="uri">
  <xs:replace/>*
</xs:override>

The syntax of xs:replace is:

<xs:replace component="QName" ref="QName">
  ... content ...
</xs:replace>

where component is one of the top-level component names xs:element, xs:attribute, xs:simpleType, xs:complexType, xs:group, xs:attributeGroup etc, and the ref attribute refers to a named global component of that kind by its expanded name. The content model for xs:replace is the same as the content model of the relevant kind of component, for example if component="xs:simpleType" then the content model is the same as that for xs:simpleType, including all attributes other than the name attribute. This can be defined in the S4S using conditional type assignment.

The semantics of xs:override are defined as follows. This specification is written as a transformation to be applied to schema documents. It is done strictly at the level of schema documents, and is applied before any construction of schema components. The rules are as follows:

1. Let the transformed document set be the document retrieved using the URI contained in the schemaLocation, together with all schema documents retrieved by transitively following the URIs contained in xs:include, xs:import, and xs:redefine elements in documents within the transformed document set.

2. Any xs:override element is a transformed document is processed by applying this rule recursively. It is an error if there are cycles, that is, if this process leads back to the original xs:override element.

3. Every document in the transformed document set is transformed using the XSLT 2.0 transformation below.

4. Every URI contained in an xs:include, xs:import, and xs:redefine element in a transformed document is replaced by a sythetic URI that refers to the result of transforming its original target.

5. The xs:override element is replaced by an xs:include element referring to the result of transforming the document referenced in its schemaLocation attribute.

5. The transformation that is applied is as follows, where $ov is the original xs:override element and $schema is the xs:schema element of the document being transformed. The transformation is assumed to apply to validated input documents.

<xs:param name="ov" as="schema-element(xs:override)"/>
<xs:param name="schema" as="schema-element(xs:schema)"/>

<xsl:template match="schema-element(xs:schema)">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:copy-of select="xs:include | xs:import | xs:redefine"/>
    <xsl:apply-templates/>
  <xsl:copy>
</xsl:template>

<xsl:template match="xs:schema/*">
   <xsl:variable name="component" select="."/>
   <xsl:variable name="replacement" select="$ov/xs:replace[@ref=f:componentName($component) and @component=node-name($component)"/>
   <xsl:choose>
     <xsl:when test="$replacement">
       <xsl:copy>
         <xsl:attribute name="name" select="local-name()"/>
         <xsl:copy-of select="$replacement"/>
      </xsl:copy>
    </xsl:when>
    <xsl:otherwise>
      <xsl:copy-of select="."/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:function name="f:componentName" as="xs:QName">
  <xsl:param name="component" as="element()"/>
  <xsl:sequence select="QName($component/../@targetNamespace, $component/@name)"/>
</xsl:function>

NOTES

A. No particular attempt has been made to handle the interaction between replace and redefine elegantly; it is well-defined but may not meet user needs.

B. Components cannot be renamed by this mechanism. Components are referred to by their "original" name, not by any name they might subsequently acquire as a result of chameleon includes.

C. The effect of xs:override is confined to documents reachable via the given URI.
Comment 1 C. M. Sperberg-McQueen 2007-08-03 18:29:32 UTC
On its telcon today, the Working Group discussed this and other
recently opened issues in the issues database and concluded (not
without some pangs of regret) that for scheduling reasons it is not
feasible for us to resolve this issue, or any of the others in the
group, before we go to Last Call.

On whether the issue / proposal discussed here is worth pursuing or
not, the WG has taken no formal decision. Accordingly I am closing
this issue with a disposition of LATER, not WONTFIX.  That means the
Working Group believes that the issue may be resolved in some future
version of the spec, and encourages whatever Working Groups are
responsible for future versions of the spec to consider this issue
at an appropriate time.  (If this bug relates both to 1.0 and 1.1,
this resolution applies only to 1.1 and leaves undetermined how to
handle it vis-a-vis 1.0.)
Comment 2 Eric Sirois 2008-05-15 02:00:59 UTC
I'm hoping the WG can take some time during their upcoming meetings to revisit this particular proposal. 

This particular proposal would be very useful as another tool for DITA or Docbook developers to evolve their schemas using XML Schemas.  For DITA, developers using DTD and XSLT currently have the tools necessary to override base definitions to support new topic type.   In fact, XSLT specializations rely heavily on the fact that you can override the base template in order to support your own custom processing.

On the XML Schema side of the house, the only mechanism that is currently available is the xs:redefine.  Which I must admit is pretty restrictive, but so far we haven't had the need for much else.  Eliot Kimber, has run into some issues where xs:redefine is no longer sufficient [1].

I'm currently in the process of updating the XML Schemas for DITA 1.2.  I am running into some issues with xs:redefine trying to implement DITA feature 12008 Constraints - restriction without specialization [2] and feature 12011 - more general task type [3].  With the help of one of our WG representatives, I have been able to implement {3) with some crafty use of model groups.  Which is fine for this particular case, but for (2) we are trying to use xs:redefine for a something in which it was not originally designed to do.

I would like to thank the WG for taking the time to look at this request.  

Kind regards,
Eric 


[1] - http://lists.w3.org/Archives/Public/xmlschema-dev/2007Jun/0035.html
[2] - http://www.oasis-open.org/committees/download.php/25090/IssueConstraints12008.html 
[3] - http://www.oasis-open.org/committees/download.php/26791/IssueNumber12011v1.2rev3.html 

Comment 3 C. M. Sperberg-McQueen 2008-05-23 15:54:27 UTC
Accepted as needsDrafting on telcon of 23 May 2008.  Phase-1 agreement:
roughly as described (but lose xs:replace?).
Comment 4 C. M. Sperberg-McQueen 2008-05-29 06:41:51 UTC
A wording proposal intended to resolve this issue is at
http://www.w3.org/XML/Group/2004/06/xmlschema-1/structures.b4767.html
(member-only link).

Comment 5 C. M. Sperberg-McQueen 2008-06-07 01:26:03 UTC
The proposal mentioned in comment #4 was adopted on today's XML Schema
WG call; I'm marking this issue as resolved.

Michael, as the originator of the issue, would you please indicate
whether you are satisfied with the proposal adopted by closing the issue
or reopening it as appropriate?  If we don't hear from you within the
next week, we will assume you are happy.

Eliot Kimber and Eric Sirois are invited, as interested parties,
to indicate whether they are satisfied or not satisfied by adding
comments to the bug record, but the issue should be closed or 
reopened by Michael Kay as the originator of record.   Thanks to all
of you for your interest in this area.