(:
    Module: Language menus.
            Returns all available languages for a dictionary,
            or for all collections if input argument is "all".
:)
module namespace langmenu="http://www.risten.no/shared/langmenu";
declare namespace util="http://exist-db.org/xquery/util";
(: Get all language codes registered in all or the specified collection :)
(: Returns a sequence of empty elements with the following structure:
   
:)
declare function langmenu:get-termlangs($coll as xs:string) as element()
{
  	let $langs := if ($coll = "all") then
  					/termmeta/langs/*
  				  else
  				    collection($coll)/termmeta/langs/*
    return
      
      {
        for $r in distinct-values($langs)
        order by $r descending
        return 
      }
      
};