2014-03-06 45 views
1

我有一個名爲entity的根節點的XML文檔。對於每個文檔,我想要計算它的名稱爲tender的節點數量,並將其作爲屬性添加到entity如何在Zorba XQuery中添加屬性?

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,這是不是左巴,但我猜,這是標準的XQuery。

我得到的錯誤

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

我在做什麼錯?

回答

1

我懷疑你的更新語句對於Zorba是不正確的。 eXist實現了XQuery Update 1.0的早期草案。我相信,而不是左巴正確implemenets 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

+0

讀是的,這會是正確的。 – wcandillon

+0

下面是Zorba上的一個工作示例:http://try.zorba.io/queries/xquery/U%2FcxnnwOm8RG0mpsMI2hBikeIeQ%3D在這個示例中,我們使用xquery腳本來應用更新並返回結果。 – wcandillon