title: How to group and sum values in XSLT
body: <p>For each "agency" node I need to find the "stmt" elements that have the same key1, key2, key3 values and output just one "stmt" node with the "comm" and "prem" values summed together. For any "stmt" elements within that "agency" that don't match any other "stmt" elements based on key1, key2 and key3 I need to output them as is.  So after transformation the first "agency" node would only have two "stmt" nodes (one summed) and the second "agency" node would be passed as is because the keys don't match.  XSLT 1.0 or 2.0 solutions are ok...though my stylesheet is currently 1.0.  Note that the agency nodes could have any number of "stmt" elements that have matching keys which need to be grouped and summed and any number that don't.</p>
  
  <pre><code>&lt;statement&gt;
  &lt;agency&gt;
      &lt;stmt&gt;
          &lt;key1&gt;1234&lt;/key1&gt;
          &lt;key2&gt;ABC&lt;/key2&gt;
          &lt;key3&gt;15.000&lt;/key3&gt;
          &lt;comm&gt;75.00&lt;/comm&gt;
          &lt;prem&gt;100.00&lt;/prem&gt;
      &lt;/stmt&gt;
      &lt;stmt&gt;
          &lt;key1&gt;1234&lt;/key1&gt;
          &lt;key2&gt;ABC&lt;/key2&gt;
          &lt;key3&gt;15.000&lt;/key3&gt;
          &lt;comm&gt;25.00&lt;/comm&gt;
          &lt;prem&gt;200.00&lt;/prem&gt;
      &lt;/stmt&gt;
      &lt;stmt&gt;
          &lt;key1&gt;1234&lt;/key1&gt;
          &lt;key2&gt;ABC&lt;/key2&gt;
          &lt;key3&gt;17.50&lt;/key3&gt;
          &lt;comm&gt;25.00&lt;/comm&gt;
          &lt;prem&gt;100.00&lt;/prem&gt;
      &lt;/stmt&gt;
  &lt;/agency&gt;
  &lt;agency&gt;
      &lt;stmt&gt;
          &lt;key1&gt;5678&lt;/key1&gt;
          &lt;key2&gt;DEF&lt;/key2&gt;
          &lt;key3&gt;15.000&lt;/key3&gt;
          &lt;comm&gt;10.00&lt;/comm&gt;
          &lt;prem&gt;20.00&lt;/prem&gt;
      &lt;/stmt&gt;
      &lt;stmt&gt;
          &lt;key1&gt;5678&lt;/key1&gt;
          &lt;key2&gt;DEF&lt;/key2&gt;
          &lt;key3&gt;17.000&lt;/key3&gt;
          &lt;comm&gt;15.00&lt;/comm&gt;
          &lt;prem&gt;12.00&lt;/prem&gt;
      &lt;/stmt&gt;
  &lt;/agency&gt;
  </code></pre>
  
  <p>   </p>