1
votes

I have the following problem. I want to replace a value of an element in my xquery-file by using baseX as the database. The xquery code is as follows:

    let $db := doc('update.xml')

replace value of node $db//elem with 'haha'

return <result> {$db//elem/text()} </result>

The xml document contains the following elements:

<?xml version="1.0" encoding="ISO-8859-1"?>
<root xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<check>
    <ok>
        <elem>test</elem>
        <help></help>
    </ok>
</check>
</root> 

Everytime I want to execute this xquery an error like this is thrown:

Expecting 'where', 'order' or 'return' expression

so what should i do or change, to just replace the text "test" by "haha" in the element ? If I use just this line of code it works, but I have to read out of URL-Parameter so I need more lines of code, except the "replace...." line!

1

1 Answers

1
votes

let starts a flwor-expression which may not directly contain update statements. You will have to put a return between these two:

let $db := doc('update.xml')
return
  replace value of node $db//elem with 'haha'

You will also be able to do arbitrary calculations, but make sure not to have any output returned by your query.

There is no way to use updating statements and return a result at the same time.