The copy-namespaces="no" attribute does not delete all namespace nodes - as specified in the XSLT 2.0 specification
>
If it takes the value no, then none of the namespace nodes is copied: however, the namespace nodes will still be created in the result tree, as the namespace fixing process requires: see 5.7.3 Correcting the namespace. This attribute affects all elements copied by this statement: both elements selected directly by the select statement and elements that are descendants of the nodes selected by the select statement.
Here is an example of how to get rid of all (optional) namespace nodes :
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="*"> <xsl:element name="{local-name()}"> <xsl:apply-templates select="node()|@*"/> </xsl:element> </xsl:template> <xsl:template match="@*"> <xsl:attribute name="{local-name()}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template> </xsl:stylesheet>
When this general conversion is applied to this XML document:
<x:nums xmlns:x="my:x"> <x:num>01</x:num> <x:num>02</x:num> <x:num>03</x:num> <x:num>04</x:num> <x:num>05</x:num> <x:num>06</x:num> <x:num>07</x:num> <x:num>08</x:num> <x:num>09</x:num> <x:num>10</x:num> </x:nums>
the desired, correct result is output:
<nums> <num>01</num> <num>02</num> <num>03</num> <num>04</num> <num>05</num> <num>06</num> <num>07</num> <num>08</num> <num>09</num> <num>10</num> </nums>
Please note :
The conversion is not specific to XSLT-2.0 and can also be used with XSLT 1.0.
Removing all nodes in the namespace is usually an unsafe process, because nodes from different namespaces are placed in "no namespace." In this process, some attributes may be lost, and the process is usually not reversible (not 1: 1).
source share