On Fri, Nov 27, 2020 at 04:38:42AM +0100, Giuseppe G. A. Celano scripsit:
What I was looking for is a “quick way” to get a comparison such that an item (when it is repeated more than once) is returned only as many times as it appears in both sequences.
I don't know if it's quick, and I don't know if I understand the requirements, but resorting to maps seems to work:
let $occursMap as function(*) := function($in as xs:integer+) { map:merge( for $item in $in let $key as xs:integer := $item group by $key (: where $item[2] :) return map:entry($key,$item => count()) ) }
let $a as xs:integer+ := (1,2,3,5,3,3) let $k as xs:integer+ := (1,3,2,3,2)
let $aMap as map(xs:integer,xs:integer) := $occursMap($a) let $aKeys as xs:integer+ := $aMap => map:keys()
let $kMap as map(xs:integer,xs:integer) := $occursMap($k) let $kKeys as xs:integer+ := $kMap => map:keys()
return for $each in $aKeys[. = $kKeys] return (1 to min(($aMap($each),$kMap($each)))) ! $each
If you need to restrict this to "and they have to occur multiple times in the sequence" as well as "occurs in both sequences", uncomment "where $item[2]".