title: xsd:unique with optional attributes
body: <p>I have this Xml file:</p>
  
  <pre><code>&lt;objects&gt;
    &lt;object name="ID1" /&gt;
    &lt;object name="ID2" /&gt;
    &lt;object name="ID2" color="green" /&gt;
    &lt;object name="ID3" color="green" /&gt;
  &lt;objects&gt;
  </code></pre>
  
  <p>I would like to validate this against an XSD Schema, so that the combination between <code>name</code> and <code>color</code> are unique in the document.</p>
  
  <p>The problem is that, if I use:</p>
  
  <pre><code>&lt;xs:unique name="UniqueObjectNameColor"&gt;
    &lt;xs:selector xpath="./object" /&gt;
    &lt;xs:field xpath="@name" /&gt;
    &lt;xs:field xpath="@color" /&gt;
  &lt;/xs:unique&gt;
  </code></pre>
  
  <p>... the rule will ignore <code>object</code> elements without the optional <code>color</code> attribute. The following validates correctly while it shouldn't.</p>
  
  <pre><code>  &lt;object name="ID2" /&gt;
    &lt;object name="ID2" /&gt;
  </code></pre>
  
  <p>Can you tell me how can I specify a rule that enforces unique <code>name</code> and <code>color</code> combinations and, when the <code>color</code> attribute is not present in the element <code>object</code>, it checks the <code>name</code>?</p>