[Home] [By Thread] [By Date] [Recent Entries]

  • From: "Costello, Roger L." <costello@m...>
  • To: <xml-dev@l...>
  • Date: Wed, 26 Mar 2008 07:17:12 -0400

Hi Folks,

Along the road to learning version 2.0 of XSLT/XPath, I learned this
about designing XML Schemas.
 
BAD: locally declared elements with anonymous types.
 
Example:  NumPages is BAD because it is locally declared and has an
anonymous type.
 
<element name="Book">
    <complexType>
        <sequence>
          <element name="NumPages">
               <simpleType>
                     <restriction base="positiveInteger">
                         <maxInclusive value="1200"/>
                     </restriction>
               </simpleType>
          </element>
        </sequence>
    </complexType>
</element>
 
GOOD: globally declared elements and/or elements with a named type.
 
Example: Now NumPages is GOOD because it is globally declared and has a
named type.
 
<element name="Book">
    <complexType> 
        <sequence>
          <element ref="bk:NumPages"/> 
        </sequence>
    </complexType>
</element>
 
<element name="NumPages" type="NumPagesType" />
 
<simpleType name="NumPagesType">
    <restriction base="positiveInteger">
        <maxInclusive value="1200"/>
    </restriction>
</simpleType>
 
 
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.

Summary: make the element global, or with a named type, or both.
 
/Roger


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member