Evil solution to the XSLT empty xmlns probem
I’m currently using XSLT, and I’ve come across the dreaded empty xmlns
problem. My XML contains elements that do not have rules in my XSL stylesheet and most XSLT engines append the attribute xmlns=""
when it gets confused about what namespace the element belongs to… I get bitten by this because I do not have an input DTD as the document is not meant to be used as anything but fodder to create XHTML.
Many people even have this problem when using XSLT to transform XHTML into XHTML… the input and output namespaces are the same, and they’re using properly formated and validated XHTML documents (complete with the doctype statement and the xmlns
attribute on the html
element).
Many people just want to force the transforming engine to blindly copy the elements as is over to the new document, and ignore the namespace issue. The below XSL should do this, use wisely.
<xsl:template match="*|@*">
<xsl:element name="{ local-name( . ) }">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
So, now I can go use XHTML in my input and have it spit back out unmolested.
I tried that solution before, it doesn’t want to work right for me, thus what I did above.