title: Using XSLT, how can I select only elements with a certain attribute value?
body: <p>I have XML that looks something like this:</p>
  
  <pre><code>&lt;Assessment xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" GUID="00000000-0000-0000-0000-000000000000"&gt;
    &lt;Data ID="4543" DateCreated="2020-02-18T09:22:31.743"&gt;
      &lt;Questions&gt;
        &lt;Question ID="120" RowNumber="1" ElementName="E147" ElementType="DropDownList" Type="a32c5590-cd7c-4b1f-8df5-592cd243e0e0" Required="false" IncludeComment="false"&gt;
          &lt;Text&gt;Foo Hours&lt;/Text&gt;
          &lt;Answers&gt;
            &lt;Answer ID="718" Type="a32c5590-cd7c-4b1f-8df5-592cd243e0e0"&gt;
              &lt;Text&gt;.25&lt;/Text&gt;
            &lt;/Answer&gt;
          &lt;/Answers&gt;
        &lt;/Question&gt;
        &lt;Question ID="121" RowNumber="2" ElementName="E121" ElementType="CheckBoxList" Type="22c5e458-d3ff-4f45-b669-ba0ec8f3703d" Required="false" IncludeComment="false"&gt;
          &lt;Text&gt;Foo&lt;/Text&gt;
          &lt;Answers&gt;
            &lt;Answer ID="739" Type="22c5e458-d3ff-4f45-b669-ba0ec8f3703d"&gt;
              &lt;Text&gt;This is some text&lt;/Text&gt;
            &lt;/Answer&gt;
          &lt;/Answers&gt;
        &lt;/Question&gt;
        &lt;Question ID="122" RowNumber="3" ElementName="E142" ElementType="TextBox" Type="" Required="false" IncludeComment="false"&gt;
          &lt;Text&gt;Other&lt;/Text&gt;
          &lt;Answers&gt;
            &lt;Answer Type="Assessment6" Qualifier="E142"&gt;
              &lt;Text&gt;42&lt;/Text&gt;
            &lt;/Answer&gt;
          &lt;/Answers&gt;
        &lt;/Question&gt;
        &lt;Question ID="123" RowNumber="4" ElementName="E148" ElementType="DropDownList" Type="a32c5590-cd7c-4b1f-8df5-592cd243e0e0" Required="false" IncludeComment="false"&gt;
          &lt;Text&gt;Bar Hours&lt;/Text&gt;
          &lt;Answers&gt;
            &lt;Answer /&gt;
          &lt;/Answers&gt;
        &lt;/Question&gt;
        &lt;Question ID="124" RowNumber="5" ElementName="E122" ElementType="CheckBoxList" Type="3d29c234-99de-4ba1-a8a1-a3e20a6e880c" Required="false" IncludeComment="false"&gt;
          &lt;Text&gt;Bar &lt;/Text&gt;
          &lt;Answers&gt;
            &lt;Answer /&gt;
          &lt;/Answers&gt;
        &lt;/Question&gt;
        &lt;Question ID="125" RowNumber="6" ElementName="E123" ElementType="TextBox" Type="" Required="false" IncludeComment="false"&gt;
          &lt;Text&gt;Other&lt;/Text&gt;
          &lt;Answers&gt;
            &lt;Answer /&gt;
          &lt;/Answers&gt;
        &lt;/Question&gt;
        &lt;Question ID="126" RowNumber="7" ElementName="E149" ElementType="DropDownList" Type="a32c5590-cd7c-4b1f-8df5-592cd243e0e0" Required="false" IncludeComment="false"&gt;
          &lt;Text&gt;Baz Hours&lt;/Text&gt;
          &lt;Answers&gt;
            &lt;Answer /&gt;
          &lt;/Answers&gt;
        &lt;/Question&gt;
        &lt;Question ID="127" RowNumber="8" ElementName="E124" ElementType="CheckBoxList" Type="5b6901f2-2e52-483b-9b4c-9426744c1076" Required="false" IncludeComment="false"&gt;
          &lt;Text&gt;Baz&lt;/Text&gt;
          &lt;Answers&gt;
            &lt;Answer /&gt;
          &lt;/Answers&gt;
        &lt;/Question&gt;
        &lt;Question ID="128" RowNumber="9" ElementName="E125" ElementType="TextBox" Type="" Required="false" IncludeComment="false"&gt;
          &lt;Text&gt;Other&lt;/Text&gt;
          &lt;Answers&gt;
            &lt;Answer /&gt;
          &lt;/Answers&gt;
        &lt;/Question&gt;
      &lt;/Questions&gt;
    &lt;/Data&gt;
  &lt;/Assessment&gt;
  </code></pre>
  
  <p>I want to select all the <code>Question</code> tags that have <code>ElementType</code> attribute values of <code>DropDownList</code> and add up their values. So I tried this:</p>
  
  <pre><code>&lt;xsl:value-of select="sum(Data/Questions/Question[@ElementType=DropDownList]/Answers/Answer/Text)" /&gt;
  </code></pre>
  
  <p>But I get zero for some reason. If I leave out the <code>[@ElementType=DropDownList]</code> conditional, I get <code>NaN</code> which indicates that all values are being summed, including the text values. So something's wrong with this conditional, but I'm not sure what...</p>