title: Replacing a Namespace with XSLT
body: <p>Hi I want to <a href="https://stackoverflow.com/questions/2443925/xml-fix-namespace-declaration">work around a 'bug' in certain RSS-feeds</a>, which use an incorrect namespace for the mediaRSS module. I tried to do it by manipulating the DOM programmatically, but using XSLT seems more flexible to me.</p>
  
  <p>Example:</p>
  
  <pre><code>&lt;media:thumbnail xmlns:media="http://search.yahoo.com/mrss" url="http://www.suedkurier.de/storage/pic/dpa/infoline/brennpunkte/4311018_0_merkelxI_24280028_original.large-4-3-800-199-0-3131-2202.jpg" /&gt;
  &lt;media:thumbnail url="http://www.suedkurier.de/storage/pic/dpa/infoline/brennpunkte/4311018_0_merkelxI_24280028_original.large-4-3-800-199-0-3131-2202.jpg" /&gt;
  </code></pre>
  
  <p>Where the namespace must be <code>http://search.yahoo.com/mrss/</code> (mind the slash).</p>
  
  <p>This is my stylesheet:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:template match="//*[namespace-uri()='http://search.yahoo.com/mrss']"&gt;
          &lt;xsl:element name="{local-name()}" namespace="http://search.yahoo.com/mrss/" &gt;
              &lt;xsl:apply-templates select="@*|*|text()" /&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Unfortunately the result of the transformation is an invalid XML and my RSS-Parser (<a href="http://wiki.java.net/bin/view/Javawsxml/Rome" rel="nofollow noreferrer">ROME Library</a>) does not parse the feed anymore:</p>
  
  <pre><code>java.lang.IllegalStateException: Root element not set
      at org.jdom.Document.getRootElement(Document.java:218)
      at com.sun.syndication.io.impl.RSS090Parser.isMyType(RSS090Parser.java:58)
      at com.sun.syndication.io.impl.FeedParsers.getParserFor(FeedParsers.java:72)
      at com.sun.syndication.io.WireFeedInput.build(WireFeedInput.java:273)
      at com.sun.syndication.io.WireFeedInput.build(WireFeedInput.java:251)
      ... 8 more
  </code></pre>
  
  <p>What is wrong with my stylesheet?</p>