2014-03-06 30 views
1

我不知道爲什麼這不起作用。xsl導航似乎不工作

這裏是我的xml:

<s:Body xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
<LoginBodyResponse xmlns="http://tempuri.org"> 
<LoginBodyResult>somettext</LoginBodyResult> 
</LoginBodyResponse> 
</s:Body> 

這裏是我當前的xsl:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
      xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" 
      exclude-result-prefixes="msxsl var s0" 
      version="1.0" 
      xmlns:ns0="http://tempuri.org" 
      xmlns:s0="http://tempuri.org"> 
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" /> 
<xsl:template match="LoginBodyResponse"> 
    <ns0:LoginBodyReponse> 
    <xsl:if test="LoginBodyResult"> 
     <LoginBodyResult> 
     <xsl:value-of select="LoginBodyResult/text()" /> 
     </LoginBodyResult> 
    </xsl:if> 
    </ns0:LoginBodyReponse> 
</xsl:template> 
</xsl:stylesheet> 

我不能讓它進入這個模板。我真的不確定爲什麼它不會去LoginBodyResponse節點。我認爲我犯了一個愚蠢的小錯誤,但無法弄清楚它是個問題。我也將模板匹配設置爲* /,當我這樣做時,它無法在xsl:if部分中找到LoginBodyResult。

我基本上是在尋找這樣的輸出:

<ns0:LoginBodyReponse xmlns:ns0="http://tempuri.org"> 
    <LoginBodyResult>somettest</LoginBodyResult> 
    </ns0:LoginBodyReponse> 

回答

3

這是因爲LoginBodyResponse是在默認名稱空間http://tempuri.org。你需要在你的xpaths中添加元素的前綴。

未經測試的例子:

<xsl:template match="ns0:LoginBodyResponse"> 
    <ns0:LoginBodyReponse> 
     <xsl:if test="ns0:LoginBodyResult"> 
      <LoginBodyResult> 
       <xsl:value-of select="ns0:LoginBodyResult" /> 
      </LoginBodyResult> 
     </xsl:if> 
    </ns0:LoginBodyReponse> 
</xsl:template> 

此外,如果您刪除重複的命名空間聲明xmlns:s0="http://tempuri.org"(並從exclude-prefix-resultss0),你應該讓你在尋找的輸出。

+0

duh。就是這樣。謝謝!另外,tempuri.org並不是我的xsl的樣子。我只是改變它來隱藏我的真實命名空間在這裏。 –