<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>replacing a node in in-memory XML</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16544" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=377462615-06112007><FONT face=Arial 
color=#0000ff size=2>In the absence of XQuery updates (still&nbsp;a draft W3C 
spec) it's quite a bit harder to do this in XQuery than in XSLT: you basically 
have to organize the recursive walk down the tree copying nodes as you go 
yourself "by hand". If you are comfortable with XSLT then this is definitely a 
task where XSLT currently wins. It will get a lot easier with XQuery 
updates.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=377462615-06112007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=377462615-06112007><FONT face=Arial 
color=#0000ff size=2>Michael Kay</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=377462615-06112007><FONT face=Arial 
color=#0000ff size=2><A 
href="http://www.saxonica.com/">http://www.saxonica.com/</A></FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
  <HR tabIndex=-1>
  <FONT face=Tahoma size=2><B>From:</B> talk-bounces@x-query.com 
  [mailto:talk-bounces@x-query.com] <B>On Behalf Of </B>Robert 
  Walpole<BR><B>Sent:</B> 06 November 2007 15:05<BR><B>To:</B> 
  talk@xquery.com<BR><B>Subject:</B> [xquery-talk] replacing a node in in-memory 
  XML<BR></FONT><BR></DIV>
  <DIV></DIV><!-- Converted from text/rtf format -->
  <P><FONT face=Arial size=2>Hi,</FONT> </P>
  <P><FONT face=Arial size=2>I am trying to figure out the best way to replace a 
  node within an in-memory XML fragment.</FONT> </P>
  <P><FONT face=Arial size=2>For example, lets say I have the following fragment 
  in memory&#8230;</FONT> </P>
  <P><FONT face=Arial size=2>&lt;communitygroup&gt;</FONT> 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT face=Arial 
  size=2>&lt;group&gt;</FONT> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT face=Arial 
  size=2>&lt;name&gt;Test&lt;/name&gt;</FONT> 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT face=Arial 
  size=2>&lt;services&gt;</FONT> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT face=Arial size=2>&lt;service 
  value="true"&gt;2&lt;/service&gt;</FONT> 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT face=Arial 
  size=2>&lt;/services&gt;</FONT> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  <FONT face=Arial size=2>&lt;/group&gt;</FONT> <BR><FONT face=Arial 
  size=2>&lt;/communitygroup&gt;</FONT> </P>
  <P><FONT face=Arial size=2>&#8230;and want to replace the services node with the 
  following&#8230;</FONT> </P>
  <P><FONT face=Arial size=2>&lt;services&gt;</FONT> 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT face=Arial 
  size=2>&lt;service value="false"&gt;1&lt;/service&gt;</FONT> 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT face=Arial 
  size=2>&lt;service value="true"&gt;2&lt;/service&gt;</FONT> 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT face=Arial 
  size=2>&lt;service value="false"&gt;3&lt;/service&gt;</FONT> <BR><FONT 
  face=Arial size=2>&lt;/services&gt;</FONT> </P>
  <P><FONT face=Arial size=2>Is there a way of doing this in XQuery?</FONT> </P>
  <P><FONT face=Arial size=2>Obviously I could use an XSL transformation, which 
  would give me the result I want, but maybe there is a more efficient way using 
  XQuery?</FONT></P>
  <P><FONT face=Arial size=2>Thanks</FONT> <BR><FONT face=Arial size=2>Rob 
  Walpole</FONT> <BR><FONT face=Arial size=2>Devon Portal Developer</FONT> 
  <BR><FONT face=Arial size=2>Email robert.walpole@devon.gov.uk</FONT> <BR><FONT 
  face=Arial size=2>Web </FONT><A href="http://www.devonline.gov.uk"><U><FONT 
  face=Arial color=#0000ff size=2>http://www.devonline.gov.uk</FONT></U></A> 
</P></BLOCKQUOTE></BODY></HTML>