|
Re: XUpdate:how to replace a node: msg#00228text.xml.exist
Hi, > Hi, > > > Hi, I need to replace a given node in my database by a whole new node. > > First, is the XUpdate documentation found on > > http://xmldb-org.sourceforge.net/xupdate/xupdate-wd.html current > > enough? > > > > Well, this documentation doesn't mention any replace functionality. So > > I thought that I could just remove the node, and add the new node to > > the parent, at the same position. Problem: in order to be able to > > append the new node to the parent, I need to put a reference to the > > parent in a variable before deleting the old node: my XPath to the > > node is like //node[@id="2"], so I can easily find the parent before > > deleting the node, but it is impossible afterwards. > > I first tried the approach using variables. However, this didn't work, > basically because the declared variables were not visible from within the > select. I have thus fixed the code, so the following code snippet > does the > job now (example taken from the corresponding junit test > "src/org/exist/xupdate/test/modifications/variables.xml"): > > <xu:variable name="address" select="//address[lname = 'Hyde']"/> > <xu:variable name="root" select="$address/.."/> > > <xu:remove select="$address"/> > <xu:append select="$root"> > <address> > <fname>Boris</fname> > <lname>Becker</lname> > <company>BB-Inc.</company> > <city>Leimen</city> > </address> > </xu:append> > > However, I also added an experimental xupdate:replace command. The code > differs only slightly from xupdate:update. Using xupdate:replace, you can > directly do: > > <xu:replace select="//address[lname = 'Hyde']"> > <address> > <fname>Boris</fname> > <lname>Becker</lname> > <company>BB-Inc.</company> > <city>Leimen</city> > </address> > </xu:replace> > > which is definitely much simpler. You will find both changes in > the current > CVS or snapshot. > > Wolfgang thanks for the fix,I need to use the variable within the select! However I think there is an error in your first example because is not make a true replace.It doesn't save the order of the child node removed and the new node is inserted as last.It's possible to use the variables reference within the child attribute of append? Marco --- avast! Antivirus: In partenza messaggio pulito. Virus Database (VPS): 0439-2, 24/09/2004 Controllato il: 25/09/2004 12.40.15 avast! is copyright (c) 2000-2003 ALWIL Software. http://www.avast.com ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | XUpdate specifications: 00228, Sergey Prohorenko |
|---|---|
| Next by Date: | Re: New snapshot: 00228, Wolfgang Meier |
| Previous by Thread: | Restructuring util: and xmldb: function modulesi: 00228, Luigi Bai |
| Next by Thread: | NEW: jEdit XQuery Plugin Adapter: 00228, Wolfgang Meier |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |