Christian,
Sony,
this query might do what you want:
let $node :=
copy $c :=return replace value of node $child with "This is a child node"
<entry>
<title>How to use updating and non-updating expressions together</title>
<child>child 1</child>
<child>child 2</child>
</entry>
modify (
for $child in $c//child
)
return $c
return
insert node $node into doc('seconddocument')
Due to the sometimes confusing flexibility of XQuery, this is just one
way to do it. Note that you always need to specify complete FLWOR
expressions; e.g., in your first query you forgot to add a "return"
statement after the first "let" clause. The syntax would be simpler if
Transform expressions (copy .. modify .. return) were part of the
FLWOR expression, and it might be that future version of XQuery won't
make a difference here anymore.
Christian
___________________________
On Fri, Feb 25, 2011 at 5:07 PM, Sony Vijay <sony.vibh@gmail.com> wrote:
> @Christian and Lukas: Many thanks for helping me with the transform
> expression so far.
> However, I am not sure if we can use both non-updating and updating
> expressions in a single query ? Meaning, I am trying to modify one document
> and insert the modified document into the second document.
> Example:
>
> let $newchild := "This is a child node"
> copy $c := <entry><title>How to use updating and non-updating expressions
> together</title>
> <child>child 1<child>
> <child>child 2</child>
> </entry>
> modify (
> for $child in $c//child
> return replace value of node $child with $newchild
> )
> return insert node $c into doc('seconddocument')
>
> I also tried:
>
> let $newchild := "This is a child node"
> copy $c := <entry><title>How to use updating and non-updating expressions
> together</title>
> <child>child 1<child>
> <child>child 2</child>
> </entry>
> return
> modify (
> for $child in $c//child
> return replace value of node $child with $newchild
> )
> insert node $c into doc('seconddocument')
>
> Of course, I can achieve this when I use two xqueries (one to return the
> modified document and the other to insert it into a second document). But,
> it would be great if I could perform both actions in a single query.
> Thanks,
> Sony