[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Best namespace attribute removal strategy?

Subject: Re: Best namespace attribute removal strategy?
From: Mayo <mayo@xxxxxxx>
Date: Mon, 21 Jun 2004 00:03:34 -0700
xsl remove namespace
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.