[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Types and Context
- From: Jonathan Borden <jborden@mediaone.net>
- To: Gavin Thomas Nicol <gtn@ebt.com>, xml-dev@lists.xml.org
- Date: Mon, 21 May 2001 20:14:26 -0400
Gavin Thomas Nicol wrote:
> > <p:book>
> > <title />
> > <genre/>
> > <author>
> > <title/>
> > <familyName/>
> > </author>
> > </p:book>
> >
> > Then how do you distinguish between the two title elements?
>
> Context.
Exactly. And if you stop to think about this, XML Schema "datatypes" are
hardly going to revolutionize XSLT/XPath 2.0.
Gasp! I hear cries of "no, no, no" echoing around the web...
In the Schema Algebra [1] statements [7-9] a "type" is the property of
belonging to a class. The predicate "typeOf(x, c)" tests a node "x" for
membership in the instance set of the class "c".
Think about XSLT templates, a template matches an XPath selector returning a
_set_ of nodes. This selector is seen directly as a _type_ which is defined
based on _context_. XML Schema may use rules other than context to classify
a node as a type, but this basic capability is one we already know and use
in XSLT/XPath.
Now let's think about one of the given examples:
"
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'
xmlns:this='urn:example.org.people'
targetNamespace='urn:example.org.people' >
<xs:complexType name='person' >
<xs:sequence>
<xs:element name='given' type='xs:string' />
<xs:element name='family' type='xs:string' />
</xs:sequence>
</xs:complexType>
<xs:element name='person' type='this:person' />
</xs:schema>
"
which would be used with a snippet such as:
<this:person xmlns:this='urn:example.org.people'>
<family>Gudgin</family>
<given>Martin</given>
</p:martin>
Now how might we refer to the _type_ of the <family> element. In XML Schema
terms the _type_ of the "this:person" element is "this:person" ... this is
also the XML 1.0 type as in XML 1.0 an element's type is its name, so far so
good.
What about the <family> element. In XML Schema, this element is declared in
the "this:person" complex type so you might use an XPath expression:
"this:person/family"
to refer to the "XML Schema datatype" in this new PSVI world (actually in
the XML Schema Formal Language it would be something like
"urn:example.org.people::type(person)::element(family) but assume the above
is shorthand)
... turns out that this is _exactly_ the same as the XPath used as an XSLT
selector. So I guess the real utility of XML Schema datatypes is the ability
to say: "use this QName as shorthand for this path selector".
Context.
-Jonathan
[1] http://www.rddl.org/SchemaAlgebra