title: XML Schema Key with multiple fields
body: <p>I have an XML file format that contains a structure of questions:</p>
  
  <pre><code>&lt;question id="q101"&gt;
    &lt;text&gt;Do you like the color red?&lt;/text&gt;
    &lt;answer&gt;yes&lt;/answer&gt;
    &lt;answer&gt;no&lt;/answer&gt;
  &lt;/question&gt;
  &lt;question id="q102"&gt;
    &lt;text&gt;What is your favorite color?&lt;/text&gt;
    &lt;answer&gt;red&lt;/answer&gt;
    &lt;answer&gt;blue&lt;/answer&gt;
    &lt;answer&gt;white&lt;/answer&gt;
    &lt;answer&gt;yellow&lt;/answer&gt;
  &lt;/question&gt;
  </code></pre>
  
  <p>I also have in the same file responses from multiple users.</p>
  
  <pre><code>&lt;user id="bob"&gt;
    &lt;response questionIdRef="q101"&gt;yes&lt;/response&gt;
    &lt;response questionIdRef="q102"&gt;white&lt;/response&gt;
  &lt;/user&gt;
  &lt;user id="jane"&gt;
    &lt;response questionIdRef="q101"&gt;no&lt;/response&gt;
    &lt;response questionIdRef="q102"&gt;blue&lt;/response&gt;
  &lt;/user&gt;
  </code></pre>
  
  <p>I have already defined in the xml a key and a keyref element for the questionId:</p>
  
  <pre><code>&lt;xsd:key name="questionId"&gt;
    &lt;xsd:selector xpath=".//question" /&gt;
    &lt;xsd:field xpath="@id" /&gt;
  &lt;/xsd:key&gt;
  &lt;xsd:keyref name="responseQuestionIdKeyRef" refer="questionId"&gt;
    &lt;xsd:selector xpath=".//response" /&gt;
    &lt;xsd:field xpath="@questionIdRef" /&gt;
  &lt;/xsd:keyref&gt;
  </code></pre>
  
  <p>What I would like to do now would be to do is now have the schema verify that value of the user's response for a certain question is actually an answer provided in the referenced question.  I tried to do this with the following key and keyref, but it would only recognize the first answer, all other answers were not recognized as valid:</p>
  
  <pre><code>&lt;xsd:key name="answerValue"&gt;
    &lt;xsd:selector xpath=".//question" /&gt;
    &lt;xsd:field xpath="@id" /&gt;
    &lt;xsd:field xpath=".//answer/value" /&gt;
  &lt;/xsd:key&gt;
  &lt;xsd:keyref name="validAnswer" refer="answerValue"&gt;
    &lt;xsd:selector xpath=".//response" /&gt;
    &lt;xsd:field xpath="@questionIdRef" /&gt;
    &lt;xsd:field xpath="." /&gt;
  &lt;/xsd:keyref&gt;
  </code></pre>
  
  <p>The exact error I am getting is:</p>
  
  <blockquote>
    <p>The field 'answer' is expecting at most one value.</p>
  </blockquote>
  
  <p>I should note that I am using C# XML validator.</p>
  
  <p>For completeness, below is the complete schema and xml instance I am referring to:
  Schema:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xsd:element name="survey"&gt;
      &lt;xsd:complexType&gt;
        &lt;xsd:sequence&gt;
          &lt;xsd:element name="user" maxOccurs="unbounded"&gt;
            &lt;xsd:complexType&gt;
              &lt;xsd:sequence&gt;
                &lt;xsd:element name="response" maxOccurs="unbounded"&gt;
                  &lt;xsd:complexType&gt;
                    &lt;xsd:simpleContent&gt;
                      &lt;xsd:extension base="xsd:string"&gt;
                        &lt;xsd:attribute name="questionIdRef" type="xsd:string" use="required" /&gt;
                      &lt;/xsd:extension&gt;
                    &lt;/xsd:simpleContent&gt;
                  &lt;/xsd:complexType&gt;
                &lt;/xsd:element&gt;
              &lt;/xsd:sequence&gt;
              &lt;xsd:attribute name="id" type="xsd:string" use="required" /&gt;
            &lt;/xsd:complexType&gt;
          &lt;/xsd:element&gt;
          &lt;xsd:element name="question" maxOccurs="unbounded"&gt;
            &lt;xsd:complexType&gt;
              &lt;xsd:sequence&gt;
                &lt;xsd:element name="text" type="xsd:string" /&gt;
                &lt;xsd:element name="answer" maxOccurs="unbounded" type="xsd:string"/&gt;
              &lt;/xsd:sequence&gt;
              &lt;xsd:attribute name="id" type="xsd:string" use="required" /&gt;
            &lt;/xsd:complexType&gt;
            &lt;xsd:unique name="uniqueAnswer"&gt;
              &lt;xsd:selector xpath=".//answer" /&gt;
              &lt;xsd:field xpath="@value" /&gt;
            &lt;/xsd:unique&gt;
          &lt;/xsd:element&gt;
        &lt;/xsd:sequence&gt;
      &lt;/xsd:complexType&gt;
      &lt;!--
  
      &lt;xsd:key name="questionId"&gt;
        &lt;xsd:selector xpath=".//question" /&gt;
        &lt;xsd:field xpath="@id" /&gt;
      &lt;/xsd:key&gt;
      &lt;xsd:keyref name="responseQuestionIdKeyRef" refer="questionId"&gt;
        &lt;xsd:selector xpath=".//response" /&gt;
        &lt;xsd:field xpath="@questionIdRef" /&gt;
      &lt;/xsd:keyref&gt;
  
      --&gt;
      &lt;xsd:key name="answerValue"&gt;
        &lt;xsd:selector xpath=".//question" /&gt;
        &lt;xsd:field xpath="@id" /&gt;
        &lt;xsd:field xpath=".//answer" /&gt;
      &lt;/xsd:key&gt;
      &lt;xsd:keyref name="validAnswer" refer="answerValue"&gt;
        &lt;xsd:selector xpath=".//response" /&gt;
        &lt;xsd:field xpath="@questionIdRef" /&gt;
        &lt;xsd:field xpath="." /&gt;
      &lt;/xsd:keyref&gt;
      &lt;xsd:unique name="uniqueUserId"&gt;
        &lt;xsd:selector xpath=".//user" /&gt;
        &lt;xsd:field xpath="@id" /&gt;
      &lt;/xsd:unique&gt;
    &lt;/xsd:element&gt;
  &lt;/xsd:schema&gt;
  </code></pre>
  
  <p>Sample XML Instance:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;survey&gt;
    &lt;user id="bob"&gt;
      &lt;response questionIdRef="q101"&gt;yes&lt;/response&gt;
      &lt;response questionIdRef="q102"&gt;white&lt;/response&gt;
    &lt;/user&gt;
    &lt;user id="jane"&gt;
      &lt;response questionIdRef="q101"&gt;no&lt;/response&gt;
      &lt;response questionIdRef="q102"&gt;blue&lt;/response&gt;
    &lt;/user&gt;
    &lt;question id="q101"&gt;
      &lt;text&gt;Do you like the color red?&lt;/text&gt;
      &lt;answer&gt;yes&lt;/answer&gt;
      &lt;answer&gt;no&lt;/answer&gt;
    &lt;/question&gt;
    &lt;question id="q102"&gt;
      &lt;text&gt;What is your favorite color?&lt;/text&gt;
      &lt;answer&gt;red&lt;/answer&gt;
      &lt;answer&gt;blue&lt;/answer&gt;
      &lt;answer&gt;white&lt;/answer&gt;
      &lt;answer&gt;yellow&lt;/answer&gt;
    &lt;/question&gt;
  &lt;/survey&gt;
  </code></pre>