Re: [xsl] Unwanted (default) namespaces.

Subject: Re: [xsl] Unwanted (default) namespaces.
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 08 Jul 2002 16:29:22 -0400
At 2002-07-08 12:19 -0600, Edward L. Knoll wrote:
When I made this change, a
   namespace started showing up on an HTML tag which was being
   copied from the XML file to the generated XSL file: <html:br\>
   became <html:br xmlns="http://fedex.com/gnsl"/>.

   Outside of eliminating my use of the default namespace in my
   source XML file, I have discovered no way to circumvent the
   inclusion of this unwanted "xmlns" attribute.  I am using the
   XalanC++ 'Xalan'  and 'testXSLT' XSL processors.

   The source XML file has the following (truncated) content:
   <TagLabels  xmlns:html="http://www.w3.org/1999/xhtml";
               xmlns="http://fedex.com/gnsl"; >
   <Tag name="GNSL_LOCATION_TYPE_CD">LOC<html:br/>TYPE</Tag>
   </TagLabels>

   The XSL stylesheet declaration and the templates which output
   the offending statement follow:

<xsl:stylesheet version="1.0"

   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                    xmlns:html="http://www.w3.org/1999/xhtml";
                    xmlns:gnsl="http://fedex.com/gnsl";
                    exclude-result-prefixes="gnsl html" >

Note that exclude-result-prefixes= only prunes namespace nodes from the stylesheet tree and never from the source tree.


Elements copied from the source tree will always copy ancestral namespace nodes from the source tree to the result tree.

I'm assuming in your "stuff excluded" section you are copying the HTML <br/> from the source tree to the result tree, thus copying the ancestral namespace.

I'm also assuming that you never want any of your GNSL namespace nodes in your HTML, so therefore you must not be doing any copying of those nodes to the result tree.

Therefore, your solution would be to create a template for all of the nodes in the HTML namespace and re-synthesize the HTML elements in the result tree instead of copying them, so you would have something along the lines of the following.

Note how using knoll.xsl the namespaces are copied as you report your problem, but with knoll2.xsl the namespaces do not show up. I added an attribute to an HTML element in your data to show that attribute nodes can be copied.

I hope this helps.

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

p.s. some of the HTML markup in the following example may get eaten by your mailer if it interprets HTML ... looking at the following as simple text illustrates the point I am trying to make.

T:\ftemp>type knoll.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<TagLabels xmlns:html="http://www.w3.org/1999/xhtml";
xmlns="http://fedex.com/gnsl"; >
<Tag name="GNSL_LOCATION_TYPE_CD">LOC<html:br/>TYPE<html:a href="abc"/>END</Tag>
</TagLabels>


T:\ftemp>type knoll.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                    xmlns:html="http://www.w3.org/1999/xhtml";
                    xmlns:gnsl="http://fedex.com/gnsl";
                    exclude-result-prefixes="gnsl html"
                version="1.0">

<xsl:template match="html:*">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>type knoll2.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                    xmlns:html="http://www.w3.org/1999/xhtml";
                    xmlns:gnsl="http://fedex.com/gnsl";
                    exclude-result-prefixes="gnsl html"
                version="1.0">

<xsl:template match="html:*">
  <xsl:element name="{local-name()}">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>xt knoll.xml knoll.xsl
<?xml version="1.0" encoding="utf-8"?>

LOC<html:br xmlns:html="http://www.w3.org/1999/xhtml"; xmlns="http://fedex.com/gnsl"/>TYPE<html:a href="test" xmlns:html="http://www.w3.org/1999/xhtml"; xmlns="http://fedex.com/gnsl"/>END

T:\ftemp>xt knoll.xml knoll2.xsl
<?xml version="1.0" encoding="utf-8"?>

LOC<br/>TYPE<a href="test"/>END

T:\ftemp>


-- Upcoming: 3-days XSLT/XPath and/or 2-days XSL-FO:Sep 30-Oct 4,2002

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 (Fax:-0995)
ISBN 0-13-065196-6                       Definitive XSLT and XPath
ISBN 1-894049-08-X   Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1                Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books (electronic, printed),
articles, training (instructor-live,Internet-live,web/CD,licensed)
Next public training:                 2002-08-05,26,27,09-30,10-03


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread