title: Transform a XML file using attribute values from one node and merging with another node
body: <p>I have written below XSLT to achieve translation required for my reporting requirement.</p>
  <p>Though, Input and Output XML are self-explanatory, but in short, requirement is to build a new XML from an existing XML by merging different pair of nodes, related by common attribute.</p>
  <p><strong>Input File</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;dataset  xmlns=&quot;http://developer.cognos.com/schemas/xmldata/1/&quot;  xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
  &lt;crosstab&gt;
  &lt;values&gt;
    &lt;value row=&quot;R1&quot; col=&quot;C1&quot;&gt;111&lt;/value&gt;
    &lt;value row=&quot;R1&quot; col=&quot;C2&quot;&gt;222&lt;/value&gt;
    &lt;value row=&quot;R1&quot; col=&quot;C3&quot;&gt;333&lt;/value&gt;
    &lt;value row=&quot;R1&quot; col=&quot;C4&quot;&gt;444&lt;/value&gt;
    &lt;value row=&quot;R1&quot; col=&quot;C5&quot;&gt;555&lt;/value&gt;
    &lt;value row=&quot;R1&quot; col=&quot;C6&quot;&gt;666&lt;/value&gt;
    &lt;value row=&quot;R1&quot; col=&quot;C7&quot;&gt;777&lt;/value&gt;
  &lt;/values&gt;
  &lt;corner&gt;
    &lt;caption&gt;Number of Employees&lt;/caption&gt;
  &lt;/corner&gt;
  &lt;columns&gt;
    &lt;colEdge&gt;
      &lt;caption&gt;2010&lt;/caption&gt;
      &lt;colEdge id=&quot;C1&quot;&gt;
        &lt;caption&gt;October&lt;/caption&gt;
      &lt;/colEdge&gt;
      &lt;colEdge id=&quot;C2&quot;&gt;
        &lt;caption&gt;November&lt;/caption&gt;
      &lt;/colEdge&gt;
      &lt;colEdge id=&quot;C3&quot;&gt;
        &lt;caption&gt;December&lt;/caption&gt;
      &lt;/colEdge&gt;
    &lt;/colEdge&gt;
    &lt;colEdge&gt;
      &lt;caption&gt;2011&lt;/caption&gt;
      &lt;colEdge id=&quot;C4&quot;&gt;
        &lt;caption&gt;January&lt;/caption&gt;
      &lt;/colEdge&gt;
      &lt;colEdge id=&quot;C5&quot;&gt;
        &lt;caption&gt;February&lt;/caption&gt;
      &lt;/colEdge&gt;
      &lt;colEdge id=&quot;C6&quot;&gt;
        &lt;caption&gt;March&lt;/caption&gt;
      &lt;/colEdge&gt;
      &lt;colEdge id=&quot;C7&quot;&gt;
        &lt;caption&gt;April&lt;/caption&gt;
      &lt;/colEdge&gt;
    &lt;/colEdge&gt;
  &lt;/columns&gt;
  &lt;rows&gt;
  &lt;/rows&gt;
  </code></pre>
    
      
  <p><strong>Output File</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;dataset xmlns:c=&quot;http://developer.cognos.com/schemas/xmldata/1/&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
  &lt;crosstab&gt;
  &lt;values&gt;
    &lt;value col=&quot;October 2010&quot;&gt;111&lt;/value&gt;
    &lt;value col=&quot;November 2010&quot;&gt;222&lt;/value&gt;
    &lt;value col=&quot;December 2010&quot;&gt;333&lt;/value&gt;
    &lt;value col=&quot;January 2011&quot;&gt;444&lt;/value&gt;
    &lt;value col=&quot;February 2011&quot;&gt;555&lt;/value&gt;
    &lt;value col=&quot;March 2011&quot;&gt;666&lt;/value&gt;
    &lt;value col=&quot;April 2011&quot;&gt;777&lt;/value&gt;
  &lt;/values&gt;
  &lt;corner&gt;
    &lt;caption&gt;Number of Employees&lt;/caption&gt;
  &lt;/corner&gt;
  &lt;/crosstab&gt;
  &lt;/dataset&gt;
  </code></pre>