Question

I have XML documents with the root node called entity. For each document, I want to count how many nodes it has with the name tender and add it as an attribute to 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

I was following http://exist-db.org/exist/apps/doc/update_ext.xml, which is not for Zorba, but I guessed this is standard XQuery.

I get the error

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

What am I doing wrong?

Was it helpful?

Solution

I suspect that your update statement is not correct for Zorba. eXist implements an early draft of XQuery Update 1.0. I believe instead that Zorba correctly implemenets XQuery Update 1.0 specification, so your update should conform with this instead: http://www.w3.org/TR/xquery-update-10/

Perhaps something like:

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

In particular have a read of http://www.w3.org/TR/xquery-update-10/#id-insert

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top