XQuery Short exercises

Rolling months

This problem was triggered by an article in The Daily WTF. It shows a function manipulating Lists of Months in a rather clumsy way. It appears that the function generates the sequence of Months starting anywhere in the year and wrapping round i.e. if month=6 then we get the sequence from June back to May.

Here it is in XQuery:

declare variable $local:months := ("January","Febrary","March","April","May","June","July","August","September","October","November", "December");
declare function local:rolling-months($start as xs:integer)  as xs:string+ {
       ($local:months,$local:months)[position() >= $start][position()<=12]
};        
        

Months June to May

Explanation