views:

56

answers:

2

Hi,

I am using the copy-of element in xsl to print some xml to client, but the xslt outputs the unescapes the escaped xml characters to the output e.g.

if the xml being transformed is

<one attr="http://one.com/page?param1=value1&amp;amp;param2=value2">
   <child>text</child>
</one>

and if i use the copy-of to output this node <xsl:copy-of select"."></>

the output converts the "&amp;" in attribute attr to just "&" which causes xml parse error on client.

how can i preserve the escaped xml characters when outputting the xml

Thanks in advance.

Best Regards,

Keshav

+1  A: 

I can't reproduce the problem. Provided full stylesheet and your processor. This

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
<xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:template match="/*">
            <xsl:copy-of select="."/>
    </xsl:template>
</xsl:stylesheet>

Return:

<one attr="http://one.com/page?param1=value1&amp;amp;param2=value2"&gt;
<child>text</child>
</one>

And this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
<xsl:output method="html" omit-xml-declaration="yes"/>
    <xsl:template match="/*">
            <xsl:copy-of select="."/>
    </xsl:template>
</xsl:stylesheet>

Return:

<one attr="http://one.com/page?param1=value1&amp;amp;param2=value2"&gt; <child>text</child> </one>
Alejandro
+1  A: 

In case you use <xsl:output method="xml"/> the XSLT processor must produce well-formed XML document (or fragment).

Not producing such indicates a bug in the used XSLT processor and you need to report it to its developers and ask for a fix or workaround.

Dimitre Novatchev
hithanks for the reply, yes you are right it should be a problem with the xsl processor in such case. but it turned out that this happened because of some internal processing we were doing.
keshav.veerapaneni