title: XSLT 1.0 Move of one Segment
body: <p>please tell me, how can i move the Segment "BGM" from "CNT" to "GRP"?</p>
  
  <p>Actually XML:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0"?&gt;
  &lt;SEEDELFOR&gt;
   &lt;AG/&gt;
   &lt;CNT&gt;
    &lt;TRANSMISSION_DATE&gt;20190307&lt;/TRANSMISSION_DATE&gt;
    &lt;TRANSMISSION_TIME&gt;113300&lt;/TRANSMISSION_TIME&gt;      &lt;/INTERCHANGE_CONTROL_NUMBER&gt;
    &lt;/SENDER&gt;
    &lt;/SENDER_QUALIFIER&gt;
    &lt;/RECEIVER&gt;
    &lt;/RECEIVER_QUALIFIER&gt;
    &lt;/SYNTAX_IDENTIFIER&gt;
    &lt;/SYNTAX_VERSION&gt;
    &lt;BGM&gt;227&lt;/BGM&gt;
    &lt;GRP&gt;   
     &lt;/IDENTIFIER_BY&gt;
     &lt;/IDENTIFIER_SU&gt;
     &lt;/DATE_4&gt;
     &lt;/REF_ON&gt;       
    &lt;/GRP&gt;
   &lt;/CNT&gt;
  &lt;/SEEDELFOR&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Correct output of my XML Should be:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0"?&gt;
  &lt;SEEDELFOR&gt;
   &lt;AG/&gt;
   &lt;CNT&gt;
    &lt;TRANSMISSION_DATE&gt;20190307&lt;/TRANSMISSION_DATE&gt;
    &lt;TRANSMISSION_TIME&gt;113300&lt;/TRANSMISSION_TIME&gt;
    &lt;SENDER&gt;&lt;/SENDER&gt;
    &lt;/SENDER_QUALIFIER&gt;
    &lt;/RECEIVER&gt;
    &lt;/RECEIVER_QUALIFIER&gt;
    &lt;/SYNTAX_IDENTIFIER&gt;
    &lt;/SYNTAX_VERSION&gt;  
    &lt;GRP&gt;
        &lt;BGM&gt;227&lt;/BGM&gt;             
    &lt;/GRP&gt;
   &lt;/CNT&gt;
  &lt;/SEEDELFOR&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here´s my XSLT: I tried to copy, but i think it´s better to move the segment?</p>
  
  <p>Edit: Thats my full XSLT: Maybe i have to cominate with other copy segments?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"&gt;
      &lt;xsl:output method="xml" indent="yes"/&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;!--Copy all of CNT != BGM--&gt;    
  &lt;xsl:template match="CNT"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="*[local-name()!='BGM']" /&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  
  &lt;!--copy BGM from CNT to GRP--&gt;
  &lt;xsl:template match="GRP"&gt;
      &lt;xsl:element name="GRP"&gt;
          &lt;xsl:apply-templates /&gt;
          &lt;xsl:copy-of select="../BGM" /&gt;
      &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  
  &lt;!--copy the data from ADD/CONTACT with Qualifier EM to GRP, so it can be used in the mapping to set EMAIL from Customer--&gt;
  &lt;xsl:template match="GRP"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:for-each select ="./ADD/CONTACT"&gt;
           &lt;xsl:if test="./QUALIFIER='EM'"&gt;          
    &lt;CONTACT_EMAIL&gt;
    &lt;xsl:value-of select="NUMBER"/&gt;      
    &lt;/CONTACT_EMAIL&gt;
         &lt;/xsl:if&gt;
           &lt;xsl:if test="./QUALIFIER='TE'"&gt;          
    &lt;CONTACT_TEL&gt;
    &lt;xsl:value-of select="NUMBER"/&gt;      
    &lt;/CONTACT_TEL&gt;
         &lt;/xsl:if&gt;
           &lt;xsl:if test="./QUALIFIER='FX'"&gt;          
    &lt;CONTACT_FAX&gt;
    &lt;xsl:value-of select="NUMBER"/&gt;      
    &lt;/CONTACT_FAX&gt;
         &lt;/xsl:if&gt;
        &lt;/xsl:for-each&gt;
      &lt;!--copy all other nodes--&gt;
        &lt;xsl:apply-templates select="@* | node()"/&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
    
    &lt;!--delete IC node--&gt;
    &lt;xsl:template match="IC" /&gt;
    
    &lt;!--delete FILTER_SET node--&gt;
    &lt;xsl:template match="FILTER_SET" /&gt;
   
    &lt;!--delete SEE_AG node--&gt;
    &lt;xsl:template match="SEE_AG" /&gt;
  
    &lt;!--delete ME node--&gt;
    &lt;xsl:template match="ME" /&gt;
    
      &lt;!--delete ADD node--&gt;
    &lt;xsl:template match="ADD" /&gt;
    
    &lt;!-- delete segment (ADD) with specified QUALIFER (SU)  --&gt;
    &lt;xsl:template match="ADD[QUALIFIER='SU']"/&gt; 
    
    &lt;!--delete TRANSPORT_DETAILS node--&gt;
    &lt;xsl:template match="TRANSPORT_DETAILS" /&gt;
    
    &lt;!--delete PACKAGE_DETAILS node--&gt;
    &lt;xsl:template match="PACKAGE_DETAILS" /&gt;
    
    &lt;!--delete AMOUNT_DETAILS node--&gt;
    &lt;xsl:template match="AMOUNT_DETAILS" /&gt;
    
      &lt;!--delete IC node--&gt;
    &lt;xsl:template match="CONTACT" /&gt;
    
     &lt;!-- delete empty nodes --&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;xsl:template match="*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/&gt;
  &lt;!-- delete empty nodes --&gt;  
    
  &lt;/xsl:stylesheet&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thanks for your help.</p>
  
  <p>Best regards
  Julian</p>