<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:complexType name="uniqueString">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="uuid" type="uuid" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:element name="uniqueString" type="uniqueString" abstract="true"/>

<xs:simpleType name="uuid">
<xs:restriction base="xs:string">
<xsattern value="[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="uniqueUuid">
<xs:simpleContent>
<xs:extension base="uuid">
<xs:attribute name="uuid" type="uuid" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:element name="uniqueUuid" type="uniqueUuid" abstract="true"/>
<xs:element name="parent" type="uniqueString" abstract="true"/>
<xs:element name="child" type="uniqueString" abstract="true"/>
<xs:element name="hierarchy" abstract="true">
<xs:complexType>
<xs:sequence>
<xs:element ref="parent"/>
<xs:element ref="child" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="hierarchy">
<xs:sequence>
<xs:element ref="hierarchy"/>
</xs:sequence>
</xs:complexType>

<xs:element name="xHierarchy" substitutionGroup="hierarchy"/>
<xs:element name="containingX" substitutionGroup="parent"/>
<xs:element name="containedX" substitutionGroup="child"/>

<xs:element name="X">
<xs:complexType>
<xs:sequence>
<xs:element name="xHierarchy" type="hierarchy"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="yHierarchy" substitutionGroup="hierarchy"/>
<xs:element name="containingY" substitutionGroup="parent"/>
<xs:element name="containedY" substitutionGroup="child"/>

<xs:element name="Y">
<xs:complexType>
<xs:sequence>
<xs:element name="yHierarchy" type="hierarchy"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

given the above schema definition containingX can be used interchangably with containingY and containedX can be used interchangably with containedY. This is undesirable for the system I'm working on - is there a way to allow multiple hierarchy elements to be defined within a single .xsd that are derived from the same hierarchy complexType without having interchangable parent elements and interchangable child elements.