title: How can I count the number of elements in an XML document using xmlstarlet in BASH?
body: <p>I need to count the number of times an element occurs within an XML document. The element I need to count is called 'ThreadGroup'</p>
  
  <p>Elelement to count:</p>
  
  <pre><code>&lt;ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true"&gt;
  </code></pre>
  
  <p>There are three ThreadGroup elements in the following XML. How can we count them using xmlstarlet?</p>
  
  <p>Test XML </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jmeterTestPlan version="1.2" properties="2.8" jmeter="2.13 r1665067"&gt;
  &lt;hashTree&gt;
  &lt;TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true"&gt;
    &lt;stringProp name="TestPlan.comments"&gt;&lt;/stringProp&gt;
    &lt;boolProp name="TestPlan.functional_mode"&gt;false&lt;/boolProp&gt;
    &lt;boolProp name="TestPlan.serialize_threadgroups"&gt;false&lt;/boolProp&gt;
    &lt;elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"&gt;
      &lt;collectionProp name="Arguments.arguments"/&gt;
    &lt;/elementProp&gt;
    &lt;stringProp name="TestPlan.user_define_classpath"&gt;&lt;/stringProp&gt;
  &lt;/TestPlan&gt;
  &lt;hashTree&gt;
    &lt;ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true"&gt;
      &lt;stringProp name="ThreadGroup.on_sample_error"&gt;continue&lt;/stringProp&gt;
    &lt;/ThreadGroup&gt;
    &lt;hashTree/&gt;
    &lt;ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true"&gt;
      &lt;stringProp name="ThreadGroup.on_sample_error"&gt;continue&lt;/stringProp&gt;
    &lt;/ThreadGroup&gt;
    &lt;hashTree/&gt;
    &lt;ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true"&gt;
      &lt;stringProp name="ThreadGroup.on_sample_error"&gt;continue&lt;/stringProp&gt;
  
    &lt;/ThreadGroup&gt;
    &lt;hashTree/&gt;
  &lt;/hashTree&gt;
  </code></pre>
  
  <p>
  </p>