1
<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>

我想检索每个出版商都出版过书籍的字段(在这个示例中是“网络”)。

伪代码:如果所有发布者 = fieldX 返回 fieldX

4

1 回答 1

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 = .]
于 2013-11-11T11:52:43.170 回答