Page 1 of 1

XQueryUpdateOperation document update in for loop

Posted: Mon Oct 24, 2016 7:10 pm
by steve.cuzner
I've got a custom action that implements XQueryUpdateOperation. The associated script is something like:

Code: Select all

for $node in  ( //*:section )
let $new_att_node := mwclib:augment($node)
return
insert node $new_att_node into $node
The problem is that the function mwclib:augment() depends on evaluating the entire document so after the first iteration the section element is modified to have the new attribute and on the second iteration the function needs to know about the data inserted in iteration one, but that doesn't seem to be happening. Is there a way to signal a document update between iterations?

Re: XQueryUpdateOperation document update in for loop

Posted: Tue Oct 25, 2016 9:25 am
by Radu
Hi Steve,

I would suggest you ask this question on an XSLT users list or on the Saxon users list.
From what I suspect both XQuery and XSLT are side-effect free, not sure about XQuery update but it should also be side effect free, the original model on which the iteration is done is not the same with the changed nodes model which will be eventually be saved.

Regards,
Radu

Re: XQueryUpdateOperation document update in for loop

Posted: Tue Oct 25, 2016 4:51 pm
by steve.cuzner
Radu,

You are correct about the side effect free implementation. You might want to consider this proposed extension for use in XQueryUpdateOperation as a possible enhancement:

http://www.cs.stanford.edu/people/chris ... ryBang.pdf

Steve

Re: XQueryUpdateOperation document update in for loop

Posted: Wed Oct 26, 2016 7:52 am
by Radu
Hi Steve,

The XQueryUpdate operation uses the Saxon 9 XSLT processor engine so we do not control its implementation. Se if you want you can request this on the Saxon mailing list. In the meantime you can probably also use a Javascript operation which iterates directly over the AuthorNode implementations and uses the AuthorDocumentController to directly change the nodes.

Regards,
Radu