Re: [xsl] How do I get rid of: xmlns=""

Subject: Re: [xsl] How do I get rid of: xmlns=""
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 03 Jan 2009 12:36:13 -0500
At 2009-01-03 17:29 +0000, Arthur Maloney wrote:
Hello Xsl-list,

In element <url xmlns=""> How do I get rid of xmlns="" ?

By not asking for it as you are in your stylesheet.

  Other than this code works OK
  Using Xslt v 1.0 in Net Framework
  Transfoming Xml to build Google sitemap.xml

Google specifcation - entity-escaped
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="";>

My output after transform is <?xml version="1.0" encoding="utf-8"?> <urlset xmlns="";> <url xmlns=""> <loc></loc> <changefreq>monthly</changefreq> <priority>0.6</priority> </url> ... repeats ~ 8,000 times </urlset>

My Source Xml

Xslt for transform
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl=""; version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" standalone="yes"/>

<xsl:template match="/"> <urlset xmlns="";>

At this point, your default namespace is as desired.

                <xsl:apply-templates select="table/row"/>

<xsl:template match="row">

At this point, your default namespace is the empty URI, thus you are adding an element without a namespace URI to the result tree.

Therefore, the processor is correctly adding the xmlns="" in order to preserve what you have asked for in your stylesheet.

      <loc><xsl:text>http://</xsl:text><xsl:value-of select="./Uri"/>/</loc>

<loc><xsl:text>http://</xsl:text><xsl:value-of select="./Uri"/><xsl:text>/About/about.aspx</xsl:text></loc>

... Repeats for each page in website

And you are repeated asking for elements to be added to the tree that are not in any namespace.

If you put your default namespace declaration at the top of your stylesheet, then all unprefixed literal result elements will be in your default namespace:

<xsl:stylesheet xmlns:xsl="";

<xsl:template match="/">
<xsl:template match="row">

I hope this helps.

. . . . . . . . . . Ken

Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes:
:  Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:
Video overview:
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread