具有多个名称空间的SOAP响应的XSLT转换

时间:2016-11-26 11:48:56

标签: xml xslt soap xml-namespaces

我一直在尝试转换SOAP响应,基于我的知识,我尝试了很多方法,下面是我编写的XML和XSL,我似乎无法获得任何节点的价值。

下面是xml:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
  <CreateCallResponse xmlns="http://tempuri.org/">
     <CreateCallResult xmlns:a="http://schemas.datacontract.org/2004/07/ServiceCallCreate" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:ParameterList>
           <a:Paramname>errorstate</a:Paramname>
           <a:ParamValue>0</a:ParamValue>
        </a:ParameterList>
        <a:ParameterList>
           <a:Paramname>errorstring</a:Paramname>
           <a:ParamValue/>
        </a:ParameterList>
        <a:ParameterList>
           <a:Paramname>newcallid</a:Paramname>
           <a:ParamValue>160901-0083</a:ParamValue>
        </a:ParameterList>
     </CreateCallResult>
  </CreateCallResponse>
 </s:Body>
</s:Envelope>

以下是XSL:

 <xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
  xmlns:s="http://schemas.xmlsoap.org/soap/envelope"
  xmlns:a="http://schemas.datacontract.org/2004/07/ServiceCallCreate"
  xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:k="http://tempuri.org" exclude-result-prefixes="s k i a">
 <xsl:output method="xml" omit-xml-declaration="yes" encoding="utf-8" indent="yes" />
<xsl:template match="/">
    <CreateCallResponse>
        <ErrorCode>
             <xsl:value-of select="s:Envelope/s:Body/k:CreateCallResponse/i:CreateCallResult/a:ParameterList/a:ParamValue" />
        </ErrorCode>
    </CreateCallResponse>
</xsl:template>
</xsl:stylesheet>

请帮我解决我犯错的地方。

1 个答案:

答案 0 :(得分:1)

在样式表中,您没有使用输入中的URI,因此在样式表中将xmlns:k="http://tempuri.org"更改为xmlns:k="http://tempuri.org/",并将xmlns:s="http://schemas.xmlsoap.org/soap/envelope"更改为xmlns:s="http://schemas.xmlsoap.org/soap/envelope/",然后更改路径到<xsl:value-of select="s:Envelope/s:Body/k:CreateCallResponse/k:CreateCallResult/a:ParameterList/a:ParamValue" />。我不确定你输入的ParamValue是哪个。

相关问题