You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by ikke ekki <ba...@hotmail.com> on 2003/06/11 16:00:34 UTC

xsl:copy-of with namespaces not working

Can anyone tell me how I should copy an entire subtree to a new XML document 
using Xalan.

My problem

Xml contents:
<IN>
<GRAPH>
<svg:svg xmlns:svg="http://www.w3.org/2000/svg">
<svg:rect x="0mm" y="0mm" width="5mm" height="15mm" style="fill: red"/>
<svg:rect x="5mm" y="0mm" width="5mm" height="12mm" style="fill: green"/>
<svg:rect x="10mm" y="0mm" width="5mm" height="20mm" style="fill: blue"/>
</svg:svg>
</GRAPH>
</IN>

xsl file

<xsl:template match="IN">
<GRAPH>
<xsl:copy-of select="GRAPH/svg:svg" xmlns:svg="http://www.w3.org/2000/svg"/>
</GRAPH>
</xsl:template>

I want this to produce the same output as the input file. Ofcourse I only 
simplified the problem,I don't need an exact copy  afterwards, but a new 
result with some copied stuff.
Using Xalan I get an empty GRAPH node. Using XML spy it is fine.

if I use the following xsl I get an exception: org.w3c.dom.DOMException: 
NAMESPACE_ERR: An attempt is made to create or change an object in a way 
which is incorrect with regard to namespaces.

<xsl:template match="IN">
<GRAPH>
<xsl:copy-of select="GRAPH/svg" xmlns:svg="http://www.w3.org/2000/svg"/>
</GRAPH>
</xsl:template>

If I want to do a value-of then I have to use
<xsl:value-of select="GRAPH/svg/rect/@x" 
xmlns:svg="http://www.w3.org/2000/svg"/>

This is not working in XML spy, there again I need to use the following
<xsl:value-of select="GRAPH/svg:svg/svg:rect/@x" 
xmlns:svg="http://www.w3.org/2000/svg"/>

Can anyone help me producing the exect copy using Xalan? I tried xalan2.4.1 
and 2.5.1 already.
Thank you very much

_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail


Re: xsl:copy-of with namespaces not working

Posted by da...@us.ibm.com.



> Can anyone tell me how I should copy an entire subtree to a new XML
document
> using Xalan.
>
> My problem
>
> Xml contents:
> <IN>
> <GRAPH>
> <svg:svg xmlns:svg="http://www.w3.org/2000/svg">
> <svg:rect x="0mm" y="0mm" width="5mm" height="15mm" style="fill: red"/>
> <svg:rect x="5mm" y="0mm" width="5mm" height="12mm" style="fill: green"/>
> <svg:rect x="10mm" y="0mm" width="5mm" height="20mm" style="fill: blue"/>
> </svg:svg>
> </GRAPH>
> </IN>
>
> xsl file
>
> <xsl:template match="IN">
> <GRAPH>
> <xsl:copy-of select="GRAPH/svg:svg" xmlns:svg="http://www.w3.org/2000/svg
"/>
> </GRAPH>
> </xsl:template>
>
> I want this to produce the same output as the input file. Ofcourse I only

> simplified the problem,I don't need an exact copy  afterwards, but a new
> result with some copied stuff.
> Using Xalan I get an empty GRAPH node. Using XML spy it is fine.

Then XML Spy has a bug.  Modify the match pattern in your template as
follows:

   <xsl:template match="IN">
   <GRAPH>
   <xsl:copy-of select="GRAPH/svg:svg" xmlns:svg="
   http://www.w3.org/2000/svg"/>
   </GRAPH>
   </xsl:template>

Since the svg element in your source file is in the namespace
http://www.w3.org/2000/svg, you must make sure you are matching on the same
namespace.

Dave