Re: [xml-dev] XML Schema Design: no local elements with anonymous types

From
Jonathan Robie <>
To
"Costello, Roger L." <>
Date
2008-03-26T15:24:36Z
ID
<>
Thread
Re: [xml-dev] XML Schema Design: no local elements with anonymous types
Costello, Roger L. wrote:
> Here's why: XSLT/XPath 2.0 is "schema-aware."  That is, in a 2.0
> stylesheet you can take advantages of the type information in the
> schema.  However, that's true only if the elements are declared
> globally and/or with a named type.  So, to facilitate the use of type
> information by a 2.0 stylesheet, design your XML Schemas such that
> elements are declared globally and/or with a named type.
>   
This is not true as written.

XPath 2.0 is schema aware for anonymous types too, and leverages such 
types appropriately for operators, including comparisons. What you can 
not do is refer to such a type by name. Of course, you can refer to a 
base type. So you could use tests like:

element(NumPages, xs:integer)
element(NumPages, xs:positiveInteger)

But of course you can't match the anonymous type directly, because it 
has no name, you can only match against its base types or against the 
element name. But in many cases this is sufficient - would you really 
use the full derived type to make decisions on how to format this 
particular integer? You'd be more likely to use the element name, its 
position in the document, and perhaps the fact that it is a positive 
integer.

To me, it's good to use named types if:

1. The type will be used in more than one place.
2. The type has a meaningful identity that can affect the way it is 
processed.

Jonathan