[xquery-talk] problem with Xupdate

Wolfgang Meier wolfgang at exist-db.org
Tue Jan 10 10:39:17 PST 2006


Hi,

your second XUpdate applies to the nodes selected by the XPath
expression: doc('/db/content/map1.xml')/maps/map. This selects all map
elements in the document - including the one you added through the first
XUpdate. If you want to update just the element you added, you have to
select it, e.g. by using last():

doc('/db/content/map1.xml')/maps/map[last()]

Please note that XUpdate is not really related to XQuery, so XUpdate
questions should probably be asked on the corresponding product-specific
lists (from the extension functions I guess you are using eXist).

Wolfgang


> Hello All,
> 
> I am facing a small problem with Xupdate. 
> 
> I have a xml file 
> 
> <maps>
> 
> <map>
> <prereq></prereq>
> <main></main>
> <result></result>
> </map>
> .
> .
> .
> </maps
> 
> 
> I am populating this xml file from a form using Xupdate. Below is the
> bit of code for this -
> _______________________________________
> let $updt:=  
> 	
> 	<xupdate:modifications version="1.0"
> 	          xmlns:xupdate="http://www.xmldb.org/xupdate" >    
> 	 <xupdate:append select="doc('/db/content/map1.xml ')/maps">    
>       <xupdate:element name="map"></xupdate:element>       
> 	   </xupdate:append> 
> 	</xupdate:modifications> 
> 
> let $dummy:= xmldb:update($collection, $updt)
> 
> (: creates a new /map node in the xml file :)
> 
> (: update user inputs into /maps/map :)
> 
>             let $xupdate :=
>                                         <xupdate:modifications
> version="1.0"
>  
> xmlns:xupdate="http://www.xmldb.org/xupdate" >
>                       <xupdate:append
> select="doc('/db/content/map1.xml')/maps/map">
>                                       <xupdate:element
> name="prereq">{$prereq}</xupdate:element>
>                                       <xupdate:element
> name="main">{$main}</xupdate:element>
>                                      <xupdate:element
> name="resultt">{$result}</xupdate:element>
>                                       
>                       </xupdate:append>
>                     </xupdate:modifications>
>                                             
> (: update the collection :)                                           
> 
> let $dummy2:= xmldb:update($collection, $xupdate)
> 
> _______________________________________
> 
> 
> This works fine but the only problem is that every time it goes and
> updates each map node with the content and also creates a new map node.
> 
> 
> So if I had 
> 
> <maps>
> 
> <map>
> <prereq>test </prereq>
> <main>test2</main>
> <result>test3</result>
> </map>
> .
> .
> .
> </maps
> 
> And I input a new node
> 
> Prereq - tes5
> Main - test6
> Result - test7
> 
> The result is
> 
> <maps>
> 
> <map>
> <prereq>test </prereq>
> <main>test2</main>
> <result>test3</result>
> 
> <prereq>test5 </prereq>
> <main>test6</main>
> <result>test7</result>
> 
> </map>
> .
> <map>
> <prereq>test5 </prereq>
> <main>test6</main>
> <result>test7</result>
> 
> </map>
> .
> .
> </maps
> 
> 
> 
> Is there a way in which I can add a new node and not change/add to the
> existing nodes in the xml file?
> 
> 
> Thanks and Regards
> Titash



More information about the talk mailing list