title: How to remove SOAP envelope and namespaces with XSLT
body: <p>I have a message</p>
  
  <pre><code>&lt;soapenv:Envelope  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                 xmlns="http://xmlns.oracle.com/policyautomation/hub/12.0/metadata/types"&gt;
      &lt;soapenv:Header/&gt;
      &lt;soapenv:Body&gt;          
      &lt;load-request root="Vehicles" region="en-US" language="en-US" timezone="Etc/GMT"&gt;
          &lt;tables&gt;
              &lt;table name="Vehicles"&gt;
                  &lt;link name="Cars" target="Car" /&gt;
              &lt;/table&gt;
          &lt;/tables&gt;
      &lt;/load-request&gt;
      &lt;/soapenv:Body&gt;
  </code></pre>
  
  <p>
  and I need to make two transformations to it:</p>
  
  <ul>
  <li>remove SOAP Envelope </li>
  <li>transform the contents of the body (<strong>load-request</strong> tag)</li>
  </ul>
  
  <p>I do know how to morph load-request, and tried <a href="https://stackoverflow.com/q/11689719">this solution</a> to remove SOAP, but cannot manage to combine the two and remove the envelope AND transform the body (<strong>load-request</strong>) with single xslt. 
  The result XML should be:</p>
  
  <pre><code>&lt;load-request&gt;
    &lt;root&gt;Vehicles&lt;/root&gt;
    &lt;region&gt;en-US&lt;/region&gt;
    &lt;language&gt;en-US&lt;/language&gt;
    &lt;timezone&gt;Etc/GMT&lt;/timezone&gt;
    &lt;request-context&gt;
      &lt;parameter&gt;
          &lt;name&gt;MyParam1&lt;/name&gt;
          &lt;value&gt;MyValue&lt;/value&gt;
      &lt;/parameter&gt;
    &lt;/request-context&gt;
    &lt;tables&gt;
      &lt;table&gt;
          &lt;name&gt;Vehicles&lt;/name&gt;
          &lt;link&gt;
          &lt;name&gt;Cars&lt;/name&gt;
          &lt;target&gt;Car&lt;/target&gt;
          &lt;/link&gt;
      &lt;/table&gt;
    &lt;/tables&gt;
   &lt;/load-request&gt;
  </code></pre>
  
  <p>The XSLT I used:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" &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;xsl:template match="soapenv:*"&gt;
      &lt;xsl:apply-templates select="@* | node()" /&gt;        
  &lt;/xsl:template&gt;
  &lt;xsl:template match="load-request"&gt;
      &lt;xsl:element name="load-request"&gt;
          &lt;xsl:element name="root"&gt;
              &lt;xsl:value-of select="@root"/&gt;
          &lt;/xsl:element&gt;
          &lt;xsl:element name="region"&gt;
              &lt;xsl:value-of select="@region"/&gt;
          &lt;/xsl:element&gt; 
          &lt;xsl:element name="language"&gt;
              &lt;xsl:value-of select="@language"/&gt;
          &lt;/xsl:element&gt; 
          &lt;xsl:element name="timezone"&gt;
              &lt;xsl:value-of select="@timezone"/&gt;
          &lt;/xsl:element&gt; 
          &lt;xsl:apply-templates select="request-context"/&gt; 
          &lt;xsl:apply-templates select="tables"/&gt; 
      &lt;/xsl:element&gt;        
  &lt;/xsl:template&gt;
  &lt;xsl:template match="request-context"&gt;
      &lt;xsl:element name="request-context"&gt;
          &lt;xsl:for-each select="parameter"&gt;
              &lt;xsl:element name="parameter"&gt;
                  &lt;xsl:element name="name"&gt;
                      &lt;xsl:value-of select="@name"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="value"&gt;
                      &lt;xsl:value-of select="@value"/&gt;
                  &lt;/xsl:element&gt;
              &lt;/xsl:element&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:element&gt;        
  &lt;/xsl:template&gt; 
  &lt;xsl:template match="tables"&gt;
      &lt;xsl:element name="tables"&gt;
          &lt;xsl:for-each select="table"&gt;
              &lt;xsl:element name="table"&gt;
                  &lt;xsl:element name="name"&gt;
                      &lt;xsl:value-of select="@name"/&gt;
                  &lt;/xsl:element&gt; 
                  &lt;xsl:apply-templates select="link"/&gt; 
                  &lt;xsl:for-each select="field"&gt;
                      &lt;xsl:element name="field"&gt;
                          &lt;xsl:element name="name"&gt;
                              &lt;xsl:value-of select="@name"/&gt;
                          &lt;/xsl:element&gt;                   
                      &lt;/xsl:element&gt;
                  &lt;/xsl:for-each&gt;                     
              &lt;/xsl:element&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:element&gt;        
  &lt;/xsl:template&gt; 
  &lt;xsl:template match="link"&gt;
      &lt;xsl:element name="link"&gt; 
          &lt;xsl:element name="name"&gt;
              &lt;xsl:value-of select="@name"/&gt;
          &lt;/xsl:element&gt;
          &lt;xsl:element name="target"&gt;
              &lt;xsl:value-of select="@target"/&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:element&gt;    
  &lt;/xsl:template&gt;
  &lt;xsl:template match="field"&gt;
      &lt;xsl:for-each select="field"&gt;
          &lt;xsl:element name="field"&gt;
              &lt;xsl:element name="name"&gt;
                  &lt;xsl:value-of select="@name"/&gt;
              &lt;/xsl:element&gt;                   
          &lt;/xsl:element&gt;
      &lt;/xsl:for-each&gt;        
   &lt;/xsl:template&gt; 
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Update:
  The answer works for the input. Could you please weigh in on additional tweak:
  In some of my scenarios turning attributes into elements is not enough. The message below</p>
  
  <pre><code>&lt;soapenv:Envelope  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                     xmlns="http://xmlns.oracle.com/policyautomation/hub/12.0/metadata/types"&gt;
  &lt;soapenv:Header/&gt;
  &lt;soapenv:Body&gt;  
      &lt;load-request root="Complains"&gt;
          &lt;field name="Explanation"&gt;
              &lt;text-val name="Text"&gt;The client needs a new toothbrush&lt;/text-val&gt;
          &lt;/field&gt;
      &lt;/load-request&gt;
  &lt;/soapenv:Body&gt;
  </code></pre>
  
  <p></p>
  
  <p>needs to become</p>
  
  <pre><code>&lt;load-request&gt;
     &lt;root&gt;Complains&lt;/root&gt;
     &lt;field&gt;
       &lt;name&gt;Explanation&lt;/name&gt;
       &lt;text-val&gt;
         &lt;name&gt;Text&lt;/name&gt;
         &lt;value&gt;The client needs a new toothbrush&lt;/value&gt;
       &lt;/text-val&gt;
     &lt;/field&gt;
  &lt;/load-request&gt;
  </code></pre>