Re: [xsl] getting rid of namespaces

Subject: Re: [xsl] getting rid of namespaces
From: "Manfred Staudinger" <manfred.staudinger@xxxxxxxxx>
Date: Mon, 30 Jul 2007 00:52:35 +0200
I'm not sure what you mean by "get rid" of the namespace. If you only
want it to appear at the html element, then you may simply specify it
in the stylesheet for the default namespace:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns="http://www.w3.org/1999/xhtml";
   xmlns:html="http://www.w3.org/1999/xhtml"; version="2.0"
exclude-result-prefixes="#all">

Manfred

On 30/07/07, David J Birnbaum <djbpitt+xml@xxxxxxxx> wrote:
> Dear XSL List,
>
> I'm trying to get rid of a pesky namespace declaration, and I've tried
> to follow the rules (as I ... er ... understand them), but without
> success. Can someone please advise me on where my blind spot lies?
> Here's a sample XML document instance:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
>     <p>A paragraph in no namespace</p>
>     <html xmlns="http://www.w3.org/1999/xhtml";>
>         <head>
>             <title>Title in html namespace</title>
>         </head>
>         <body>
>             <p>A paragraph in the html namespace</p>
>         </body>
>     </html>
> </root>
>
> Here's the XSLT:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>     xmlns:html="http://www.w3.org/1999/xhtml"; version="2.0"
> exclude-result-prefixes="#all">
>     <xsl:template match="/">
>         <html>
>             <head>
>                 <title>Test of removing namespaces</title>
>             </head>
>             <body>
>                 <xsl:apply-templates/>
>             </body>
>         </html>
>     </xsl:template>
>     <xsl:template match="p">
>         <p>
>             <xsl:apply-templates/>
>         </p>
>     </xsl:template>
>     <xsl:template match="html:html/html:body/html:*">
>         <xsl:copy-of select="." copy-namespaces="no"/>
>     </xsl:template>
>     <xsl:template match="html:html/html:head"/>
> </xsl:stylesheet>
>
> I specify exclude-result-prefixes="#all" on the <xsl:stylesheet> node
> and I specify copy-namespaces="no" on the <xsl:copy-of> instruction that
> copies all elements in the body the html document that is embedded in my
> XML source. The first of these strategies makes the namespace
> declaration on the paragraph in no namespace go away (so far, so good),
> but the second does not suppress the unwanted namespace declaration on
> the embedded <html:p>. Here's the output of a Saxon 8.9.0.4J
> transformation (I've edited out some unwanted white space):
>
> <html>
>    <head>
>       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
>       <title>Test of removing namespaces</title>
>    </head>
>    <body>
>         <p>A paragraph in no namespace</p>
>         <p xmlns="http://www.w3.org/1999/xhtml";>A paragraph in the html
> namespace</p>
>    </body>
> </html>
>
> What should I be doing to get rid of the xhtml namespace declaration?
>
> Thanks!
>
> Best,
>
> David
> djbpitt+xml@xxxxxxxx

Current Thread