我找不到任何關於XPath中的id()
函數的好解釋。它有什麼作用?你如何使用它?XPath id()函數
從可用的描述,它聽起來像它會給你一個節點id
。
所以我打了它這樣的,但得到了一個錯誤:
//bookstore/id(book)
然後有一個小票友,並試圖
//bookstore/book[name = id(book/@category)]
它沒有返回一個錯誤,但沒有得到命中。
有人可以爲我和未來的Stack粉絲和Google員工解釋這個功能嗎?
下面是我用打XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J. K. Rowling</author>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
<book category="OPENSOURCE">
<title lang="en">Open Source</title>
<year>2003</year>
<price>39.95</price>
</book>
<book category="WEB">
<title lang="en">WEB</title>
<year>2012</year>
<price>21.99</price>
</book>
</bookstore>
你應該玩一個包含'id'屬性的文檔,不是嗎? :) – hek2mgl