我们想使用xslt介体来转换其他的xml。 我们有这个肥皂消息。
<?xml version = "1.0" encoding="ISO-8859-1"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.es">
<soapenv:Header/>
<soapenv:Body>
<ws:reception>
<ws:xml>
<message>Data messsage to send</message>
</ws:xml>
</ws:reception>
</soapenv:Body>
</soapenv:Envelope>
我们希望这条消息成为结果。
<?xml version = "1.0" encoding="ISO-8859-1"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.es">
<soapenv:Header/>
<soapenv:Body>
<ws:reception>
<ws:xml>
<![CDATA[<message>Data messsage to send]]></message>
</ws:xml>
</ws:reception>
</soapenv:Body>
</soapenv:Envelope>
我们正在使用这个xslt模板
<?xml version = "1.0" encoding = "ISO-8859-1"?>
<xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "//ws:xml">
<xsl:copy>
<xsl:text disable-output-escaping="yes"> <![CDATA[</xsl:text>
<xsl:copy-of select="*"/>
<xsl:text disable-output-escaping="yes"> ]]></xsl:text>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
但它不起作用。
任何人都可以帮助我们吗?
提前致谢。
答案 0 :(得分:0)
您的两个文件完全相同。但如果我认为你想要改变
,那就是正确的<message>Data messsage to send</message>
到
<message><![CDATA[Data messsage to send]]></message>
若是,请尝试以下方法:
(代码已经过编辑以反映更新的问题)
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="message">
<xsl:text disable-output-escaping="yes"> <![CDATA[</xsl:text>
<message>
<xsl:value-of select="//message"/>
</message>
<xsl:text disable-output-escaping="yes"> ]]></xsl:text>
</xsl:template>
请注意,Michael Kay会因使用disable-output-escaping