[xquery-talk] Need help with an insert query (need to reference an attribute value)

Christian Grün christian.gruen at gmail.com
Thu Dec 12 05:20:24 PST 2013

> 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?

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

More information about the talk mailing list