[xsl] possible to use copy-of without namespace

Subject: [xsl] possible to use copy-of without namespace
From: Thomas Brand <brand@xxxxxxxxx>
Date: Wed, 08 Jan 2003 05:03:22 +0100

Hello dear reader,


i try to get a 1:1 copy of a tree (using xsl:copy-of) without having the xmlns attribute set in the root node of the result tree.

http://www.w3.org/TR/xslt#copy-of says "copying an element node copies the attribute nodes, namespace nodes and children of the element node as well as the element node itself"

Is there a possibility to avoid the xmlns attribute added?

In the following, i have a simple document b.xml which is transformed with a.xsl:

b.xml ---

<?xml-stylesheet type="text/xsl" href="a.xsl"?>
<ans:mydoc xmlns:ans="http://www.someurl.com/a"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>


<ans:anode>anodevalue1</ans:anode>

        <somenode>
                <![CDATA[
                <somechildnode>childvalue1</somechildnode>
                ]]>
        </somenode>

        <anothernode>
                <anotherchildnode>anotherchildvalue1</anotherchildnode>
        </anothernode>

</ans:mydoc>

a.xsl ---

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:ans="http://www.someurl.com/a"; exclude-result-prefixes="ans"
version="1.0">

<xsl:output method="xml" encoding="iso-8859-1" indent="yes" omit-xml-declaration="no"/>

<xsl:template match="ans:mydoc">
<xsl:element name="result">
<xsl:copy-of select="ans:anode" />
<xsl:value-of select="somenode" disable-output-escaping="yes"/>
<xsl:copy-of select="anothernode"/>
</xsl:element>
</xsl:template>


</xsl:stylesheet>

---

the result is:

<?xml version="1.0" encoding="iso-8859-1"?>
<result>
<ans:anode xmlns:ans="http://www.someurl.com/a"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>anodevalue1</ans:anode>


<somechildnode>childvalue1</somechildnode> <!-- how it should be -->

<anothernode xmlns:ans="http://www.someurl.com/a"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
<anotherchildnode>anotherchildvalue1</anotherchildnode>
</anothernode>
</result>


---

The best result I get is by using <![CDATA[ ]]> in b.xml, and then take it as a string (xsl:value-of), and printing it out with disable-output-escaping="yes". This produces the desired output, but it is not a very good solution.

I think there must be a way to avoid the xmlns attributes to show up..

Any help is very appreciated

Regards,
 Thomas Brand


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread