title: How to find element that matches xslt attribute value in for-each loop
body: <p>Suppose I have the following XML:</p>
  
  <pre><code>&lt;data&gt;
    &lt;foos&gt;
      &lt;foo id="1" checked="yes" /&gt;
      &lt;foo id="2" /&gt;
      &lt;foo id="3" /&gt;
      &lt;foo id="4" checked="yes" /&gt;
    &lt;/foos&gt;
    &lt;bars&gt;
      &lt;bar for="1" name="blub" /&gt;
      &lt;bar for="2" name="bla" /&gt;
      &lt;bar for="3" name="baz" /&gt;
      &lt;bar for="4" name="plim" /&gt;
    &lt;/bars&gt;
  &lt;/data&gt;
  </code></pre>
  
  <p>Now I want to print all the <code>name</code> attributes of those element <code>bar</code> which point to an element <code>foo</code> that has the attribute <code>checked</code>. So for the example above, my xslt would output <code>blub</code> and <code>plim</code>.</p>
  
  <p>Here is what I have tried so far is to just check whether I can print the <code>id</code> attribute of the <code>foo</code> element that each <code>bar</code> belongs to:</p>
  
  <pre><code>&lt;xsl:template match="/"&gt;
    &lt;xsl:for-each select="//bars/bar"&gt;
      &lt;xsl:value-of select="../../foos/foo[@id=./@for]/@id" /&gt;
    &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>but to no avail. I think the problem is, that the check <code>foo[@id=./@for]</code> will select both <code>@id</code> and <code>@for</code> from the <code>foo</code> element. So how can I say that I want the <code>@for</code> attribute from my current element in the for loop but the <code>@id</code> from the <em>other</em> current element?</p>