title: XSLT Merge challenge Pt. II
body: <p>I have an XML document with 2 Customer Nodes (Current and Updated). I would like to be able to traverse through and produce a resulting XML document to merge the Customer and its various elements (Addresses, Contacts, Accounts, etc.) along with a status at the filed and parent level(s). The solution needs to be able to traverse through n number of child elements which may have n number of children themselves. The format of the input XML is open to change. I can make the Ids attributes if it helps.</p>
  
  <p>Input:</p>
  
  <pre><code> &lt;Customer Id="Current"&gt;
         &lt;CustId&gt;1&lt;/CustId&gt;
         &lt;CustName&gt;Acme&lt;/CustName&gt;
     &lt;Addresses&gt;
         &lt;Address&gt;
            &lt;AddressId&gt;1&lt;/AddressId&gt;
            &lt;Street&gt;111 Main&lt;/Street&gt;
        &lt;/Address&gt;
        &lt;Address&gt;
            &lt;AddressId&gt;2&lt;/AddressId&gt;
            &lt;Street&gt;222 Main&lt;/Street&gt;
        &lt;/Address&gt;
     &lt;Contacts&gt;
        &lt;Contact&gt;
          &lt;ContactId&gt;1&lt;/ContactId&gt;
          &lt;ContactName&gt;Tom&lt;/ContactName&gt;
          &lt;ContactPhone&gt;555-1212&lt;/ContactPhone&gt;
        &lt;/Contact&gt;
     &lt;/Contacts&gt;
     &lt;/Customer&gt;
       &lt;Customer Id="Updated"&gt;
         &lt;CustId&gt;1&lt;/CustId&gt;
         &lt;CustName&gt;Acme&lt;/CustName&gt;
     &lt;Addresses&gt;
         &lt;Address&gt;
            &lt;AddressId&gt;1&lt;/AddressId&gt;
            &lt;Street&gt;111 Main&lt;/Street&gt;
        &lt;/Address&gt;
        &lt;Address&gt;
            &lt;AddressId&gt;3&lt;/AddressId&gt;
            &lt;Street&gt;333 Main&lt;/Street&gt;
        &lt;/Address&gt;
     &lt;Contacts&gt;
        &lt;Contact&gt;
          &lt;ContactId&gt;1&lt;/ContactId&gt;
          &lt;ContactName&gt;Tom&lt;/ContactName&gt;
          &lt;ContactPhone&gt;555-1212&lt;/ContactPhone&gt;
        &lt;/Contact&gt;
     &lt;/Contacts&gt;
    &lt;/Customer&gt;
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>    &lt;Customer Id="Updated" status="Changed"&gt;
         &lt;CustId&gt;1&lt;/CustId&gt;
         &lt;CustName&gt;Acme&lt;/CustName&gt;
         &lt;CustRegion status="New"/&gt;
       &lt;Addresses status="Changed"&gt;
         &lt;Address&gt;
            &lt;AddressId&gt;1&lt;/AddressId&gt;
            &lt;Street&gt;111 Main&lt;/Street&gt;
        &lt;/Address&gt;
        &lt;Address Status="Deleted"&gt;
            &lt;AddressId&gt;2&lt;/AddressId&gt;
            &lt;Street&gt;222 Main&lt;/Street&gt;
        &lt;/Address&gt;
        &lt;Address Status="New"&gt;
            &lt;AddressId status="New"&gt;3&lt;/AddressId&gt;
            &lt;Street status="New"&gt;222 Main&lt;/Street&gt;
        &lt;/Address&gt;
      &lt;Contacts status="Changed"&gt;
        &lt;Contact status="Changed"&gt;
          &lt;ContactId&gt;1&lt;/ContactId&gt;
          &lt;ContactName&gt;Tom&lt;/ContactName&gt;
          &lt;ContactPhone tatus="New"&gt;555-1212&lt;/ContactPhone&gt;
        &lt;/Contact status="New"&gt;
     &lt;/Contacts&gt;
    &lt;/Customer&gt;
  </code></pre>