2010-05-18 38 views
-1

我有下面的代碼,我不得不選擇所有id爲節點=「文本」,而不是已經有一個父id爲節點=「文本」:的XPath選擇標籤的ID沒有後裔

<fo:block id="text"> 
    test00 
    <fo:block id="text"> 
     test01 
    </fo:block> 
    <fo:block> 
     test02 
    </fo:block> 
</fo:block> 
<fo:block id="text"> 
    test03 
</fo:block> 

所以在這個例子中,查詢必須只返回兩個帶有內容test00和test03的fo:block。

謝謝。

+0

到目前爲止你寫了些什麼? – Oded 2010-05-18 12:31:56

+1

似乎無效(!),沒有人使用屬性ID作爲「不唯一」! ......在最好的情況下,我們可以說這不是最佳做法。 – 2014-06-30 18:00:35

回答

2

我會像這樣的東西去:

//fo:block[@id='text' and not(./*[@id='text'])] 

我要去給它一個測試,現在,以確保它是明智的。是啊。它根據需要返回text00和text03。所以讓我解釋一下這個表達。

//fo:block    # Select all fo:block elements in the document 
[ 
    @id='text' and  # Get only those whose id attribute's value is "text" 
    not(./*[@id='text']) # and whose children do not have id attributes equal to "text" 
] 
+0

非常感謝你,你太快了,現在你是我的新偶像! – Stefano 2010-05-18 13:01:06