title: XSLT counting elements with a matching value
body: <p>I have a variation on <a href="https://stackoverflow.com/questions/721963/xslt-counting-elements-with-a-given-value">this</a> question</p>
  <p>Given the following input XML</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;root&gt;
    &lt;zone name=&quot;zone1&quot;/&gt;
    &lt;zone name=&quot;zone2&quot;/&gt;
  
    &lt;device name=&quot;foo&quot; zone=&quot;zone1&quot;/&gt;
    &lt;device name=&quot;bar&quot; zone=&quot;zone1&quot;/&gt;
  &lt;/root&gt;
  </code></pre>
  <p>I wish to count - in XSLT - how many devices are in any given zone.</p>
  <p>With my limited knowledge I came up with:</p>
  <pre class="lang-xml prettyprint-override"><code>...
  &lt;xsl:for-each select=&quot;zone&quot;&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;xsl:value-of select=&quot;@name&quot;/&gt;&lt;/td&gt;
      &lt;td&gt;&lt;xsl:value-of select=&quot;count(/root/device[@zone = @name]&quot;/&gt;&lt;/td&gt;
    &lt;/tr&gt;
  </code></pre>
  <p>How do I make it clear in the above statement that I want to compare the attribute <code>zone</code> from the <code>&lt;device&gt;</code> element with the <code>name</code> attribute from the current <code>&lt;zone&gt;</code> element?</p>
  <p>Or is there perhaps a better/clearer way in achieving my ultimate goal?</p>