3
<child id="1" name="alpha" >Some Text</child
<child id="2" name="beta" >
<grandchild id="2.1"></grandchild>
<grandchild id="2.2"></grandchild>
</child>
<child id="3" name="gamma" mark="yes" >
<grandchild id="3.1" name="gamma-alpha"> </grandchild>
<grandchild id="3.2" name="gamma-beta" ></grandchild>
</child>
有4個孫子節點,我想獲得所有他們的父母(這恰好是在我的示例數據)id值中的「孩子」節點。我自己的愚蠢的嘗試:
//孫子/父母子女::/@ ID
回報:
text{"2"},
text{"3"}
而已,但
text{"2"},
text{"2"},
text{"3"},
text{"3"}
是我想看到什麼。
儘管答案在技術上是正確的,但並不能解釋爲什麼不出現重複。 XPath在節點集上工作,而不是強制性的。根據定義,這些集合不能包含重複項。 – Lucero
好吧,如果XPath只在集合上運行,那麼我的XPath 2.0或3.0建議將不起作用。我解釋說,選擇節點的步驟消除了重複項,這在XPath 2.0和3.0數據模型和規範的意義上是正確的。 XPath 1.0適用於節點集,這是正確的。 –
是的,我應該寫出我的意思是XPath 1.0,謝謝指出它。 – Lucero