When using the XSLT stylesheet to convert an XML file that contains embedded XHTML (using namespaces) to pure XHTML, I am left with redundant namespace definitions on elements that were originally XHTML. A simple test case:
XML:
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xml" href="fbb.xsl"?>
<foo xmlns="urn:foo:bar:baz" xmlns:html="http://www.w3.org/1999/xhtml">
<bar>
<baz>Some <html:i>example</html:i> text.</baz>
</bar>
</foo>
XSL:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:fbb="urn:foo:bar:baz" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="fbb">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/fbb:foo">
<html>
<head>
<title>Example</title>
</head>
<body>
<p>
<xsl:copy-of select="fbb:bar/fbb:baz/node()"/>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example</title>
</head>
<body>
<p>Some <html:i xmlns="urn:foo:bar:baz" xmlns:html="http://www.w3.org/1999/xhtml">example</html:i> text.</p>
</body>
</html>
Is it possible to prevent the addition of redundant namespaces (and prefix) to the element <i>? (For reference, I use xsltprocwith libxml2-2.7.3and libxslt-1.1.24in Cygwin.)
source
share