W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2011

Re: What is lost if xsd:choice is jettisoned?

From: C. M. Sperberg-McQueen <cmsmcq@blackmesatech.com>
Date: Wed, 9 Mar 2011 18:34:20 -0700
Cc: "C. M. Sperberg-McQueen" <cmsmcq@blackmesatech.com>, "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-Id: <F9C1543B-3449-4DB1-AC65-C4F7E04877A5@blackmesatech.com>
To: "Costello, Roger L." <costello@mitre.org>

On Mar 8, 2011, at 7:36 AM, Costello, Roger L. wrote:
> 
> 
> Suppose the xsd:choice element were jettisoned from the XML Schema specification. Would there be any loss of functionality? Put another way, can you provide a real-world, compelling example of a schema that uses xsd:choice which cannot be expressed using abstract element plus substitution groups?

Looking at the choices in one well known existing vocabulary,
I find these examples which I don't believe can be replaced by
substitution groups.  You may argue that they aren't really
compelling, because the languages could have been designed
a different way.  The only answer to that will be to say "yes, they
could, but in fact the language was designed *this* way".

- The XHTML 'head' element has one 'title', at most one
'base', and zero or more of various other possible children,
in any order.  The content model is expressed in a choice
whose branches are sequences; the same language cannot
be defined using substitution groups.  

- The XHTML 'map' element takes as children either a
sequence of 'area' elements or a sequence of block-level
elements.  This choice cannot be expressed using substitution
groups, because it is not allowed to interleave area elements 
and the block-level elements (p, div, etc.).

- The XHTML 'table' element begins with a sequence of 
col or colgroup elements (that choice you could handle with
a substitution group), followed optionally by thead and tfoot,
with either a series of 'tr' elements or a series of 'tbody'
elements bringing up the rear.  The choice between
'tr+' and 'tbody+' cannot be handled by a substitution group,
since the two must not be interleaved.

In XSD 1.1, an additional example is added to the list by the 
constraint that an element may have at most one 
substitution-group head:

- in XHTML, a number of elements can contain 'block-level'
children, in various combinations.  It would be easy enough
to define the choice among p, div, blockquote, form, etc.
in terms of a substitution group.  Form is sometimes included
(e.g. in body and blockquote) and sometimes excluded (e.g.
in form itself).  That we can model (one substitution group
for non-form-block elements, another for those and also form).

But in an 'object' element, we need p or div or blockquote or 
form or param.  While in a 'fieldset', we need p or div or
blockquote or form or legend.  

Generalizing:  for a given set of content models including 
choices between elements (not between sequences), it may 
be possible to replace some choices with substitution groups, 
but there is no guarantee that a single substitution-group 
hierarchy can be constructed that provides just the set of 
choices one wants.  

Don't get me wrong:  substitution groups are a good
thing in many ways, and as George Bina has explained they
make extending a vocabulary much easier. This is not
surprising, since several members of the group that defined
them had long experience with the tasks of specifying and
modifying markup vocabularies, and adding new elements
that 'work just like element X, except they are called Y'
is a frequentlyl required form of modification.

But choice is more expressive, in the formal sense, than 
substitution groups.

I hope this helps.

-- 
****************************************************************
* C. M. Sperberg-McQueen, Black Mesa Technologies LLC
* http://www.blackmesatech.com 
* http://cmsmcq.com/mib                 
* http://balisage.net
****************************************************************
Received on Thursday, 10 March 2011 01:34:51 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 10 March 2011 01:34:51 GMT