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

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
xml namespace removal
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

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.