|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: possible to use copy-of without namespace
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. 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>
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








