Thanks a lot.
I'm really wondering how I was able to overlook "head" and "tail" .... maybe the age .... :-(

M.

On 05/20/2013 03:44 PM, Jens Erat wrote:
hi Marco,

using recursion is easily possible (and the only way to solve that problem 
without using maps), just write a small XQuery function like

   declare function local:interprete($operations as item()*, $set as item()*) 
as item()* {
     let $op := head($operations)
     let $ops := tail($operations)
     let $intermediate :=
       switch($op/@operator)
         case "UNION" return ($set, $op/item[not(@name = $set/@name)])
         case "INTERSECT" return $set[@name = $op/item/@name]
         case "DIFFERENCE" return $set[not(@name = $op/item/@name)]
         default return error()
     return
       if ($ops)
       then
         local:interprete($ops, $intermediate)
       else $intermediate
   };

Which you would call using `local:interpret(//set, ())`. I guess the code 
should be small enough to be self-explaining. I seems to work, but I didn't 
test with much more than the input you provided, better do some additional 
tests on production data before using it.

If you want to compare whole nodes instead of their name attribute, use 
`fn:deep-equal()` instead of the name comparisons. You will have to use some 
explicit loop, [quantified expressions] should get handy for that.

Regards from Lake Constance, Germany,
Jens Erat

[quantified expressions]: 
http://www.w3.org/TR/xpath20/#id-quantified-expressions


_______________________________________________
BaseX-Talk mailing list
[email protected]
https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk

Reply via email to