(: Helper functions :)
declare function local:distinct($a) {
$a[index-of($a,.)[1]]
};
(: Group 1 :)
(: ** which building has the most courses? :)
let $list := (
let $buildings := (
for $courses in //course
return $courses//building)
for $building in distinct-values($buildings)
return $building)
for $b in $list
return {$b}, {count(//building[text() eq $b])}
(:Group 2 :)
(: ** which instructor in a building has the earliest courses :)
let $all = //courses
let $blist = distinct-values(//courses//building)
for $b1 in $blist
let $timelist = (for $b2 in $all
where $b1 = $b2//building
let $t = $b2//time/start_time[matches(. , 'AM')]
order by $t
return $t)
let $instr = $timelist[1]/ancestor::course/instructor
return $instr
(: Group 5 :)
(: * list all courses that start before 10am :)
for $c in //course
where $c//start_time < "10:00AM" and substring($c//start_time, 6, 2) = "AM"
return {$c}
(: * name all instructors that teach at least three courses :)
let $i := local:distinct(//instructor)
for $t in $i
where count(//course[./instructor=$t]) >= 3
return {$t}
(: Group 6 :)
(: ** Which building has the most rooms? :)
let $total:=(
for $b in local:distinct(//building)
let $c := //place[./building = $b]
let $count := count($c/room)
return
{$b/text()}
{$count}
)
let $maxcount := max($total//count)
return $total[count = $maxcount]/bl
(: ** what courses are taught in a given room in a given building and when?
** (you can pick a room/building that s interesting). :)
for $cs in //course[.//building/text()='PHYSIC' and .//room/text()='134']
return {$cs//title,$cs//time}