Juan
Juan

Reputation: 532

XQUery collections: deleting?

I am new to xquery, and I am trying to use a collection to reload my webpage and keep some information. My problem is after I create the collection and save my node using (sausalito) the collection stays alive even afterI close the program. Next time I use the collection it has nodes already in it. I only need the collection to save a node, then reload website and delete node. Problem is that I am not able to delete the collection or the nodes. I tried using delete-nodes() and other methods from http://www.zorba-xquery.com/doc/zorba-1.4.0/zorba/xqdoc/xhtml/www.zorba-xquery.com_modules_xqddf.html#delete-index-1

What I have

declare collection resultview:collection as node()*;
declare variable $resultview:collection as xs:QName := xs:QName("resultview:collection");
declare sequential function resultview:add($allMovies as element(movies))
{
for $movie in $allMovies
return xqddf:insert-nodes($resultview:collection, $allMovies);
fn:trace(xqddf:collection($resultview:collection), "Collection data: "),
exit returning resultview:list();
};
declare sequential function resultview:deleteList() {
    let $a := ""
    return  xqddf:delete-index($resultview:collection);
    exit returning resultview:list();
};

Upvotes: 2

Views: 257

Answers (1)

Dennis Münkle
Dennis Münkle

Reputation: 5071

if I do understand you correctly, this should work:

declare collection resultview:collection as node()*;
declare variable $resultview:collection as xs:QName := xs:QName("resultview:collection");

declare sequential function resultview:add($allMovies as element(movies))
{
  xqddf:insert-nodes($resultview:collection, $allMovies);
  resultview:list();
};

declare sequential function resultview:deleteList() {
  xqddf:delete-nodes(
    $resultview:collection,
    xqddf:collection($resultview:collection));
  resultview:list();
};

use delete-nodes instead of delete-index (the latter deletes a complete index and not a node at a specific index position).

does that help?

Upvotes: 2

Related Questions