是否有XPath方法使用XPath查詢直接恢復XML節點的前一個兄弟節點的一個特定屬性?檢索特定的前面的兄弟節點屬性
在以下示例中,我想檢索前面標有id=marker
的div
元件每個img
節點的alt
屬性的值。
<content>
<img alt="1" src="file.gif" />
<img alt="2" src="file.gif" />
<img alt="3" src="file.gif" />
<img alt="4" src="file.gif" />
<div id='marker'></div>
</content>
對於本示例,我想檢索值1 2 3 4
。
我用下面的XPath查詢
//div[@id='marker']/preceding-sibling::img
,以便檢索節點列表我想
<img alt="1" src="file.gif"/>
<img alt="2" src="file.gif"/>
<img alt="3" src="file.gif"/>
<img alt="4" src="file.gif"/>
由於它是一個節點列表,然後我可以在節點上進行迭代,以檢索屬性值I我正在尋找,但是有XPath的方式嗎? 我本來期望能夠寫類似:
//div[@id='marker']/preceding-sibling::[email protected]
or //div[@id='marker']/[email protected]::img
,但我甚至不知道是否有可能,一旦你已經使用了XPath Axe
像前同輩。
@skaffman:我可能會問你爲什麼你打消了我的'sibling'請標籤? – 2010-05-26 22:37:19