2016-11-26 95 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