Whilst transforming XHTML to XHTML with XSL I have a problem with namespaces. Consider as an example input:
<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Test</title></head>
<body>
<p>Remove this</p>
</body>
</html>
Then the following transformation does not work (e.g. does not remove the <p />):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()" name="copy">
<xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
</xsl:template>
<xsl:template match="p" />
</xsl:stylesheet>
But this one does:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:template match="@*|node()" name="copy">
<xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
</xsl:template>
<xsl:template match="xhtml:p" />
</xsl:stylesheet>
My problem and question is: How can I change the XSLT so that I do not have to add prefixes to all the XHTML elements and it still get to match them? From what I tried so far, adding a default namespace like <xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" /> does not achieve this.
Thanks for your help!
This is possible, but I would recommens defining the namespace and using the preefix in referring to elements in this namespace:
Warning:
This technique can be safe only if it is guaranteed that there arent two elements with the same
local-name()but in different namespaces.