Copying elements between namespaces in XSLT

Monday, 14 Mar 2005

I recently wrote a transform to downgrade Atom draft-05 feeds (which Liferea won’t grok) to Atom 0.3. Between those versions, the namespace changed from to There are a few elements which have been renamed, and taking care of them is easy enough:

<xsl:template match="atom05:published">
    <xsl:apply-templates select="@*|node()"/>

But there are a few too many elements which have not changed – other than that their namespace is now different. What to do when you don’t want to write heaps of repetitious rules which instantiate the element matched in the old namespace as the same thing in the new namespace? Actually, after a bit of thought, it turned out that it’s very simple:

<xsl:template match="atom05:*|atom05:@*">
  <xsl:element name="{ local-name( . ) }">
    <xsl:apply-templates select="@*|node()"/>

The curious can look at the whole thing.