title: Add a root node and child to root node to XML using XSLT as well as output transformed xml
body: <p>I am trying to add two nodes to the outside of some xml and output the transformed result to an xml file. I have not been able to get it to work. My xml would be:</p>
  
  <pre><code>&lt;message&gt;
      &lt;!-- ...other nodes and elements in here, not always consistent --&gt;
  &lt;/message&gt;
  </code></pre>
  
  <p>(EDIT)Expected XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;rootNode&gt;
      &lt;submessage&gt;
          &lt;message&gt;
             &lt;!-- ...other nodes and elements in here, not always consistent --&gt;
          &lt;/message&gt;
      &lt;/submessage&gt;
  &lt;/rootNode&gt;
  </code></pre>
  
  <p>Below is the xsl that I have tried but does not seem to work. Any ideas on what I should do to add the two nodes 'rootNode' and 'submessage' and output the results?</p>
  
  <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;    
      &lt;xsl:output indent="yes" method="xml" /&gt;
      &lt;xsl:variable name="root" select="/" /&gt;
      &lt;xsl:variable name="filename" select="'testOutPut'" /&gt;
  
  &lt;xsl:template match="/"&gt;        
      &lt;xsl:result-document href="{$filename}.xml" method="xml"&gt;
          &lt;rootNode&gt;
              &lt;submessage&gt;
                  &lt;message&gt;
                      &lt;xsl:apply-templates select="@*|node()"/&gt;
                  &lt;/message&gt;
              &lt;/submessage&gt;
          &lt;/rootNode&gt;
      &lt;/xsl:result-document&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="DefaultNodes/*"&gt;       
      &lt;xsl:variable name="sourceNode" select="$root/message/*[name() = name(current())]" /&gt;
      &lt;xsl:choose&gt;            
          &lt;xsl:when test="$sourceNode"&gt;
              &lt;xsl:copy-of select="$sourceNode" /&gt;
          &lt;/xsl:when&gt;            
          &lt;xsl:otherwise&gt;
              &lt;xsl:copy-of select="." /&gt;
          &lt;/xsl:otherwise&gt;            
      &lt;/xsl:choose&gt;       
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="/rootNode"&gt;
      &lt;Request xmlns="urn:NameSpace-Definition-Message" 
          xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;             
          &lt;xsl:apply-templates select="@*|node()"/&gt;           
      &lt;/Request&gt;
  &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>EDIT: Also, I am a quite green at xsl transforms, this is my first attempt and am trying to possibly use this as a solution to editing/doctoring some xml before it gets consumed.</p>