title: XSLT counting elements with a given value
body: <p>I need to count the number of elements in an XML file that have a particular value (to verify uniqueness). The XML file looks like this:</p>
  
  <p><strong>EDIT:</strong> I updated the original "simplified" XML with the actual hairy mess someone designed. Unfortunately, this is going to make all the previous Answers really confusing and wrong unless edited.</p>
  
  <pre><code>&lt;root&gt;
    &lt;ac&gt;
     &lt;Properties&gt;
       &lt;Property Name="Alive"&gt;
        &lt;Properties&gt;
          &lt;Property Name="ID"&gt;
           &lt;Properties&gt;
             &lt;Property Name="Value"&gt;
              &lt;long&gt;11007&lt;/long&gt;
             &lt;/Property&gt;
           &lt;/Properties&gt;
          &lt;/Property&gt;
        &lt;/Properties&gt;
       &lt;/Property&gt;
       &lt;Property Name="Dead"&gt;
        &lt;Properties&gt;
          &lt;Property Name="ID"&gt;
           &lt;Properties&gt;
             &lt;Property Name="Value"&gt;
              &lt;long&gt;11008&lt;/long&gt;
             &lt;/Property&gt;
           &lt;/Properties&gt;
          &lt;/Property&gt;
        &lt;/Properties&gt;
       &lt;/Property&gt;
       ...
       &lt;Property Name="MostlyDeadAllDay"&gt;
        &lt;Properties&gt;
          &lt;Property Name="ID"&gt;
           &lt;Properties&gt;
             &lt;Property Name="Value"&gt;
              &lt;long&gt;99001&lt;/long&gt;
             &lt;/Property&gt;
           &lt;/Properties&gt;
          &lt;/Property&gt;
        &lt;/Properties&gt;
       &lt;/Property&gt;
     &lt;/Properties&gt;
    &lt;/ac&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I am trying to define a variable to see how many of the properties at the Alive/Dead level have the long value (ID) as defined in a template parameter. Something along these lines (though I suspect this is wrong)...</p>
  
  <pre><code>&lt;xsl:param name="parPropId"/&gt;
  &lt;xsl:variable name="countProperties"&gt;
     &lt;xsl:value-of select="count(/root/ac/
        Properties/Property/
        Properties/Property[@Name = 'ID']/
        Properites/Property[@Name = 'Value']/long = $parPropId)"/&gt;
  &lt;/xsl:variable&gt;
  </code></pre>
  
  <p>There can be multiple Property elements defined at the "ID" level. But I am fairly certain I can count on just one Property element ("Value") under "ID", and only one "long" element under "Value".</p>
  
  <p>[disclaimer] Whoever designed the overall XML file I'm stuck working with REALLY didn't know how to structure XML (e.g., backwards use of attributes versus elements). I fear my XSLT thinking has temporarily been warped :) as a result. [/disclaimer]</p>