title: Group By and Count in Xquery
body: <p>I am trying to count Similar 'itemid_ref', to get numbers of each Items ref in this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;electrystore&gt;
    &lt;itembill&gt;
     &lt;itembill_id&gt;1&lt;/itembill_id&gt;
     &lt;itemid_ref&gt;2&lt;/itemid_ref&gt;
     &lt;billid_ref&gt;2&lt;/billid_ref&gt;
     &lt;price&gt;20000&lt;/price&gt; 
    &lt;/itembill&gt;
     &lt;itembill&gt;
     &lt;itembill_id&gt;2&lt;/itembill_id&gt;
     &lt;itemid_ref&gt;3&lt;/itemid_ref&gt;
     &lt;billid_ref&gt;3&lt;/billid_ref&gt;
     &lt;price&gt;250000&lt;/price&gt; 
    &lt;/itembill&gt;
    &lt;itembill&gt;
     &lt;itembill_id&gt;3&lt;/itembill_id&gt;
     &lt;itemid_ref&gt;3&lt;/itemid_ref&gt;
     &lt;billid_ref&gt;3&lt;/billid_ref&gt;
     &lt;price&gt;30000&lt;/price&gt; 
    &lt;/itembill&gt;
    &lt;itembill&gt;
     &lt;itembill_id&gt;4&lt;/itembill_id&gt;
     &lt;itemid_ref&gt;1&lt;/itemid_ref&gt;
     &lt;billid_ref&gt;2&lt;/billid_ref&gt;
     &lt;price&gt;140000&lt;/price&gt; 
    &lt;/itembill&gt;
    &lt;itembill&gt;
     &lt;itembill_id&gt;5&lt;/itembill_id&gt;
     &lt;itemid_ref&gt;2&lt;/itemid_ref&gt;
     &lt;billid_ref&gt;1&lt;/billid_ref&gt;
     &lt;price&gt;10000&lt;/price&gt; 
    &lt;/itembill&gt;
  &lt;/electrystore&gt;
  </code></pre>
  
  <p>I am trying to get the output from xquery to be like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;results&gt;
  &lt;result&gt;
      &lt;itemid_ref&gt;
         2
      &lt;/itemid_ref&gt;
      &lt;numberOfitemes&gt;2&lt;/numberOfitemes&gt;
  &lt;/result&gt;
  &lt;result&gt;
      &lt;itemid_ref&gt;
         3
      &lt;/itemid_ref&gt;
      &lt;numberOfitemes&gt;2&lt;/numberOfitemes&gt;
  &lt;/result&gt;
  &lt;result&gt;
     &lt;itemid_ref&gt;
         1
      &lt;/itemid_ref&gt;
      &lt;numberOfitemes&gt;1&lt;/numberOfitemes&gt;
  &lt;/result&gt;
  </code></pre>
  
  <p>how can I do this?</p>