title: XSLT - Create duplicate nodes from an XML
body: <p>I have a multi level XML, I need to duplicate a set of nodes with a new node using XSLT 1.0 Below is a sample xml.</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;Parent&gt;
     &lt;ChildL1 Childtype="A"&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1&gt;
           &lt;ChildL1L2/&gt;
        &lt;/ChildL1L1&gt;
     &lt;/ChildL1&gt;
     &lt;ChildL1 Childtype="B"&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
     &lt;/ChildL1&gt;
  &lt;/Parent&gt;
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;Parent&gt;
     &lt;ChildL1 Childtype="A"&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1&gt;
           &lt;ChildL1L2/&gt;
        &lt;/ChildL1L1&gt;
     &lt;/ChildL1&gt;
     &lt;ChildL1 Childtype="B"&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
     &lt;/ChildL1&gt;
  &lt;NewNode&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
  &lt;/NewNode&gt;    
  &lt;/Parent&gt;
  </code></pre>
  
  <p>Here the NewNode has the Children nodes of ChildL1 only when Childtype="B". </p>
  
  <p>Thanks in Advance; Let me know if this question is not clear. It is my first time posting this type of question.</p>
  
  <p><strong>Editing to show deeper xml nodes:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;Parent&gt;
     &lt;ChildL1 Childtype="A"&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1&gt;
           &lt;ChildL1L2&gt;
              &lt;ChildL1L3 index="1"/&gt;
              &lt;ChildL1L3 index="2"/&gt;
              &lt;ChildL1L3 index="3"/&gt;
           &lt;/ChildL1L2&gt;
        &lt;/ChildL1L1&gt;
     &lt;/ChildL1&gt;
     &lt;ChildL1 Childtype="B"&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
     &lt;/ChildL1&gt;
  &lt;/Parent&gt;
  </code></pre>
  
  <p><strong>desired output(pick Parent/ChildL1/ChildL1L1/ChildL1L2/ChildL1L3 where ChildL1/Childtype='A')</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;Parent&gt;
     &lt;ChildL1 Childtype="A"&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1&gt;
           &lt;ChildL1L2&gt;
              &lt;ChildL1L3 index="1"/&gt;
              &lt;ChildL1L3 index="2"/&gt;
              &lt;ChildL1L3 index="3"/&gt;
           &lt;/ChildL1L2&gt;
        &lt;/ChildL1L1&gt;
     &lt;/ChildL1&gt;
     &lt;ChildL1 Childtype="B"&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
        &lt;ChildL1L1/&gt;
     &lt;/ChildL1&gt;
  &lt;NewNode&gt;
              &lt;ChildL1L3 index="1"/&gt;
              &lt;ChildL1L3 index="2"/&gt;
              &lt;ChildL1L3 index="3"/&gt;
  &lt;/NewNode&gt;    
  &lt;/Parent&gt;
  </code></pre>