2016-11-26 76 views
0

我一直在努力改造SOAP响应,根据我的知识,我已经试过许多方法,下面是我写的XML和XSL,我似乎无法得到任何节点的值。XSLT转换

下面是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

在样式表中你没有使用这些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来自你想要的输入。

+0

我也试过这个,但没有得到任何价值。从我的理解上面的xpath应该给我带来第一个paramValue – joga

+0

你的代码中有另一个不正确的URI。 –

+0

谢谢,它工作:) – joga