Replace NameSpaces in XSLT

You may come across a situation where you want to replace one set of namespaces to another set. A typical example is that you have a pass-through OSB Service whose proxy is based on your Project’s namespaces and the underlying service is based on the out-of-the-box service namespaces.

In such cases, the following XSLT will search-replace the namespaces

For example, if your input xml looks like


..
..
..

..
..

..
..

..

..

and the response has to have a different set of namespaces,


..
..
..

..
..

..
..

..

..

The following XSLT works

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myns1="http://www.w3.org/TR/html4/1"
xmlns:myns2="http://www.w3.org/TR/html4/2"
xmlns:myns3="http://www.w3.org/TR/html4/3"
xmlns:myns4="http://www.w3.org/TR/html4/4"
xmlns:myns5="http://www.w3schools.com/furniture"
xmlns:ns1="http://www.w3.org/TR/html4/1"
xmlns:ns2="http://www.w3.org/TR/html4/2"
xmlns:ns3="http://www.w3.org/TR/html4/3"
xmlns:ns4="http://www.w3.org/TR/html4/4"
xmlns:ns5="http://www.w3schools.com/furniture">

<xsl:template match="*">





<xsl:template match="ns2:*">
<xsl:element name="myns2:{local-name()}">




<xsl:template match="ns3:*">
<xsl:element name="myns3:{local-name()}">




<xsl:template match="ns4:*">
<xsl:element name="myns4:{local-name()}">



<xsl:template match="ns5:*">
<xsl:element name="myns5:{local-name()}">


This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s