I'm trying to strip the namespace qualifiers from a document, while retaining the document namespace as the default:
<foo:doc xmlns:foo='somenamespace'>
<foo:bar />
</foo:doc>
To
<doc xmlns='somenamespace'>
<bar/>
</doc>
(I know, this is meaningless, but our client doesn't get XML and uses string comparisons to find information in the document.)
I'm using Java's JAXP Transformer API to do my work here. I can strip out all namespace information with this stylesheet, but I want instead to force serialization without prefixes:
<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:xs='http://www.w3.org/2001/XMLSchema'
exclude-result-prefixes='xs'
version='2.0'>
<xsl:output omit-xml-declaration='yes' indent='yes'/>
<xsl:template match='@*|node()'>
<xsl:copy>
<xsl:apply-templates select='@*|node()' />
</xsl:copy>
</xsl:template>
<xsl:template match='*'>
<xsl:element name='{local-name()}'>
<xsl:apply-templates select='@*|node()' />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
How can I do this?