Discussion:
[xquery-talk] Need help with an insert query (need to reference an attribute value)
Ando Roy
2013-12-12 06:45:20 UTC
Permalink
Greetings all,

Let's say I want to do an insertion as this point:

doc("example.html")/ABC

where attribute x in ABC is equal to "123". How can this be achieved?

Thanks in advance

Regards,
Roy
David Lee
2013-12-12 13:07:49 UTC
Permalink
Could you explain precisely what you mean by "insertion" ?

Do you want to generate a document with an a additional attribute *in memory* or do you want to insert data on disk or database ?
Do you want to insert an attribute x="123" or do you want to insert something else *where* x="123" ?
Do you want to insert a child of ABC or a sibling ?
Also ... (sorry for the long list but the answer depends on it )
What version and processor of XQuery are you using ? Some XQuery versions and processors support "XQuery with updates" some do not, and some have vendor extensions
that do similar things.

So I am sorry, the answer (as are most things of this sort) "It Depends"


-David



----------------------------------------
David A. Lee
***@calldei.com<mailto:***@calldei.com>
http://www.xmlsh.org

From: talk-***@x-query.com [mailto:talk-***@x-query.com] On Behalf Of Ando Roy
Sent: Thursday, December 12, 2013 1:45 AM
To: ***@x-query.com
Subject: [xquery-talk] Need help with an insert query (need to reference an attribute value)

Greetings all,

Let's say I want to do an insertion as this point:

doc("example.html")/ABC

where attribute x in ABC is equal to "123". How can this be achieved?

Thanks in advance

Regards,
Roy
Christian Grün
2013-12-12 13:20:24 UTC
Permalink
Post by Ando Roy
doc("example.html")/ABC
where attribute x in ABC is equal to "123". How can this be achieved?
If your processor supports XQuery Update, you can do the following:

insert node <whatever-you-want-to-insert/>
into doc("example.html")/ABC[@x = "123"]

Please note that the result may not automatically be reflected in the
original document. As David indicated, it depends on the processor you
are using.

If you want to update a document "in-place" without storing it to
disk, you can also use the transform expression:

copy $c := doc("example.html")
modify (
insert node <whatever-you-want-to-insert/>
into $c/ABC[@x = "123"] )
return $c

Loading...