Question: I have the following XML:

```
<Content name="contentName1">
    <!-- Some sub elements here -->
</Content>

<Sequence Name="sequenceName1">
    <Content name="contentName1" />
    <!-- Some sub elements here -->
</Sequence>

```

with the following XSD

```
<xs:element maxOccurs="unbounded" name="Content">
    <xs:complexType>
        <xs:attribute name="Name" type="xs:string" use="required" />
        <!-- other definitions here -->
     </xs:complexType>
</xs:element>

<xs:element maxOccurs="unbounded" name="Sequence">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="unbounded" name="Content">
                <xs:complexType>
                    <xs:attribute name="ContentName" type="xs:string" use="required" />
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="Name" type="xs:string" use="required" />
    </xs:complexType>
</xs:element>

```

In the XSD, how can I tell to the ContentName attribute of the Content elements of Sequence to only accepts value declared in the ContentName of Content elements? 

e.g: with the XML provided above, only contentName1 will be accepted in the Content of sequence.

Answer: 
Identity constraint definitions are used for enforcing the unique, primary key and foreign key relations. you need to first define a key element for the content element and then use a keyref in the inner content element for the schema validator to enforce the condition you mentioned.  
 Refer the below link it has some examples as well, also the tutorial in xfront for xsd covers some examples -

<http://www.w3.org/TR/xmlschema11-1/#Identity-constraint_Definition_details>  

<http://www.xfront.com/files/xml-schema.html>
i am not good in xsd too, but maybe you will change `<xs:attribute name="Name" type="xs:string" use="required" />` to `<xs:attribute name="Name" type="contentNames" use="required" />` 

and create 

```
 <xs:simpleType name="contentNames" >
    <xs:restriction base="xs:token">
      <xs:enumeration value="contentName1"/>
      <xs:enumeration value="contentName2"/>

      <xs:pattern value="contentName[1234567890][1234567890]"/> 
      <xs:enumeration value="contentName1"/>
    </xs:restriction>
  </xs:simpleType>

```

for 

```
<xs:pattern value="contentName[1234567890][1234567890]"/>

```

contentName1-99 but dont know if you can use `<xs:enumeration/>` too, you can try