Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: "G. Ken Holman" <gkholman@-------------------->
To:
Date: 1/3/2009 5:37:00 PM
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="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
    <loc>http://www.example.com/</loc>
   <lastmod>2005-01-01</lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.8</priority>
   </url>
</urlset>


My output after transform is
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url xmlns="">
    <loc>http://www.superDupperSite.co.uk/</loc>
    <changefreq>monthly</changefreq>
    <priority>0.6</priority>
  </url>
... repeats ~ 8,000 times
</urlset>

My Source Xml
<table>
  <row>
    <websiteId>545</websiteId>
    <modified>2008-08-21</modified>
    <Uri>www.superDupperSite.co.uk</Uri>
  </row>
...
</table>

Xslt for transform

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">

   <xsl:output method="xml" version="1.0" encoding="UTF-8" 
indent="yes" standalone="yes"/>




<xsl:template match="/">
        <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

At this point, your default namespace is as desired.



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

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

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>
      <changefreq>monthly</changefreq>
        <priority>0.6</priority>
   </url>

   <url>

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

      changefreq>monthly</changefreq>

      <priority>0.3</priority>

   </url>



... 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="http://www.w3.org/1999/XSL/Transform"
                version="1.0"
                xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

<xsl:template match="/">
        <urlset>
...
<xsl:template match="row">
   <url>
...

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:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent