[xslt] Can anyone help with this?



I have this xsl document "test.xsl"

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
       xmlns="http://www.w3.org/1999/xhtml";>
   <xsl:output method="xml" indent="yes"
       doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
       doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

<xsl:template match="/base">
<html><head>
	<title><xsl:value-of select="title"/></title>
</head><body>

<!-- This almost works but creates poor namespace issues -->
<xsl:copy-of select="body/*"></xsl:copy-of>

</body>

</html>
</xsl:template>
</xsl:stylesheet>

And this xml document "test.xml"

<?xml version="1.0"?>
<base>
<title>Test Title</title>
<body>
<p>Test Paragraph</p>
</body>
</base>

And when I apply the transformation I get

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <title>Test Title</title>
 </head>
 <body>
   <p xmlns="">Test Paragraph</p>
 </body>
</html>

But if you notice this leaves ugly little xmlns="" in the document.
How do I get rid of these? I can't seem to figure it out. Basically I
want to be able to recursively copy a chunk of elements into my xhtml
document and be able to use the proper namespace while inserting them.

Nathan Bullock

ps. This is the python file I am using to do the conversion:

import libxml2
import libxslt

def transform(str_xml, str_xsl, out):
   styledoc = libxml2.parseFile(str_xsl)
   style = libxslt.parseStylesheetDoc(styledoc)
   doc = libxml2.parseFile(str_xml)
   result = style.applyStylesheet(doc, None)
   style.saveResultToFilename(out, result, 0)
   style.freeStylesheet()
   doc.freeDoc()
   result.freeDoc()

transform("test.xml", "test.xsl", "out1.html")



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]