title: XSLT: Matching Xpath attributes to attributes from for-each scope
body: <p>I guess my problem is quite common, so there must be an easy solution. Consider the following xml snippet:</p>
  
  <pre><code>  &lt;categories&gt;
      &lt;category name="cat1" /&gt;
      &lt;category name="cat2" /&gt;
      &lt;category name="cat3" /&gt;
      &lt;category name="cat4" /&gt;
    &lt;/categories&gt;
    &lt;data&gt;
      &lt;catval name="cat2"&gt;foo&lt;/catval&gt;
      &lt;catval name="cat4"&gt;bar&lt;/catval&gt;
      &lt;catval name="cat3"&gt;boo&lt;/catval&gt;
    &lt;/data&gt;
  </code></pre>
  
  <p>I need to output the catval values in the order defined in the categories element (including categories that have no data). Please note that in the real input xml, there are multiple <em>data</em> elements all over the place and the output is way more complex, so creating a template for <em>categories</em> is not feasible. I am using a construct like the following:</p>
  
  <pre><code>&lt;xsl:template match="data"&gt;
      &lt;xsl:variable name="currentdata" select="." /&gt;
      &lt;xsl:for-each select="../categories/category"&gt;
        &lt;xsl:value-of select="@name" /&gt;: 
        &lt;xsl:value-of 
          select="$currentdata/catval[@name=@name]" /&gt; &lt;!-- ??? --&gt;
      &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>I don't know if this is the best approach to solve my problem, but even if it isn't: How can I match the <em>name</em> attribute of $currentdata/catval to the <em>name</em> attribute of the <em>category</em> element in the context of the for-each loop?</p>