Hi Petr,
Op 17 mrt 2011, om 06:46 heeft Petr Vacek het volgende geschreven:
When I try through declaring updating function, even then it reports error : declare namespace testa='test';
declare updating function testa:bid($a, $b) { if (exists(/p/pl[id=6]/name)=true) then insert node <name>thenname</name> into /p/pl[id=6] else <dummy/> };
testa:bid(0,0)
Error: [XUST0001] If expression: no updating expression allowed.
I've got these errors from baseX 6.5.1 package.
So how can I modify values in a simple fashion if possible ? If I call insert straight, the there could be multiple elements of same value. If I call replace it will fail when the node does not exist. If I delete the node before insert/replace then I could destroy sub-nodes which I don't want.
You definitely need to "declare updating function()", however, an updating function can never return a value (just like SQL UPDATE doesn't return a value from the database query). The sneaky part in XQuery Update is that the 'updating quality' bubbles up, e.g. when function A() calls an updating function B(), function A() is also an updating function (at least that's my understanding). Therefore, you're entire xquery is an updating function, so the whole thing can't return a value, not even <dummy/>. You can use the empty sequence () as a return value though.
Hartelijke groet,
Huib.
-- Drs. Huib Verweij Senior software developer - The Language Archive Max Planck Institute for Psycholinguistics P.O. Box 310 6500 AH Nijmegen The Netherlands t +31-24-3521911 e huib.verwey@mpi.nl w http://www.mpi.nl/