Figaro - The XML Database for the .NET Framework
Transform Functions
Send Feedback
Figaro - the XML Database for the .NET Framework
Figaro - The XML Database for the .NET Framework

While it is true that you cannot run an update query and simultaneously return the results, there is a way to almost do the same thing. You do this by making a copy of the nodes that you want to modify, then perform the modifications against that copy. The result of the modification is returned to you. This type of an operation is called a transformation.

Note that when you perform a transformation, the original nodes that you copied are not modified. For this reason, transformations are often limited only to situations where you want to modify a query result — for reporting purposes, for example.

To run a transformation, use the:

  1. copy keyword to copy the nodes of interest
  2. modify keyword to perform the XQuery Update against the newly copied nodes
  3. return keyword to return the result of the transformation.

For example, given the following XML document (which is identified as document mydoc.xml, and is stored in container con.dbxml):

CopyXML
<a>
   <aab1>first child</aab1>
   <b2>second child</b2>
   <b3>third child</b3>
</a>
then the following transformation:
Copy 
    copy $c := doc("dbxml:/con.dbxml/mydoc.xml")/a
modify (delete nodes $c/aab1,
        replace value of node $c/b2 with "replacement value")
return $c
results in the following document:
CopyXML
<a>
   <b2>replacement value</b2>
   <b3>third child</b3>
</a>
Figaro - The XML Database for the .NET Framework

Copyright © 2008-2009 Endpoint Systems. All rights reserved.