define function checkraised ($x) { if (exists(subsequence($x,3))) then ( if (int($x[2]/text()) > int($x[1]/text())) then ( $x[1] ) else ( checkraised(subsequence($x,2)) ) ) else () } define function raised ($empno, $start, $end) { for $x in document('v-emps.xml')/employees/employee[empno=$empno] for $y in $x/salary[((date(@tstart) >= $start) and (date(@tstart) <= $end)) or ((date(@tend) >= $start) and (date(@tend) <= $end)) or ((date(@tstart) <= $start) and (date(@tend) >= $end))] return $y } for $x in document('v-emps.xml')/employees/employee let $start := $x/title[position()=1]/@tstart let $end := $x/title[position()=2]/@tstart let $empno := $x/empno/text() where $x/title[last() > 1] and empty (checkraised(raised($empno,date($start),date($end)))) return $x