Xquery update on attribute

Hi,
what is the correct syntax for doing an update on an attrbitue ?

my first attempt was to write a query such as the following, which dose not work.

update for $x in input()/Greeting
do (replace $x/@:by with “testing”)

xml instance doc looks like this:
HellO!


also took me a while figure out that ‘by’ was a reserved word in XQuery… hence the ‘:’ in “$x/@:by”

is this even possible. so far i have only found references to posts where the query updates an entire element. Havent found anyone asking about updating attributes.

Thanks…

–joey

X-Application Version: 4.1.1
Tamino Version : 4.1.4.1
Platform : Linux
WebContainer : Tomcat 4.1.24
JDK Version : 1.4.1

Hi, you can update attributes in the following way. In the update the variable $r hold a dummy node holding the atttibute (because you can’t construct a standalone attribute) which will replace the one in the document.

update for $x in input()/Greeting
let $r :=
where …
do replace $x/@:by with $r/@:by

Hope this helps.

Stuart Fyffe-Collins
Software AG (UK) Ltd.

Thanks Stuart,

makes sense…

thnkx…

–joey

X-Application Version: 4.1.1
Tamino Version : 4.1.4.1
Platform : Linux
WebContainer : Tomcat 4.1.24
JDK Version : 1.4.1

in the instance “HellO!


I try use “update for $x in input()/Greeting
let $r := Hello!
do replace $x/@:by with $r/@:by”

to update, but it still has no changing.

could anyone tell me why?

thank you very much.

Hello VinceChen,

what was the result of executing your update?
In my environment the query you posted gives an error, because the namespace prefix “ino” is not bound to anything.
As the ino:id attribute is not used in the example, I simply deleted it from the $r document. The update then executes correctly, and the value of the “by” attribute is “testing” after the update.
(The value of the “Greeting” element itself is still “HellO!” of course, as we have not updated this yet.)

I hope that helps,
Trevor.