title: Connect one key to another key in XSL file
body: <p>I'm trying connect values of <code>RestaurantId</code> in <code>ReviewApplication/Reviews/Review</code> node to <code>Restaurant/Name</code> in <code>Companys/Company/Restaurants/Restaurant</code> node in the XSL file, but I'm not sure how to do, I've tried <code>&lt;choose&gt;</code> and <code>&lt;key&gt;</code> but it's currently not working for me.. I really appreciate any input!</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  
  &lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
                  xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;
                  exclude-result-prefixes=&quot;xs&quot;
                  version=&quot;2.0&quot;&gt;
      &lt;xsl:key name=&quot;firstname&quot; match=&quot;ReviewApplication/Reviews/Review/UserName&quot; use=&quot;ReviewApplication/Users/User/FirstName&quot; /&gt;
  
      &lt;xsl:output method=&quot;html&quot; indent=&quot;yes&quot;&gt;&lt;/xsl:output&gt;
    
      &lt;xsl:template match=&quot;/ReviewApplication&quot;&gt;
      
  
          &lt;html&gt;&lt;head&gt;&lt;title&gt;Reviews with Recommendations&lt;/title&gt;&lt;/head&gt;&lt;body&gt;
  
              &lt;table border=&quot;1&quot;&gt;
                  &lt;tr&gt;
                      &lt;th&gt;RestaurantName&lt;/th&gt;
                      &lt;th&gt;FirstName&lt;/th&gt;
                      &lt;th&gt;Rating&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;xsl:for-each select=&quot;/ReviewApplication/Reviews/Review&quot;&gt;
  
                      &lt;xsl:variable name=&quot;restaurantname&quot; select=&quot;/ReviewApplication/Companys/Company/Restaurants/Restaurant/Name&quot; /&gt;
                      &lt;xsl:variable name=&quot;name&quot; select=&quot;../../Users/User/FirstName&quot; /&gt;
  
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;xsl:value-of select=&quot;RestaurantId&quot;&gt;&lt;/xsl:value-of&gt;
                          &lt;/td&gt;
  
  
  
                          &lt;td&gt;
                              &lt;xsl:value-of select=&quot;UserName&quot;&gt;&lt;/xsl:value-of&gt;
                          &lt;/td&gt;
  
                          &lt;td&gt;
                              &lt;xsl:value-of select=&quot;Rating&quot;&gt;&lt;/xsl:value-of&gt;
                          &lt;/td&gt;
  
  
                      &lt;/tr&gt;
                  &lt;/xsl:for-each&gt;
              &lt;/table&gt;
          &lt;/body&gt;&lt;/html&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  <p>My XML file:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;ReviewApplication&gt;
     &lt;Users&gt;
        &lt;User&gt;
           &lt;UserName&gt;username1&lt;/UserName&gt;
           &lt;FirstName&gt;first1&lt;/FirstName&gt;
           &lt;LastName&gt;last1&lt;/LastName&gt;
        &lt;/User&gt;
        &lt;User&gt;
           &lt;UserName&gt;username2&lt;/UserName&gt;
           &lt;FirstName&gt;first2&lt;/FirstName&gt;
           &lt;LastName&gt;last2&lt;/LastName&gt;
        &lt;/User&gt;
        &lt;User&gt;
           &lt;UserName&gt;username3&lt;/UserName&gt;
           &lt;FirstName&gt;first3&lt;/FirstName&gt;
           &lt;LastName&gt;last3&lt;/LastName&gt;
        &lt;/User&gt;
        &lt;User&gt;
           &lt;UserName&gt;username4&lt;/UserName&gt;
           &lt;FirstName&gt;first4&lt;/FirstName&gt;
           &lt;LastName&gt;last4&lt;/LastName&gt;
        &lt;/User&gt;
        &lt;User&gt;
           &lt;UserName&gt;username5&lt;/UserName&gt;
           &lt;FirstName&gt;first5&lt;/FirstName&gt;
           &lt;LastName&gt;last5&lt;/LastName&gt;
        &lt;/User&gt;
     &lt;/Users&gt;
     &lt;Companys&gt;
        &lt;Company&gt;
           &lt;CompanyName&gt;companyname1&lt;/CompanyName&gt;
           &lt;About&gt;aboutcompany1&lt;/About&gt;
           &lt;Restaurants&gt;
              &lt;Restaurant&gt;
                 &lt;RestaurantId&gt;restaurantid1&lt;/RestaurantId&gt;
                 &lt;Name&gt;restaurant1&lt;/Name&gt;
              &lt;/Restaurant&gt;
              &lt;Restaurant&gt;
                 &lt;RestaurantId&gt;restaurantid2&lt;/RestaurantId&gt;
                 &lt;Name&gt;restaurant2&lt;/Name&gt;
              &lt;/Restaurant&gt;
              &lt;Restaurant&gt;
                 &lt;RestaurantId&gt;restaurantid3&lt;/RestaurantId&gt;
                 &lt;Name&gt;restaurant3&lt;/Name&gt;
              &lt;/Restaurant&gt;
           &lt;/Restaurants&gt;
        &lt;/Company&gt;
        &lt;Company&gt;
           &lt;CompanyName&gt;companyname2&lt;/CompanyName&gt;
           &lt;About&gt;aboutcompany2&lt;/About&gt;
           &lt;Restaurants&gt;
              &lt;Restaurant&gt;
                 &lt;RestaurantId&gt;restaurantid4&lt;/RestaurantId&gt;
                 &lt;Name&gt;restaurant4&lt;/Name&gt;
              &lt;/Restaurant&gt;
              &lt;Restaurant&gt;
                 &lt;RestaurantId&gt;restaurantid5&lt;/RestaurantId&gt;
                 &lt;Name&gt;restaurant5&lt;/Name&gt;
              &lt;/Restaurant&gt;
              &lt;Restaurant&gt;
                 &lt;RestaurantId&gt;restaurantid6&lt;/RestaurantId&gt;
                 &lt;Name&gt;restaurant6&lt;/Name&gt;
              &lt;/Restaurant&gt;
           &lt;/Restaurants&gt;
        &lt;/Company&gt;
        &lt;Company&gt;
           &lt;CompanyName&gt;companyname3&lt;/CompanyName&gt;
           &lt;About&gt;aboutcompany3&lt;/About&gt;
           &lt;Restaurants&gt;
              &lt;Restaurant&gt;
                 &lt;RestaurantId&gt;restaurantid7&lt;/RestaurantId&gt;
                 &lt;Name&gt;restaurant7&lt;/Name&gt;
              &lt;/Restaurant&gt;
              &lt;Restaurant&gt;
                 &lt;RestaurantId&gt;restaurantid8&lt;/RestaurantId&gt;
                 &lt;Name&gt;restaurant8&lt;/Name&gt;
              &lt;/Restaurant&gt;
              &lt;Restaurant&gt;
                 &lt;RestaurantId&gt;restaurantid9&lt;/RestaurantId&gt;
                 &lt;Name&gt;restaurant9&lt;/Name&gt;
              &lt;/Restaurant&gt;
           &lt;/Restaurants&gt;
        &lt;/Company&gt;
     &lt;/Companys&gt;
     &lt;Reviews&gt;
        &lt;Review&gt;
           &lt;UserName&gt;username1&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid1&lt;/RestaurantId&gt;
           &lt;Rating&gt;4.0&lt;/Rating&gt;
        &lt;/Review&gt;
        &lt;Review&gt;
           &lt;UserName&gt;username1&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid2&lt;/RestaurantId&gt;
           &lt;Rating&gt;5.0&lt;/Rating&gt;
        &lt;/Review&gt;
        &lt;Review&gt;
           &lt;UserName&gt;username1&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid4&lt;/RestaurantId&gt;
           &lt;Rating&gt;4.0&lt;/Rating&gt;
        &lt;/Review&gt;
        &lt;Review&gt;
           &lt;UserName&gt;username1&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid5&lt;/RestaurantId&gt;
           &lt;Rating&gt;1.0&lt;/Rating&gt;
        &lt;/Review&gt;
        &lt;Review&gt;
           &lt;UserName&gt;username2&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid1&lt;/RestaurantId&gt;
           &lt;Rating&gt;2.0&lt;/Rating&gt;
        &lt;/Review&gt;
        &lt;Review&gt;
           &lt;UserName&gt;username2&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid7&lt;/RestaurantId&gt;
           &lt;Rating&gt;3.0&lt;/Rating&gt;
        &lt;/Review&gt;
        &lt;Review&gt;
           &lt;UserName&gt;username2&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid8&lt;/RestaurantId&gt;
           &lt;Rating&gt;4.0&lt;/Rating&gt;
        &lt;/Review&gt;
     &lt;/Reviews&gt;
     &lt;Recommendations&gt;
        &lt;Recommendation&gt;
           &lt;UserName&gt;username1&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid1&lt;/RestaurantId&gt;
        &lt;/Recommendation&gt;
        &lt;Recommendation&gt;
           &lt;UserName&gt;username1&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid2&lt;/RestaurantId&gt;
        &lt;/Recommendation&gt;
        &lt;Recommendation&gt;
           &lt;UserName&gt;username1&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid4&lt;/RestaurantId&gt;
        &lt;/Recommendation&gt;
        &lt;Recommendation&gt;
           &lt;UserName&gt;username1&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid5&lt;/RestaurantId&gt;
        &lt;/Recommendation&gt;
        &lt;Recommendation&gt;
           &lt;UserName&gt;username3&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid1&lt;/RestaurantId&gt;
        &lt;/Recommendation&gt;
        &lt;Recommendation&gt;
           &lt;UserName&gt;username4&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid7&lt;/RestaurantId&gt;
        &lt;/Recommendation&gt;
        &lt;Recommendation&gt;
           &lt;UserName&gt;username5&lt;/UserName&gt;
           &lt;RestaurantId&gt;restaurantid8&lt;/RestaurantId&gt;
        &lt;/Recommendation&gt;
     &lt;/Recommendations&gt;
  &lt;/ReviewApplication&gt;
  </code></pre>
  <p>EDIT-- Expected result:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
    &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;HW 5.10&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;Reviews with Details&lt;/h1&gt;
      &lt;table border="1"&gt;
        &lt;tr&gt;
          &lt;th&gt;RestaurantName&lt;/th&gt;
          &lt;th&gt;FirstName&lt;/th&gt;
          &lt;th&gt;Rating&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;restaurant1&lt;/td&gt;
          &lt;td&gt;first1&lt;/td&gt;
          &lt;td&gt;4.0&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;restaurant2&lt;/td&gt;
          &lt;td&gt;first1&lt;/td&gt;
          &lt;td&gt;5.0&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;restaurant4&lt;/td&gt;
          &lt;td&gt;first1&lt;/td&gt;
          &lt;td&gt;4.0&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;restaurant5&lt;/td&gt;
          &lt;td&gt;first1&lt;/td&gt;
          &lt;td&gt;1.0&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;restaurant1&lt;/td&gt;
          &lt;td&gt;first2&lt;/td&gt;
          &lt;td&gt;2.0&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;restaurant7&lt;/td&gt;
          &lt;td&gt;first2&lt;/td&gt;
          &lt;td&gt;3.0&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;restaurant8&lt;/td&gt;
          &lt;td&gt;first2&lt;/td&gt;
          &lt;td&gt;4.0&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>