2009-10-11 75 views

回答

10

正常化空間是一個函數。你不能在那裏使用它。
您需要一個節點集。

也許你的意思是

//br/preceding-sibling::* 

,或者你可以在一個謂語使用正常化空間,在方括號內。將謂詞看作節點集上的過濾器或選擇器。所以,你可以這樣做:

//br/preceding-sibling::*[normalize-space()='Fred'] 

在英語中是轉化爲「所有元素在文檔中前<br>,併爲其(標準化)的文字是‘弗雷德’」。在此文檔中:

<html> 
    <p> 
    <h2>Fred</h2> 
    <br/> 
    </p> 
    <table> 
    <tr> 
     <td> 
     <br/> 
     </td> 
    </tr> 
    </table> 
</html> 

... xpath表達式選擇<h2>節點。

我想出了free XpathVisualizer tool available on codeplex

enter image description here