/* (Q9) List the number of items auctioned each month in 1999 for which data is available, ordered by month. */ import match as UDF_match; FUNCTION getMonth($date) { match("[0-9]+-([0-9]+)-[0-9]+", $date)[1] } FUNCTION getMonths( $dates ) { FOR $date IN $dates RETURN getMonth($date) } FUNCTION getYear( $date ) { match("([0-9]+)-[0-9]+-[0-9]+", $date)[1] } ( FOR $m IN DISTINCT getMonths( document("items.xml")//item_tuple/end_date ) LET $item := document("items.xml")//item_tuple[getYear(end_date) = 1999 AND getMonth(end_date) = $m] RETURN NUMFORMAT("##", $m) , NUMFORMAT("###", count($item)) SORTBY (month) )