1
votes

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;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

2
What are you using to do the transform?Flynn1179
i am doing transform to render an HTML but i want to preserve some parts of XML in div tags so that i can process them later if requiredkeshav84
Yes, but what's actually doing the transform? Are you using .NET, Java, or some other platform? Also, once you've done the transform, how are you passing it to the client?Flynn1179

2 Answers

2
votes

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">
<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;param2=value2">
<child>text</child>
</one>

And this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<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;param2=value2"> <child>text</child> </one>
1
votes

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.