Hi, I would like to have a nested xquery, but I am not sure if this is possible at all: When a user searches the corpus, he can save the hits he likes most. The result for the query is a form with checkboxes. The node IDs together with the query and a time stamp are saved in a second collection. This collections looks like this: <collection> <entry time="2012-03-04T17:24:53"> <node>1434455</node> <query>[text() contains text ('Daumen' ftand 'Auge' ftand 'halten') using stemming using language "de" distance at most 10 words ordered]</query> <person>xyz</person> <phraseme>Ad0024</phraseme> <selected>yes</selected> </entry> <entry time="2012-03-04T17:24:53"> <node>1475764</node> <query>[text() contains text ('Daumen' ftand 'Auge' ftand 'halten') using stemming using language "de" distance at most 10 words ordered]</query> <person>abc</person> <phraseme>Ad0024</phraseme> <selected>no</selected> </entry> </collection> When the user searches again with a different query, he will see the results as for the first search and is able to save only those that are not in the hit-collection. This is controlled by this part in the "return" part of the xquery in my perl client: { if (not (db:open("collect")//node[text() = \$node and ../phraseme[text() = "$phraseme"] and ../selected[text() = "yes"]])) then <input type="checkbox" name="NODE" value="{\node}"/> else "X" } Already saved hits get an "X" and new hits get the checkbox. For documentation, I would like to collect all queries a node could be found with. Thus, instead of printing "X", I would like to add an additional query-element to the entry-element, i.e., something like insert node <query>$query</query> after /collection/entry/node[text() = "\$node" and ../phraseme[text() = "$phraseme" and ../selected[text() = "yes"]]] to get: <collection> <entry time="2012-03-04T17:24:53"> <node>1434455</node> <query>[text() contains text ('Daumen' ftand 'Auge' ftand 'halten') using stemming using language "de" distance at most 10 words ordered]</query> <query>[text() contains text ('Daumen' ftand 'Auge') using stemming using language "de" distance at most 10 words ordered]</query> <query>[text() contains text ('Daumen' ftand 'Auge') distance at most 10 words ordered]</query> <person>xyz</person> <phraseme>Ad0024</phraseme> <selected>yes</selected> </entry> <entry time="2012-03-04T17:24:53"> <node>1475764</node> <query>[text() contains text ('Daumen' ftand 'Auge' ftand 'halten') using stemming using language "de" distance at most 10 words ordered]</query> <person>abc</person> <phraseme>Ad0024</phraseme> <selected>no</selected> </entry> </collection> However, I am not sure if it is possible at all to mix displaying (in the "then" part) and updating (in the "else" part) -- although I would like to update a different collection than I am searching. If it is possible, I guess I have to include the name of the collection for insertion by using db:open? Is it necessary to specify the exact place for insertion (as in my example) as this should be already determined by the condition? Best regards Cerstin -- Dr. phil. Cerstin Mahlow Universität Basel Deutsches Seminar Nadelberg 4 4051 Basel Schweiz Tel: +41 61 267 07 65 Fax: +41 61 267 34 40 Mail: cerstin.mahlow@unibas.ch Web: http://www.oldphras.net