I was adding a namespace in an element using xsl element namespace attribute. That adds empty namespace in child element in result.
Here is the XSL that adds namespace into element “Auto”
EDIT – short version of my xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="no"/>
<xsl:template match="/">
<xsl:element name="Root">
<xsl:element name="Auto" namespace="http://www.Root.com/XMLSchema/Auto">
<xsl:element name="Applicant">
<xsl:element name="ApplicantType">
<xsl:text>Applicant</xsl:text>
</xsl:element>
</xsl:element>
</xsl:element>
<xsl:element name="Life" namespace="http://www.Root.com/XMLSchema/Auto">
<xsl:element name="Applicant">
<xsl:element name="ApplicantType">
<xsl:text>Applicant</xsl:text>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
Here is the xml that transformed by XSL
<Root>
<Auto xmlns="http://www.Root.com/XMLSchema/Auto">
<Applicant xmlns="">
<ApplicantType>Applicant</ApplicantType>
</Applicant>
</Auto>
</Root>
If you see the Applicant element, transformation added xmlns=””. How to remove this empty namespace?
We can help you better if you show the XSL that’s producing the
ApplicantandApplicantTypeelements. Also, you’re confusing “namespace” and “namespace declaration” in your description of the problem… separating these two might help you grasp the solutionYour XSL code is apparently telling the processor to output the
Applicantelement in no namespace. (And therefore your code is probably wrong… you wantApplicantto be in the sameAutonamespace as its parent.) SinceApplicantwith no prefix would inherit the default namespace declaration from its parent, the output XML must “undeclare” the default namespace declaration, in order to putApplicantin no namespace as you requested.For example, if your XSL code says:
then you are telling XSL to output the
Applicantelement in no namespace, as described above. To fix this, you can repeat the namespace:or as @empo said, you can declare a namespace prefix and use it:
or use a default namespace declaration in the stylesheet (or template):