title: Moving nodes down using XSLT
body: <p>After puting my question up here, I managed to move a node up (<a href="https://stackoverflow.com/questions/26121407/moving-nodes-up-using-xslt">Moving nodes up using XSLT</a>). After this I thought I understood it so I tried the opposite to move a node down. Didn't work. This is what I did:</p>
  
  <p>My input data is called DEBTORS.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd"&gt;
  &lt;Accounts&gt;
   &lt;Account code="                 001" status="A" type="C"&gt;
    &lt;Name&gt;Name&lt;/Name&gt;
    &lt;Contacts&gt;
     &lt;Contact default="1" gender="M" status="A"&gt;
      &lt;Note&gt;Patient: 1&lt;/Note&gt;
      &lt;FirstName&gt;&lt;/FirstName&gt;
      &lt;Addresses&gt;
       &lt;Address type="D" desc=""&gt;
        &lt;AddressLine1&gt;Street&lt;/AddressLine1&gt;
        &lt;AddressLine2&gt;&lt;/AddressLine2&gt;
        &lt;AddressLine3&gt;&lt;/AddressLine3&gt;
        &lt;PostalCode&gt;0000 AA&lt;/PostalCode&gt;
        &lt;City&gt;&amp;apos;City&lt;/City&gt;
        &lt;Country code="NL"/&gt;
        &lt;Phone&gt;&lt;/Phone&gt;
        &lt;Fax&gt;&lt;/Fax&gt;
       &lt;/Address&gt;
       &lt;/Addresses&gt;
      &lt;Language code="NL"/&gt;
      &lt;JobDescription&gt;--&lt;/JobDescription&gt;
      &lt;Phone&gt;&lt;/Phone&gt;
      &lt;PhoneExt&gt;&lt;/PhoneExt&gt;
      &lt;Fax&gt;&lt;/Fax&gt;
      &lt;Mobile&gt;&lt;/Mobile&gt;
      &lt;Email&gt;&lt;/Email&gt;
      &lt;WebAccess&gt;0&lt;/WebAccess&gt;
       &lt;/Contact&gt;
    &lt;/Contacts&gt;
      &lt;Debtor number="   1" code="                 1"&gt;
     &lt;Currency code="EUR"/&gt;
     &lt;/Debtor&gt;
     &lt;/Account&gt;
  &lt;/Accounts&gt;
  &lt;/eExact&gt;
  </code></pre>
  
  <p>My XSL called Test2.xsl</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
  &lt;!-- Indentation in XSL --&gt;
  &lt;xsl:output method="xml" version="1.0" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/&gt;
  
  &lt;!-- Removing blank lines in XSL --&gt;
  &lt;xsl:strip-space  elements="*"/&gt;
  
  &lt;!-- Identity rule --&gt;
      &lt;xsl:template match="@*|node()"&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select="@*|node()" /&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
  
  &lt;!-- special rules ... --&gt;
      &lt;xsl:template match="Account"&gt;
          &lt;xsl:copy&gt;
            &lt;!-- exclude Name --&gt;
            &lt;xsl:apply-templates select="@* | node()[not(self::Name)]"/&gt;
          &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="Contacts"&gt;
      &lt;xsl:copy&gt;
          &lt;!-- include Name --&gt;
          &lt;xsl:apply-templates select="@* | node() | Contact/Name"/&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p><strong>Wanted</strong> output:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd"&gt;
  &lt;Accounts&gt;
   &lt;Account code="                 001" status="A" type="C"&gt;
    &lt;Contacts&gt;
     &lt;Contact default="1" gender="M" status="A"&gt;
      &lt;Name&gt;Name&lt;/Name&gt;
      &lt;Note&gt;Patient: 1&lt;/Note&gt;
      &lt;FirstName&gt;&lt;/FirstName&gt;
      &lt;Addresses&gt;
       &lt;Address type="D" desc=""&gt;
        &lt;AddressLine1&gt;Street&lt;/AddressLine1&gt;
        &lt;AddressLine2&gt;&lt;/AddressLine2&gt;
        &lt;AddressLine3&gt;&lt;/AddressLine3&gt;
        &lt;PostalCode&gt;0000 AA&lt;/PostalCode&gt;
        &lt;City&gt;&amp;apos;City&lt;/City&gt;
        &lt;Country code="NL"/&gt;
        &lt;Phone&gt;&lt;/Phone&gt;
        &lt;Fax&gt;&lt;/Fax&gt;
       &lt;/Address&gt;
       &lt;/Addresses&gt;
      &lt;Language code="NL"/&gt;
      &lt;JobDescription&gt;--&lt;/JobDescription&gt;
      &lt;Phone&gt;&lt;/Phone&gt;
      &lt;PhoneExt&gt;&lt;/PhoneExt&gt;
      &lt;Fax&gt;&lt;/Fax&gt;
      &lt;Mobile&gt;&lt;/Mobile&gt;
      &lt;Email&gt;&lt;/Email&gt;
      &lt;WebAccess&gt;0&lt;/WebAccess&gt;
       &lt;/Contact&gt;
    &lt;/Contacts&gt;
      &lt;Debtor number="   1" code="                 1"&gt;
     &lt;Currency code="EUR"/&gt;
     &lt;/Debtor&gt;
     &lt;/Account&gt;
  &lt;/Accounts&gt;
  &lt;/eExact&gt;
  </code></pre>
  
  <p>My problem is that with my XSL the node "Name" is deleted, but doesn't come back as a child of contact. Hope someone will help me?</p>