1

我有 XML 文档,其根节点名为entity. 对于每个文档,我想用名称计算它有多少个节点tender,并将其作为属性添加到entity.

import module namespace file = "http://expath.org/ns/file";

for $file in file:list("../api/entity/p/", true(), "??????.xml")
let $doc := doc(concat("../api/entity/p/", $file))
return
    update insert attribute number_of_tenders {count($doc//tender)} into $doc/entity

我关注的是http://exist-db.org/exist/apps/doc/update_ext.xml,这不适合 Zorba,但我猜这是标准的 XQuery。

我得到错误

6,69: static error [err:XPST0003]: invalid expression: syntax error, unexpected expression (missing comma "," between expressions?)

我究竟做错了什么?

4

1 回答 1

1

我怀疑您的更新声明对于 Zorba 是不正确的。eXist 实现了 XQuery Update 1.0 的早期草案。相反,我相信 Zorba 正确地实现了 XQuery 更新 1.0 规范,因此您的更新应该符合这一点:http: //www.w3.org/TR/xquery-update-10/

也许是这样的:

for $file in file:list("../api/entity/p/", true(), "??????.xml")
let $doc := doc(concat("../api/entity/p/", $file))
return
    insert node attribute number_of_tenders {count($doc//tender)} into $doc/entity

特别是阅读http://www.w3.org/TR/xquery-update-10/#id-insert

于 2014-03-06T11:31:18.530 回答