Here is my (simplified for this scenario) XML:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet href="test_1.xsl" type="text/xsl"?> <doc xmlns="http://www.foo.org"> <div> <title>Mr. Title</title> <paragraph>This is one paragraph. </paragraph> <paragraph>Another paragraph. </paragraph> </div> </doc>
And here is my XSLT:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="http://www.foo.org"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="foo:doc"> <xsl:element name="newdoc" namespace="http://www/w3.org/1999/xhtml"> <xsl:apply-templates/> </xsl:element> </xsl:template> <xsl:template match="foo:div"> <segment title="{foo:title}"> <xsl:apply-templates/> </segment> </xsl:template> <xsl:template match="foo:title"> <xsl:element name="h2"> <xsl:apply-templates/> </xsl:element> </xsl:template> <xsl:template match="foo:paragraph"> <xsl:element name="p"> <xsl:apply-templates/> </xsl:element> </xsl:template> </xsl:stylesheet>
The output produces the following:
<newdoc xmlns="http://www/w3.org/1999/xhtml"> <segment xmlns="" title="Mr. Title"> <h2>Mr. Title</h2> <p>This is one paragraph. </p> <p>Another paragraph. </p> </segment> </newdoc>
which is fine, except for xmlns = "" in a segment element, which does not appear to define a namespace for itself and all its children. How can I make it not add this?
Sidenote: I also tried converting the first node with
<xsl:template match="mydoc:doc"> <html xmlns="http://www/w3.org/1999/xhtml"> <xsl:apply-templates/> </html> </xsl:template>
but it produces the same effect.
Thanks, helpful people!
Zori
source share