使用XSLT 1.0检索转义的XML和unescape

时间:2013-08-23 01:23:12

标签: xml xslt escaping xslt-1.0

我正在调用一个将响应XML嵌入为转义XML的Web服务。我收到了完整的SOAP响应,但我只对'转义的XML'部分()感兴趣。

我正在尝试编写一个XSL(1.0)来检索转义的XML和UNESCAPE,所以我可以通过其他非XSLT组件来处理它。

我在StackOverflow中尝试了一些其他'unescaping'解决方案,但没有运气。

来自Web服务的响应

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <SendMessageResponse xmlns="http://www.company.com/CAIS">
            <SendMessageResult>&lt;?xml version="1.0"?&gt;&lt;IEXInboundServiceResponse&gt;&lt;IEXInboundServiceResponseVersion&gt;1.0&lt;/IEXInboundServiceResponseVersion&gt;&lt;ServiceResponse&gt;IEX_SUCCESS&lt;/ServiceResponse&gt;&lt;RequestMessageId&gt;22658651-024E-445B-96C1-94F027205E01&lt;/RequestMessageId&gt;&lt;/IEXInboundServiceResponse&gt;</SendMessageResult>
        </SendMessageResponse>
    </s:Body>
</s:Envelope>

unescaping后的所需输出

<?xml version="1.0"?>
<IEXInboundServiceResponse>
    <IEXInboundServiceResponseVersion>1.0</IEXInboundServiceResponseVersion>
    <ServiceResponse>IEX_SUCCESS</ServiceResponse>
    <RequestMessageId>22658651-024E-445B-96C1-94F027205E01</RequestMessageId>
</IEXInboundServiceResponse>

我正在使用的当前XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" indent="yes" omit-xml-declaration="yes"/>

    <xsl:template match="//SendMessageResult">
        <xsl:value-of select="." disable-output-escaping="yes" />
    </xsl:template>

</xsl:stylesheet>

帮助!

由于

大卫

1 个答案:

答案 0 :(得分:2)

问题是要处理你正在使用的命名空间。首先,您尚未在XSLT中声明http://www.company.com/CAIS namspace。您可以通过将第一行更改为:

来解决此问题
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
                 xmlns:c="http://www.company.com/CAIS">

注意最后的命名空间。我尝试使用空白命名空间,但它仍然存在与您相同的问题。

然后将模板的开头行更改为:

<xsl:template match="//c:SendMessageResult">

然后它应该按预期工作。