XQuery Update using IF Condition...
Dear Team, I am getting error - If expression : no updating expression allowed - while trying to update the "Data" DB. I need to update the DB, if it is not already updated... for $c in doc('2012')/Docs/Doc/No/@n return if (string-length(doc('Data')/Docs/Doc[No/@n=$c]/Title/Name/text()) eq 0) then insert node $c into doc('Data')/Docs else <l>{''}</l> -- Have a nice day JBest
Hi John, all branches of your if expression must be updating, or return an empty sequence. In the latest snapshot [1], I’ve replaced the old error message with a more helpful one (“all expressions must be updating or return an empty sequence.”). To come back to your query: The following query will be accepted: for $c in doc('2012')/Docs/Doc/No/@n return if(doc('Data')/Docs/Doc[No/@n=$c]/Title/Name/text()) then insert node $c into doc('Data')/Docs else () The following query does the same: for $c in doc('2012')/Docs/Doc/No/@n where doc('Data')/Docs/Doc[No/@n=$c]/Title/Name/text() return insert node $c into doc('Data')/Docs If you want to return some textual output for all nodes that have not been updated, you can use db:output() [2]: for $c in doc('2012')/Docs/Doc/No/@n return if(doc('Data')/Docs/Doc[No/@n=$c]/Title/Name/text()) then insert node $c into doc('Data')/Docs else db:output(<ld>{''}</l>) Hope this helps, Christian [1] http://files.basex.org/releases/latest/ [2] http://docs.basex.org/wiki/Database_Module#db:output
participants (2)
-
Christian Grün -
John Best