Changes

Jump to navigation Jump to search
62 bytes added ,  17:08, 1 March 2011
no edit summary
The node element with @id=1 is copied and subsequently assigned a new QName using the rename expression. Note that the transform expression is the only expression which returns an actual XDM instance as a result. You can therefor use it to modify results and especially DOM nodes. This is an issue beginners are often confronted with. More on this topic can be found in the [[Update#Returning Results|XQUF Concepts]] section.
The following example gives another example. The <entry> element (here it is passed to the expression as a DOM node) can also be replaced by a database node (e.g. copy $c := (db Query:open('example')//entry)[1]). In this case, the original database node remains untouched as all updates are performed on a copy.
<pre class="brush:xquery">
</entry>
</pre>
 
The <entry> element (here it is passed to the expression as a DOM node) can also be replaced by a database node, e.g.:
 
<pre class="brush:xquery">
copy $c := (db:open('example')//entry)[1])
...
</pre>
 
In this case, the original database node remains untouched as well, as all updates are performed on the node copy.
===Functions===
;Database node as target:
:Result file 'doc.xml': <pre class="brush:xml"><n id='1'/></pre>:Query: <pre class="brush:xquery">insert node attribute id { '0' } into doc('doc.xml')//n</pre>
:Result: <pre style='color:red'>[XUDY0021] Duplicate attribute "id".</pre>
;Serializing a modified DOM node:
:Query:
<pre class="brush:xquery">
put(
return $node, 'doc.xml')
</pre>
:Result file 'doc.xml':
<pre class="brush:xml">
<n><x/></n>
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu