Re: [xsl] How to remove the automatically generated empty namespace by xsl

Subject: Re: [xsl] How to remove the automatically generated empty namespace by xsl
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 14 Apr 2006 14:13:29 -0400
At 2006-04-14 20:50 +0530, Ramakant Akhairamka wrote:
when i try to use <xsl:element .. /> in main template it gets generated fine.
But when i call another template from this one and then use <xsl:element name="abc />, it generates <abc xmlns=""> .
...
<xsl:template match="/">
<Tag1 xmlns="http://www.abc.com/wahtever";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";


xsi:schemaLocation="http://www.abc.com/wahtever myschema.xsd">
                     <xsl:element name="abc" />

Note in the above how you have a default namespace in scope.


    <xsl:template name="tem1">
        <xsl:element name="abc" />

But above, you not have a default namespace in scope.


<Tag1 xmlns:a="http://www.abcd.com/abCD"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns="http://www.abc.com/wahtever"; xsi:schemaLocation="http://www.abc.com/wahtever myschema.xsd">
<abc/>
<abc xmlns=""/>

So the above results are expected.


If you need the <abc/> to be in the same namespace, then move the xmlns="http://www.abc.com/wahtever"; declaration to the stylesheet document element.

Chapter and verse of XSLT 1.0 7.1.2 reads:

"If the namespace attribute is not present then the QName is expanded into an expanded-name using the namespace declarations in effect for the xsl:element element, including any default namespace declaration."

I hope this helps.

. . . . . . . . . . . . Ken

--
Registration open for XSLT/XSL-FO training: Wash.,DC 2006-06-12/16
Also for XML/XSLT/XSL-FO training:Birmingham,England 2006-05-22/25
Also for XSLT/XSL-FO training:    Copenhagen,Denmark 2006-05-08/11
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread