我正在使用xsl中的copy-of元素将一些xml打印到客户端,但是xslt将转义的xml字符输出到输出中,例如。
如果正在转换的xml是
< one attr =“http://one.com/page?param1=value1&param2=value2”>
<儿童>文字及LT; /儿童>
< /一个>
如果我使用副本输出此节点< xsl:copy-of select“。”>< />
输出转换“& amp;”在属性 attr 中只是“&”这会导致客户端上的xml解析错误。
如何在输出xml时保留转义的xml字符
提前致谢。
最诚挚的问候,
凯沙夫
答案 0 :(得分:2)
我无法重现这个问题。提供完整的样式表和您的处理器。 此
<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>
返回:
<one attr="http://one.com/page?param1=value1&param2=value2">
<child>text</child>
</one>
而且:
<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>
返回:
<one attr="http://one.com/page?param1=value1&param2=value2"> <child>text</child> </one>
答案 1 :(得分:1)
如果您使用<xsl:output method="xml"/>
,则XSLT处理器必须生成格式良好的XML文档(或片段)。
不生成此类表示使用过的XSLT处理器中存在错误,您需要将其报告给开发人员并要求修复或解决方法。