<!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 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> </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…</FONT> </P>
<P><FONT face=Arial size=2><communitygroup></FONT>
<BR> <FONT face=Arial
size=2><group></FONT> <BR>
<FONT face=Arial
size=2><name>Test</name></FONT>
<BR>
<FONT face=Arial
size=2><services></FONT> <BR>
<FONT face=Arial size=2><service
value="true">2</service></FONT>
<BR>
<FONT face=Arial
size=2></services></FONT> <BR>
<FONT face=Arial size=2></group></FONT> <BR><FONT face=Arial
size=2></communitygroup></FONT> </P>
<P><FONT face=Arial size=2>…and want to replace the services node with the
following…</FONT> </P>
<P><FONT face=Arial size=2><services></FONT>
<BR> <FONT face=Arial
size=2><service value="false">1</service></FONT>
<BR> <FONT face=Arial
size=2><service value="true">2</service></FONT>
<BR> <FONT face=Arial
size=2><service value="false">3</service></FONT> <BR><FONT
face=Arial size=2></services></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>