title: XSLT to copy elements from source into CDATA section
body: <p>I am transforming a simple SOAP XML message into a more extended SOAP XML message. I got it almost to work, but I can't manage to fix the last 2 issues. My issues are:</p>
  
  <ol>
  <li>All elements after the element  should be in a CDATA section. I tried to use 'cdata-section-elements', but can't get it working.</li>
  <li>Element  should look like this </li>
  </ol>
  
  <p>My Source XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;SOAP-ENV:Header/&gt;
    &lt;SOAP-ENV:Body&gt;
      &lt;test&gt;
        &lt;element1&gt;123&lt;/element1&gt;
        &lt;element2&gt;123&lt;/element2&gt;
      &lt;/test&gt;
    &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>My XSLT:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" exclude-result-prefixes="fn xs SOAP-ENV"&gt;
  &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" /&gt;
  
  &lt;!-- Special rule to match the document root only --&gt;
  &lt;xsl:template match="/*"&gt;
      &lt;s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"&gt;
          &lt;xsl:namespace name="a" select="'http://www.w3.org/2005/08/addressing'"/&gt;
          &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/s:Envelope&gt;
  &lt;/xsl:template&gt;
  
  &lt;!-- Expand soap header --&gt;
  &lt;xsl:template match="SOAP-ENV:Header"&gt;
      &lt;xsl:element name="s:{local-name()}" namespace="http://www.w3.org/2003/05/soap-envelope"&gt;
          &lt;xsl:element name="a:Action" namespace="http://www.w3.org/2005/08/addressing"&gt;
              &lt;xsl:attribute name="s:mustUnderstand" namespace="http://www.w3.org/2003/05/soap-envelope"&gt;1&lt;/xsl:attribute&gt;
              &lt;xsl:text&gt;http://www.ortec.com/CAIS/IApplicationIntegrationService/SendMessage&lt;/xsl:text&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  
  &lt;!-- Change soap body --&gt;
  &lt;xsl:template match="SOAP-ENV:Body"&gt;
      &lt;xsl:element name="s:{local-name()}" namespace="http://www.w3.org/2003/05/soap-envelope"&gt;
          &lt;xsl:element name="cais:SendMessage" namespace="http://www.ortec.com/CAIS"&gt;
              &lt;xsl:element name="cais:message" namespace="http://www.ortec.com/CAIS"&gt;
                  &lt;!-- copy the rest --&gt;
                  &lt;xsl:apply-templates select="child::node()"/&gt;
              &lt;/xsl:element&gt;
              &lt;xsl:element name="cais:commandName" namespace="http://www.ortec.com/CAIS"&gt;Import&lt;/xsl:element&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  
  &lt;!-- template for the copy of the rest --&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:stylesheet&gt;
  </code></pre>
  
  <p>The WRONG output I receive now with this XSLT:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope"&gt;
    &lt;s:Header&gt;
      &lt;a:Action s:mustUnderstand="1"&gt;http://www.ortec.com/CAIS/IApplicationIntegrationService/SendMessage&lt;/a:Action&gt;
    &lt;/s:Header&gt;
    &lt;s:Body&gt;
      &lt;cais:SendMessage xmlns:cais="http://www.ortec.com/CAIS"&gt;
        &lt;cais:message&gt;
          &lt;test xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
            &lt;element1&gt;123&lt;/element1&gt;
            &lt;element2&gt;123&lt;/element2&gt;
          &lt;/test&gt;
        &lt;/cais:message&gt;
        &lt;cais:commandName&gt;Import&lt;/cais:commandName&gt;
      &lt;/cais:SendMessage&gt;
    &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>My DESIRED output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope"&gt;
    &lt;s:Header&gt;
      &lt;a:Action s:mustUnderstand="1"&gt;http://www.ortec.com/CAIS/IApplicationIntegrationService/SendMessage&lt;/a:Action&gt;
    &lt;/s:Header&gt;
    &lt;s:Body&gt;
      &lt;cais:SendMessage xmlns:cais="http://www.ortec.com/CAIS"&gt;
        &lt;cais:message&gt;
          &lt;![CDATA[
          &lt;test&gt;
            &lt;element1&gt;123&lt;/element1&gt;
            &lt;element2&gt;123&lt;/element2&gt;
          &lt;/test&gt;
          ]]&gt;
        &lt;/cais:message&gt;
        &lt;cais:commandName&gt;Import&lt;/cais:commandName&gt;
      &lt;/cais:SendMessage&gt;
    &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>