title: Unique for attributes in two elements
body: <p>I'm building XML and XML schema for a chess game. There shouldn't be duplicates on position.</p>
  
  <p>To solve that, I used unique, so this works for each element but not both together. For example, if I have position "66" for player black's pawn, rook, bishop, then it shows those are duplicated. However, if I put player white's pawn and player black's knight on position "66" together, it unique doesn't work.</p>
  
  <p>Here's my schema code.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  
    &lt;!-- Type Definitions --&gt;
    &lt;xs:simpleType name="pieceSymbolType"&gt;
      &lt;xs:restriction base="xs:string"&gt;
        &lt;xs:pattern value="P|p|R|r|N|n|B|b|K|k|Q|q" /&gt;
      &lt;/xs:restriction&gt;
    &lt;/xs:simpleType&gt;
  
    &lt;xs:simpleType name="pieceNameType"&gt;
      &lt;xs:restriction base="xs:string"&gt;
        &lt;xs:pattern value="pawn|rook|knight|bishop|king|queen" /&gt;
      &lt;/xs:restriction&gt;
    &lt;/xs:simpleType&gt;
  
    &lt;xs:simpleType name="piecePositionRangeType"&gt;
      &lt;xs:restriction base="xs:integer"&gt;
        &lt;xs:minInclusive value="11" /&gt;
        &lt;xs:maxInclusive value="88" /&gt;
      &lt;/xs:restriction&gt;
    &lt;/xs:simpleType&gt;
  
    &lt;xs:simpleType name="playerNameType"&gt;
      &lt;xs:restriction base="xs:string"&gt;
        &lt;xs:pattern value="BLACK|white" /&gt;
      &lt;/xs:restriction&gt;
    &lt;/xs:simpleType&gt;
  
    &lt;xs:simpleType name="takenPieceType"&gt;
      &lt;xs:restriction base="xs:string"&gt;
        &lt;xs:pattern value="yes|no" /&gt;
      &lt;/xs:restriction&gt;
    &lt;/xs:simpleType&gt;
  
    &lt;xs:element name="myChess"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element name="player" minOccurs="2" maxOccurs="2"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                &lt;xs:element name="pieces"&gt;
                  &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                      &lt;xs:element name="piece" minOccurs="1" maxOccurs="16"&gt;
                        &lt;xs:complexType&gt;
                          &lt;xs:attribute name="name" type="pieceNameType" use="optional" /&gt;
                          &lt;xs:attribute name="position" type="piecePositionRangeType" use="required" /&gt;
                          &lt;xs:attribute name="symbol" type="pieceSymbolType"  use="required" /&gt;
                        &lt;/xs:complexType&gt;
                      &lt;/xs:element&gt;
                      &lt;xs:element name="takenPiece" minOccurs="0" maxOccurs="15"&gt;
                        &lt;xs:complexType&gt;
                          &lt;xs:attribute name="name" type="pieceNameType" use="optional" /&gt;
                          &lt;xs:attribute name="symbol" type="pieceSymbolType"  use="required" /&gt;
                        &lt;/xs:complexType&gt;
                      &lt;/xs:element&gt;
                    &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
                  &lt;xs:unique name="UniquePiecePosition"&gt;
                    &lt;xs:selector xpath="piece" /&gt;
                    &lt;xs:field xpath="@position" /&gt;
                  &lt;/xs:unique&gt;
                &lt;/xs:element&gt;
              &lt;/xs:sequence&gt;
              &lt;xs:attribute name="name" type="playerNameType"/&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
        &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>