Re: [xsl] Best namespace attribute removal strategy?

Subject: Re: [xsl] Best namespace attribute removal strategy?
From: Mayo <mayo@xxxxxxx>
Date: Mon, 21 Jun 2004 00:03:34 -0700
Hi,

check out this
http://www.biglist.com/lists/xsl-list/archives/200405/msg00962.html
thread, it discusses very similar issue, also with few examples in it.

In short, using xsl:copy is not the best way to copy attribubutes over,
as it inserts namespaces related to the element being copied. Something
like 

    <xsl:template match="*[not(namespace-uri())] | xhtml:*">
        <xsl:element name="{local-name(.)}">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>

may work better for you. (This was suggested to me by G. Ken Holman in
the thread I refered to above, and workes great)


Hope this helps a bit,
Mayo Jordanov

On Sun, 2004-06-20 at 23:39, Max Romantschuk wrote:
> Hi,
> 
> I'm new to the list and also somewhat of an XSLT neophyte, so please 
> bear with me as I lay out a question you no doubt have encountered before...
> 
> I am developing a simple content management system for my own needs. I 
> have chosen to use XHTML for data storage, and I use XSLT to grab the 
> body of the document and insert it into the page, adding other stuff 
> using PHP. I'm using PHP's integrated XSLT processing extension.
> 
> --- My XHTML source: ---
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
> "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>
> 
> <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en">
> <head>
>    <title>The Title</title>
> </head>
> 
> <body>
> 
> <h1>A Heading.</h1>
> <p>
>    Lorem ipsum dolor sit amet.
> </p>
> 
> </body>
> </html>
> ------------------------
> 
> 
> --- My XSL stylesheet: ---
> <xsl:stylesheet version = '1.0'
>    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
>    xmlns:xhtml="http://www.w3.org/1999/xhtml";>
> 
> <xsl:output method="xhtml"/>
> 
> <xsl:template match="/">
>    <xsl:copy-of select="xhtml:html/xhtml:body/*"/>
> </xsl:template>
> 
> </xsl:stylesheet>
> --------------------------
> 
> 
> The problem (as you can probably guess by now) is that the XSLT 
> processor is outputting XML namespace attributes for each element, like 
> this:
> 
> --- Output 1: ---
> <h1 xmlns="http://www.w3.org/1999/xhtml";>A Heading.</h1>
> <p xmlns="http://www.w3.org/1999/xhtml";>
>    Lorem ipsum dolor sit amet.
> </p>
> -----------------
> 
> I am aware of the fact that using copy-of _will_ copy the implicit 
> namespace nodes. I also am aware of the fact that 
> exclude-result-prefixes won't work in this case.
> 
> What I would like to know is what would be the most elegant solution to 
> this problem? I have come up with one potential candidate:
> 
> If I modify the stylesheet's copy-of element's select attribute to 
> "xhtml:html/xhtml:body" I will get the following output:
> 
> --- Output 2: ---
> <body xmlns="http://www.w3.org/1999/xhtml";>
> 
> <h1>A Heading.</h1>
> <p>
>    Lorem ipsum dolor sit amet.
> </p>
> 
> </body>
> -----------------
> 
> Using PHP it would be rather trivial to remove the body tag, effectively 
> solving my problem.
> 
> 
> I guess I am just wondering if anyone has a better solution. My desired 
> end result is the source of Output 1 with the xmlns attributes removed.
> 
>    Sincerely,
> Max Romantschuk
> 


Current Thread