Search code examples
xsdstandards

How are XSD elements combined in an xsd:extension pattern


I am working on transforming an XSD to a FrameMaker EDD, and I get stuck on the xsd:extension mechanism. As the W3C description of the XSD standard is really complex, I am hoping one of the XSD experts here can give me a hint about this.

Here are two of the definitions in my original XSD:

<xsd:complexType name="basehierarchy">
   <xsd:choice minOccurs="0" maxOccurs="unbounded">
     <xsd:element ref="num"/>
     <xsd:element ref="heading"/>
     <xsd:element ref="subheading"/>
   </xsd:choice>
</xsd:complexType>

<xsd:complexType name="docContainerType">
  <xsd:complexContent>
    <xsd:extension base="basehierarchy">
      <xsd:choice>
        <xsd:element ref="interstitial"/>
        <xsd:element ref="toc"/>
        <xsd:element ref="documentRef"/>
      </xsd:choice>
    </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>

I need to resolve extensions before I can create my EDD (and accompanying DTD), but I am not sure what the above patterns should result in. I can imagine various options - one would be to inject the choices of the extension into the choice of the base:

<xsd:complexType name="docContainerType">
  <xsd:choice minOccurs="0" maxOccurs="unbounded">
     <xsd:element ref="num"/>
     <xsd:element ref="heading"/>
     <xsd:element ref="subheading"/>
     <xsd:element ref="interstitial"/>
     <xsd:element ref="toc"/>
     <xsd:element ref="documentRef"/>       
  </xsd:choice>
</xsd:complexType>

As a side effect this would cause the @minOccurs and @maxOccurs to be applied to the elements of the extension pattern. Maybe that is OK but I cannot find explicit information about this. Another option for correct extension of the base pattern would be to add the choice from the extension after the choice of the base:

<xsd:complexType name="docContainerType">
  <xsd:sequence>
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:element ref="num"/>
      <xsd:element ref="heading"/>
      <xsd:element ref="subheading"/>
    </xsd:choice>
    <xsd:choice>
      <xsd:element ref="interstitial"/>
      <xsd:element ref="toc"/>
      <xsd:element ref="documentRef"/>       
    </xsd:choice>
  </xsd:sequence>
</xsd:complexType>

And if the second option is the correct one, should the extension come before or after the base elements?


Solution

  • Maybe the recommendation can give you a clue : XML Schema Part 0: Primer Second Edition, §4.2 Deriving Types by Extension, especially this part of the text:

    When a complex type is derived by extension, its effective content model is the content model of the base type plus the content model specified in the type derivation. Furthermore, the two content models are treated as two children of a sequential group.