11
Sep
Remove XML Namespaces from Transformed XML / XSL

The company that I work for uses a combination of XML and XSL to render website content. Obviously when we start to get into the trickier XSL we need to include some additional XML Namespaces. We do this by adding the namespace and a schema link to the xsl:stylesheet element of the XSL template, as seen below.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:objDotNet="urn:my-scripts">

Although this gives you additional functionality in what you can do with the template, it will append the namespace to each element that is produced as part of the transform.

<div id="test" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:objDotNet="urn:my-scripts">
Content
</div>

After some intense digging on Google I finally found a solution to this problem. All you simply need to do is add another tag to the xsl:stylesheet element.

  • exclude-result-prefixes="msxsl objDotNet"

In the value, add the name of each namespace you want to exclude and separate by a space.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:objDotNet="urn:my-scripts" exclude-result-prefixes="msxsl objDotNet">

The outputted XHTML will now not contain the xml namespaces the elements.


Return to homepage
#1 - KamiloKlasuss wrote:

[Nice post, you saved me a lot of time. Thanks


Comment Published: 10/12/2008 at 7:19 AM


#2 - Dimuthu Nawarathna wrote:

Great!

This worked for me without any issue.


Comment Published: 22/6/2010 at 6:09 PM


#3 - Dimple wrote:

Thanks.


Comment Published: 24/10/2011 at 10:29 PM




Leave a Comment



Hi Guest! Login
AGK Design
© 2012 Ross Miles