title: How can I restrict the values of an XML attribute based on attribute values in other elements?
body: <p>I have XML elements like this:</p>
  
  <pre><code>&lt;characteristic name="Length"... /&gt;
  &lt;characteristic name="Width"... /&gt;
  &lt;!-- etc. --&gt;
  </code></pre>
  
  <p>Is it possible to restrict the value of another attribute to be one of the values of (XPath) "//characteristic/@name"?</p>
  
  <p>So this would be allowed:</p>
  
  <pre><code>&lt;widget&gt;
      &lt;characteristic name="Length"&gt;100&lt;/characteristic&gt;
  &lt;/widget&gt;
  </code></pre>
  
  <p>But this would not be allowed:</p>
  
  <pre><code>&lt;widget&gt;
      &lt;characteristic name="Bananas"&gt;33&lt;/characteristic&gt;
  &lt;/widget&gt;
  </code></pre>
  
  <p>(Because "Bananas" is not one of the names characteristics.)</p>
  
  <p>I assume this can be done using "key" and "keyref", but I'm not sure how to implement this when both the key and the ref are attribute values.</p>
  
  <p>Also, how would I do this if the characteristics were listed in a different XML document to the widgets? (Is that even possible?) Ideally I'd like to use XSD 1.0, but I'd be interested to know if XSD 1.1 adds anything useful here.</p>