Skip to content

Instantly share code, notes, and snippets.

@sachin-handiekar
Created September 21, 2011 17:29
Show Gist options
  • Save sachin-handiekar/1232731 to your computer and use it in GitHub Desktop.
Save sachin-handiekar/1232731 to your computer and use it in GitHub Desktop.
Add namespace in root node using XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:vbs="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt">
<xsl:output omit-xml-declaration="yes" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<!-- Just change the match="/*" to match="*" ; if you want to add namespace in all elements -->
<xsl:template match="/*">
<xsl:element name="ns:{local-name()}" namespace="http://www.example.com">
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
@jokr0815
Copy link

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
	<xsl:strip-space elements="*"/>
	<xsl:template match="@*|text()|comment()|processing-instruction()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="/*">
		<xsl:element name="{local-name()}" namespace="urn:yourNamespace">
			<xsl:apply-templates select="@*|node()"/>
		</xsl:element>
	</xsl:template>
	<xsl:template match="*">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment