title: Changing a namespace value in an XSL transformation?
body: <p>I'm not sure if that is possible, as I'm very new to XSLT and stuff, but maybe some of you could help me here? It's a bit tricky and I haven't found anything like it on the internet:</p>
  
  <p>The problem is that I have an input xml with namespaces declared and all and I only need to make slight changes to it (adding or deleting attributes, or shifting them to other locations). But at the same time, I have to update the namespace references in the document's document tag. So, for example, the input xml might look something like this:</p>
  
  <pre><code>&lt;order
    xmlns="some.url.01"
    xmlns:ns2="some.other.url"
    xmlns:ns3="another.one"
  &gt;
    &lt;orderEntry&gt;
      &lt;orderControl&gt;
        &lt;mandant&gt;test&lt;/mandant&gt;
        &lt;businessUnit&gt;test&lt;/businessUnit&gt;
        &lt;inboundChannel&gt;test&lt;/inboundChannel&gt;
        &lt;timestamp&gt;timestamp&lt;/timestamp&gt;
        &lt;requestedDocuments&gt;
          &lt;ns2:document&gt;orderForm&lt;/ns2:document&gt;
        &lt;/requestedDocuments&gt;
      &lt;/orderControl&gt;
    &lt;/orderEntry&gt;
  &lt;/order&gt;
  </code></pre>
  
  <p>the resulting xml should look like this:</p>
  
  <pre><code>&lt;order
    xmlns="some.url.02"
    xmlns:ns2="some.other.url.02"
    xmlns:ns3="another.one.02"
  &gt;
    &lt;orderEntry&gt;
      &lt;orderControl&gt;
        &lt;mandant&gt;test&lt;/mandant&gt;
        &lt;businessUnit&gt;test&lt;/businessUnit&gt;
        &lt;inboundChannel&gt;test&lt;/inboundChannel&gt;
        &lt;!-- deleted timestamp for example --&gt;
        &lt;requestedDocuments&gt;
          &lt;ns2:document&gt;orderForm&lt;/ns2:document&gt;
        &lt;/requestedDocuments&gt;
      &lt;/orderControl&gt;
    &lt;/orderEntry&gt;
  &lt;/order&gt;
  </code></pre>
  
  <p>but the only thing I get is:</p>
  
  <pre><code>&lt;order
    xmlns="some.url.02"
  &gt;
    &lt;orderEntry&gt;
      &lt;orderControl&gt;
        &lt;mandant&gt;test&lt;/mandant&gt;
        &lt;businessUnit&gt;test&lt;/businessUnit&gt;
        &lt;inboundChannel&gt;test&lt;/inboundChannel&gt;
        &lt;!-- deleted timestamp for example --&gt;
        &lt;requestedDocuments&gt;
          &lt;ns2:document xmlns:ns2="some.other.url.02"&gt;orderForm&lt;/ns2:document&gt;
        &lt;/requestedDocuments&gt;
      &lt;/orderControl&gt;
    &lt;/orderEntry&gt;
  &lt;/order&gt;
  </code></pre>
  
  <p>Now maybe for one or two of you it might not be that big a deal, but I have the restriction that the output document should look one-to-one the same as the input document except for the requested changes (namespace changes and deletion).</p>
  
  <p>My XSLT looks a like this:</p>
  
  <pre><code>&lt;xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="some.url.02"
    xmlns:ns2="some.other.url.02"
    xmlns:ns3="another.one.02"
  &gt;
    &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes" indent="yes"/&gt;
  
    &lt;xsl:strip-space elements="*"/&gt;
  
    &lt;xsl:template match="*"&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test="name(.) != 'timestamp'"&gt;
          &lt;xsl:element name="{node-name(.)}"&gt;
            &lt;xsl:apply-templates select="@*|node()"/&gt;
          &lt;/xsl:element&gt;
        &lt;/xsl:when&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="@*"&gt;
      &lt;xsl:attribute name="{node-name(.)}"&gt;
        &lt;xsl:value-of select="."/&gt;
      &lt;/xsl:attribute&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Can somebody please help? Namespaces are tricky :(</p>
  
  <p>P.S.: Whoever edited my entry: Thanks :)</p>