title: Merging and rearranging xml using xslt
body: <p>I am using XSLT for converting a XML derived from web and convert the same on the fly into the target xml file denoted as output .
  I am still unable to do so even after trying a lot , Can anyone please help me out with this conversion .</p>
  
  <p><strong>Source XML</strong><br>
  </p>
  
  <p></p>
  
  <pre><code>&lt;allocelement&gt;
      &lt;hd1&gt;12&lt;/hd1&gt;
      &lt;hd2&gt;14&lt;/hd2&gt;
      &lt;hd3&gt;87&lt;/hd3&gt;
          &lt;alc&gt;1&lt;/alc&gt;
      &lt;amount&gt;4587&lt;/amount&gt;
      &lt;code&gt;1111&lt;/code&gt;
  &lt;/allocelement&gt;
  &lt;alloclement&gt;
          &lt;hd1&gt;12&lt;/hd1&gt;
      &lt;hd2&gt;14&lt;/hd2&gt;
      &lt;hd3&gt;87&lt;/hd3&gt;
      &lt;alc&gt;2&lt;/alc&gt;
      &lt;amount&gt;80000&lt;/amount&gt;
      &lt;code&gt;1111&lt;/code&gt;
  &lt;/alloclement&gt;
  &lt;alloclement&gt;
      &lt;hd1&gt;875&lt;/hd1&gt;
      &lt;hd2&gt;455&lt;/hd2&gt;
      &lt;hd3&gt;455&lt;/hd3&gt;
      &lt;alc&gt;2&lt;/alc&gt;
      &lt;amount&gt;80000&lt;/amount&gt;
      &lt;code&gt;1112&lt;/code&gt;
   &lt;/alloclement&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong><em>Output Desired</em></strong>  </p>
  
  <p></p>
  
  <pre><code>&lt;allocelement&gt;
      &lt;Codeheader&gt;
      &lt;code&gt;1111&lt;/code&gt;
          &lt;hd1&gt;12&lt;/hd1&gt;
          &lt;hd2&gt;14&lt;/hd2&gt;
          &lt;hd3&gt;87&lt;/hd3&gt;
                  &lt;alc&gt;1&lt;/alc&gt;
                      &lt;amount&gt;4587&lt;/amount&gt;
                  &lt;alc&gt;2&lt;/alc&gt;
                      &lt;amount&gt;80000&lt;/amount&gt;
      &lt;/codeHeader&gt;
          &lt;CodeHeader&gt;
      &lt;code&gt;1112&lt;/code&gt;
          &lt;hd1&gt;875&lt;/hd1&gt;
          &lt;hd2&gt;455&lt;/hd2&gt;
          &lt;hd3&gt;455&lt;/hd3&gt;
              &lt;alc&gt;2&lt;/alc&gt;
                &lt;amount&gt;80000&lt;/amount&gt;
      &lt;/CodeHeader&gt;
  &lt;/allocelement&gt;
  </code></pre>
  
  <p></p>
  
  <p>The Grouping is on the basis of Code,[hd1,hd2,hd3] such that the different elements within  which have the same  Code and [hd1,hd2,hd3] will be merged and only show fields which are different viz. the  and . 
  Also I am using xslt 1.0 .   </p>