<bookstore>
<book category="Programming">
<title lang="en">Coding</title>
<publisher>ErBooks</publisher>
<field>web</field>
<field>programming</field>
<field>C++</field>
</book>
<book category="XML">
<title lang="en">Hey XML</title>
<publisher>BookyBooks</publisher>
<field>web</field>
<field>xml</field>
<field>database</field>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<publisher>Penguin</publisher>
<field>web</field>
<field>design</field>
<field>database</field>
</book>
我想检索每个出版商已经出版书籍的字段(在此示例中为&#34; web&#34;)。
伪代码: 如果所有发布者= fieldX return fieldX
答案 0 :(得分:3)
如果每个出版商只有一本书,例如,如果所有书籍都有该字段,您可以直接检查每个字段:
/book[1]/field[every $book in /book satisfies $book/field = .]
否则,您需要过滤图书并分别考虑每个发布商:
let $bookstore := /bookstore
let $publisher := distinct-values($bookstore/book/publisher)
let $fields := distinct-values($bookstore/book/field)
return $fields[every $p in $publisher satisfies $bookstore/book[publisher = $p]/field = .]