Best namespace attribute removal strategy?

Subject: Best namespace attribute removal strategy?
From: Max Romantschuk <max@xxxxxxxxxx>
Date: Mon, 21 Jun 2004 09:39:03 +0300
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


-- Max Romantschuk http://max.nma.fi/

Current Thread