title: How to copy one xml data into another after last occurrence of a specific element using xslt
body: <p>I am having two xml files. I want to copy one xml file data into another file under last occurrence of element. Below are the xml I am having :</p>
  
  <pre><code>---------- xml-1---------------
  &lt;?xml version="1.0"?&gt;
  &lt;parent&gt;
  ....
  &lt;form id="1" name="world"/&gt;
   &lt;source id="1" name="abc1"/&gt;
   &lt;source id="2" name="abc2"/&gt;
   &lt;source id="3" name="abc3"/&gt;
   &lt;file id="1" name="xyz"/&gt;
  ....
  &lt;/parent&gt; 
  
  ----------- xml-2--------------
  &lt;?xml version="1.0"?&gt;
  &lt;root&gt;
  &lt;source id="4" data="anything"/&gt;
  &lt;source id="5" data="anything"/&gt;
  &lt;source id="6" data="anything"/&gt;
  &lt;source id="7" data="anything"/&gt;
  &lt;/root&gt;
  
  
  ------------------The desired output I want-----------------
  &lt;?xml version="1.0"?&gt;
  &lt;parent&gt;
  ....
  &lt;source id="1" name="abc1"/&gt;
  &lt;source id="2" name="abc2"/&gt;
  &lt;source id="3" name="abc3"/&gt;
  &lt;source id="4" data="anything"/&gt;
  &lt;source id="5" data="anything"/&gt;
  &lt;source id="6" data="anything"/&gt;
  &lt;source id="7" data="anything"/&gt;
  &lt;file id="1" name="xyz"
  ....
  &lt;/parent&gt; 
  
  
  
  ============== xslt I am using =============
  
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:template match="node()|@*" name="identity"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="node()|@*"/&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="source"&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test="'id=3'"&gt;
            &lt;xsl:call-template name="identity"/&gt;
            &lt;xsl:copy-of select="document('file:///D:/Softwares/JEE    eclipse/JEEworkspace/Migration/TestMigrationWithoutDeletingProject/xml2.xml')/*/*"/&gt;
        &lt;/xsl:when&gt;
      &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <hr>
  
  <p>I am trying to find it out on the basis of id attribute but it is copying xml-2 data after every source element of xml-1 data. Please help me on this.</p>