title: Inserting several prefixed namespaces in an xml message
body: <p>I'm trying to carry out an xslt transformation but I don't get the results I would like. I need to insert several namespaces with their prefixes into an xml message.</p>
  
  <p>This is the message I get:</p>
  
  <pre><code>  &lt;Operation&gt;        
       &lt;SessionId&gt;?&lt;/SessionId&gt;        
       &lt;appUser&gt;            
          &lt;number1&gt;?&lt;/number1&gt;            
          &lt;field2&gt;?&lt;/field2&gt;            
          &lt;Properties&gt;
             &lt;!--Zero or more repetitions:--&gt;
             &lt;KeyValue&gt;
                &lt;Key&gt;?&lt;/Key&gt;
                &lt;Value&gt;?&lt;/Value&gt;
             &lt;/KeyValue&gt;
          &lt;/Properties&gt;            
          &lt;value3&gt;?&lt;/value3&gt;            
       &lt;/appUser&gt;
    &lt;/Operation&gt;
  </code></pre>
  
  <p>This is the transformation I do:</p>
  
  <pre><code>&lt;xsl:stylesheet version="2.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
   &lt;xsl:output omit-xml-declaration="yes" 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="*"&gt;
    &lt;xsl:element name="ser:{name()}" namespace="http://www.url.com/Services"&gt;
      &lt;xsl:copy-of select="namespace::*"/&gt;
      &lt;xsl:apply-templates select="node()|@*"/&gt;
    &lt;/xsl:element&gt;
   &lt;/xsl:template&gt;
  
   &lt;xsl:template match="*[ancestor::appUser]"&gt;
    &lt;xsl:element name="mp:{name()}" namespace="http://schemas.data.org/myPath"&gt;
      &lt;xsl:copy-of select="namespace::*"/&gt;
      &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:element&gt;
   &lt;/xsl:template&gt;
  
    &lt;xsl:template match="*[ancestor-or-self::KeyValue ]"&gt;
      &lt;xsl:element name="arr:{name()}" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;
      &lt;xsl:copy-of select="namespace::*" /&gt;
        &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>And i get the following:</p>
  
  <pre><code>&lt;ser:Operation xmlns:ser="http://www.url.com/Services"&gt;        
           &lt;ser:SessionId&gt;?&lt;/ser:SessionId&gt;        
           &lt;ser:appUser&gt;            
              &lt;mp:number1 xmlns:mp="http://schemas.data.org/myPath"&gt;?&lt;/mp:number1&gt;            
              &lt;mp:field2 xmlns:mp="http://schemas.data.org/myPath"&gt;?&lt;/mp:field2&gt;            
              &lt;mp:Properties xmlns:mp="http://schemas.data.org/myPath"&gt;
                 &lt;!--Zero or more repetitions:--&gt;
                 &lt;arr:KeyValue xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;
                    &lt;arr:Key&gt;?&lt;/arr:Key&gt;
                    &lt;arr:Value&gt;?&lt;/arr:Value&gt;
                 &lt;/arr:KeyValue&gt;
              &lt;/mp:Properties&gt;            
              &lt;mp:value3 xmlns:mp="http://schemas.data.org/myPath"&gt;?&lt;/mp:value3&gt;            
           &lt;/ser:appUser&gt;
        &lt;/ser:Operation&gt;
  </code></pre>
  
  <p>But I don't like seeing the namespace declaration xmlns:mp="http://schemas.data.org/myPath" in every element.</p>
  
  <p>So, could I modify my xslt to get something like the following?</p>
  
  <pre><code>&lt;ser:Operation xmlns:ser="http://www.url.com/Services" xmlns:mp="http://schemas.data.org/myPath"&gt;        
           &lt;ser:SessionId&gt;?&lt;/ser:SessionId&gt;        
           &lt;ser:appUser&gt;            
              &lt;mp:number1 &gt;?&lt;/mp:number1&gt;            
              &lt;mp:field2&gt;?&lt;/mp:field2&gt;            
              &lt;mp:Properties&gt;
                 &lt;!--Zero or more repetitions:--&gt;
                 &lt;arr:KeyValue xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;
                    &lt;arr:Key&gt;?&lt;/arr:Key&gt;
                    &lt;arr:Value&gt;?&lt;/arr:Value&gt;
                 &lt;/arr:KeyValue&gt;
              &lt;/mp:Properties&gt;            
              &lt;mp:value3&gt;?&lt;/mp:value3&gt;            
           &lt;/ser:appUser&gt;
        &lt;/ser:Operation&gt;
  </code></pre>
  
  <p>Thank you in advance for your help.</p>