title: compare 2 xml nodesets in same xml and come up with a resultant xml
body: <p>I have an xml with 2 different node sets in it. I need a comparison between them and pick up the values as needed in result.</p>
  
  <h1>Request</h1>
  
  <pre><code>&lt;MyMessage&gt;
    &lt;EmployeeLookup&gt;
      &lt;EmployeeQuery&gt;
        &lt;MsgId&gt;XXX&lt;/MsgId&gt;
        &lt;LookupValues&gt;
          &lt;LookupValue&gt;
            &lt;Name&gt;SSN&lt;/Name&gt;
            &lt;Value&gt;123456&lt;/Value&gt;
          &lt;/LookupValue&gt;
          &lt;LookupValue&gt;
            &lt;Name&gt;DrivingLicense&lt;/Name&gt;
            &lt;Value&gt;AA-234-123&lt;/Value&gt;
          &lt;/LookupValue&gt;
        &lt;/LookupValues&gt;
      &lt;/EmployeeQuery&gt;
      &lt;EmployeeQuery&gt;
        &lt;MsgId&gt;YYY&lt;/MsgId&gt;
        &lt;LookupValues&gt;
          &lt;LookupValue&gt;
            &lt;Name&gt;DrivingLicense&lt;/Name&gt;
            &lt;Value&gt;BB-494-432&lt;/Value&gt;
          &lt;/LookupValue&gt;
        &lt;/LookupValues&gt;
      &lt;/EmployeeQuery&gt;
      &lt;EmployeeQuery&gt;
        &lt;MsgId&gt;ZZZ&lt;/MsgId&gt;
        &lt;LookupValues&gt;
          &lt;LookupValue&gt;
            &lt;Name&gt;SSN&lt;/Name&gt;
            &lt;Value&gt;fakessn&lt;/Value&gt;
          &lt;/LookupValue&gt;
        &lt;/LookupValues&gt;
      &lt;/EmployeeQuery&gt;
    &lt;/EmployeeLookup&gt;
    &lt;KnownEmployees&gt;
      &lt;Employee&gt;
        &lt;eno&gt;101&lt;/eno&gt;
        &lt;SSN&gt;123456&lt;/SSN&gt;
        &lt;DrivingLicense&gt;AA-234-123&lt;/DrivingLicense&gt;
      &lt;/Employee&gt;
      &lt;Employee&gt;
        &lt;eno&gt;102&lt;/eno&gt;
        &lt;SSN&gt;456677&lt;/SSN&gt;
        &lt;DrivingLicense&gt;BB-494-432&lt;/DrivingLicense&gt;
      &lt;/Employee&gt;
    &lt;/KnownEmployees&gt;
  &lt;/MyMessage&gt;
  </code></pre>
  
  <h1>Result needed</h1>
  
  <pre><code>&lt;CombinedResult&gt;
    &lt;Employee&gt;
      &lt;MsgId&gt;XXX&lt;/MsgId&gt;
      &lt;RetrievedIds&gt;
        &lt;Identifier&gt;
          &lt;Name&gt;eno&lt;/Name&gt;
          &lt;Value&gt;101&lt;/Value&gt;
        &lt;/Identifier&gt;
      &lt;/RetrievedIds&gt;
    &lt;/Employee&gt;
    &lt;Employee&gt;
      &lt;MsgId&gt;YYY&lt;/MsgId&gt;
      &lt;RetrievedIds&gt;
        &lt;Identifier&gt;
          &lt;Name&gt;eno&lt;/Name&gt;
          &lt;Value&gt;102&lt;/Value&gt;
        &lt;/Identifier&gt;
      &lt;/RetrievedIds&gt;
    &lt;/Employee&gt;
    &lt;Employee&gt;
      &lt;MsgId&gt;ZZZ&lt;/MsgId&gt;
      &lt;RetrievedIds /&gt;
    &lt;/Employee&gt;
  &lt;/CombinedResult&gt;
  </code></pre>
  
  <p>We need to retrieve the employee number (eno) based on the lookup values such as SSN, DrivingLicense number. They can be 1 to n. We need to retrieve based on <strong>any</strong> of the provided lookup values.</p>
  
  <p>I tried defining a key like</p>
  
  <pre><code>&lt;xsl:key name="MyKey" match="//Employee" use="*" /&gt;
  </code></pre>
  
  <p>That works.. but it fails if two keys have the same value.</p>
  
  <p>So, I tried doing </p>
  
  <pre><code>&lt;xsl:key name="MyKey" match="//Employee" use="concat(local-name(*),'|',.)" /&gt;
  </code></pre>
  
  <p>But in that case, it is matching only the first field i.e. Employee/SSN</p>
  
  <p>Can some guide me here.. I am open to any approach if not the xsl:key way.</p>