At 2003-01-08 05:03 +0100, Thomas Brand wrote:
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?
Yes, by recreating each node found in the source instead of using xsl:copy-of.
But why is it important to you that an unused xmlns attribute is hanging
around?
Your test file is very confusing, though, because your <somechildnode>
construct isn't an element ... it is inside of PCDATA. The element before
is in the ans namespace and the one following isn't ... since you are using
the ans namespace in the result, you will need it.
I took a guess at what you want, though, and an example is below. Perhaps
it is along the lines of what you are looking for. I created a mode that
resynthesizes every element, thus losing the baggage of the attached
namespaces. I'm not sure why you were ignoring the <somenode> element
parent of <somechildnode>, but I mimicked that in my solution.
I hope this helps.
................. Ken
T:\ftemp>type 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/200
1/XMLSchema-instance">
<ans:anode>anodevalue1</ans:anode>
<somenode>
<somechildnode>childvalue1</somechildnode>
</somenode>
<anothernode>
<anotherchildnode>anotherchildvalue1</anotherchildnode>
</anothernode>
</ans:mydoc>
T:\ftemp>type 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:apply-templates mode="copy-no-ns" select="somenode/node()"/>
<xsl:apply-templates mode="copy-no-ns" select="anothernode"/>
</xsl:element>
</xsl:template>
<xsl:template mode="copy-no-ns" match="*">
<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="copy-no-ns"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
T:\ftemp>saxon b.xml a.xsl
<?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>
<anothernode>
<anotherchildnode>anotherchildvalue1</anotherchildnode>
</anothernode>
</result>
T:\ftemp>
--
Upcoming hands-on in-depth North America: February 3- 7,2003
XSLT/XPath and XSL-FO Europe: February 17-21,2003
G. Ken Holman mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6 Definitive XSLT and XPath
ISBN 0-13-140374-5 Definitive XSL-FO
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1 Practical Formatting Using XSL-FO
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list