title: Help with XSLT Transformation
body: <p>I was hoping I could get a little assistance with an XSLT transform.  I can't seem to get it right.</p>
  
  <p>Here is a sample of the source xml document:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;Locations&gt;
      &lt;header&gt;
         &lt;location&gt;Location Field&lt;/location&gt;
         &lt;job_function&gt;Job Function Field&lt;/job_function&gt;
         &lt;count&gt;Count&lt;/count&gt;
      &lt;/header&gt;
     &lt;data&gt;
        &lt;location&gt;2177&lt;/location&gt;
        &lt;job_function&gt;ADM&lt;/job_function&gt;
        &lt;count&gt;1&lt;/count&gt;
     &lt;/data&gt;
     &lt;data&gt;
          &lt;location&gt;2177&lt;/location&gt;
        &lt;job_function&gt;OPS&lt;/job_function&gt;
        &lt;count&gt;1&lt;/count&gt;
     &lt;/data&gt;
     &lt;data&gt;
        &lt;location&gt;2177&lt;/location&gt;
        &lt;job_function&gt;SLS&lt;/job_function&gt;
        &lt;count&gt;5&lt;/count&gt;
     &lt;/data&gt;
     &lt;data&gt;
        &lt;location&gt;2179&lt;/location&gt;
        &lt;job_function&gt;ADM&lt;/job_function&gt;
        &lt;count&gt;1&lt;/count&gt;
     &lt;/data&gt;
     &lt;data&gt;
        &lt;location&gt;2179&lt;/location&gt;
        &lt;job_function&gt;SEC&lt;/job_function&gt;
        &lt;count&gt;1&lt;/count&gt;
     &lt;/data&gt;
    &lt;/Locations&gt;
  </code></pre>
  
  <p>I want to transform it into the following format:</p>
  
  <pre><code>&lt;Locations&gt;
     &lt;data&gt;
      &lt;PeopleSoftID&gt;2177&lt;/PeopleSoftID&gt;
      &lt;ADM&gt;1&lt;/ADM&gt;
      &lt;OPS&gt;1&lt;/OPS&gt;
      &lt;SLS&gt;5&lt;/SLS&gt;
      &lt;TotalCount&gt;7&lt;/TotalCount&gt;
     &lt;/data&gt;
     &lt;data&gt;
      &lt;PeopleSoftID&gt;2179&lt;/PeopleSoftID&gt;
      &lt;ADM&gt;1&lt;/ADM&gt;
      &lt;SEC&gt;1&lt;/SEC&gt;
      &lt;TotalCount&gt;2&lt;/TotalCount&gt;
     &lt;/data&gt;
   &lt;/Locations&gt;
  </code></pre>
  
  <p>So basically, as you can see in the sample source document there are multiple  elements that have the same value.  In the destination document, there should now only be one record (<code>&lt;PeopleSoftID&gt;</code> element) per <code>&lt;location&gt;</code> element value in the source document.  Since there were 3 <code>&lt;location&gt;</code> elements with the value of 2177, the destination document now has just 1 <code>&lt;PeopleSoftID&gt;</code> element that contains that value.  The value of the <code>&lt;job_function&gt;</code> element in the source document becomes an element in the destination document.  The value of that new element ends up being the sibling value of the <code>&lt;count&gt;</code> element from the source document.  The <code>&lt;TotalCount&gt;</code> element in the destination document is the SUM of the values of all the new elements that are generated from the source <code>&lt;job_function&gt;</code> element.</p>
  
  <p>I hope that explanation did not confuse anybody =).</p>
  
  <p>I am a little new to XSLTs still so I am having trouble getting the logic right on this.  </p>
  
  <p><strong>I can only use XSLT 1.0 too.</strong></p>
  
  <p>If I did not provide enough information let me know, and I will try to provide more as soon as I am able.  </p>
  
  <p>Thanks guys!</p>