(: Module: Dictionary menu building for the search interface. Returns all available dictionaries and terminology collections. :) module namespace dictmenu="http://www.risten.no/shared/dictmenu"; declare namespace util="http://exist-db.org/xquery/util"; declare namespace xmldb="http://exist-db.org/xquery/xmldb"; (: Get ID, coll, and classification ID for all available term collections. :) (: Availability is checked against user credentials and access permisions. :) (: Returns an element containing a sequence of empty elements with the following structure: ... :) declare function dictmenu:get-termcolls($user as xs:string) as element()+ { let $count := count(/termmeta) let $groups := if ($user = "all") then /termmeta/id/text() else ( /auth/users/user[@name=$user]/group ) return (: $count is the count of all existing collections, not only those available to the current user. This could be reconsidered, if needed. :) { for $r in /termmeta let $coll := util:collection-name($r) let $collgroup := xmldb:get-group($coll) return (: we need to lower-case the ID string - groups are always lower-case :) if (contains( $groups, lower-case($r/id/text()) ) ) then (: when the group is different from the Coll. ID, use the group of the collection :) else if (contains( $groups, $collgroup ) ) then else if (contains( $groups, $r/id/text() ) ) then (: but not when the user is 'all' :) else () } }; (: Get ID, and collection for all available dictionaries. :) (: Availability is checked against user credentials and access permisions. :) (: Returns an element containing a sequence of empty elements with the following structure: ... :) declare function dictmenu:get-dictcolls($user as xs:string) as element()+ { let $count := count(/dictmeta) let $groups := if ($user = "all") then /dictmeta/id/text() else ( /auth/users/user[@name=$user]/group ) return (: $count is the count of all existing collections, not only those available to the current user. This could be reconsidered, if needed. :) { for $r in /dictmeta let $coll := util:collection-name($r) let $collgroup := xmldb:get-group($coll) return (: we need to lower-case the ID string - groups are always lower-case :) if (contains( $groups, lower-case($r/id/text()) ) ) then (: when the group is different from the Coll. ID, use the group of the collection :) else if (contains( $groups, $collgroup ) ) then else if (contains( $groups, $r/id/text() ) ) then (: no lowercase when the user is 'all' :) else () } }; (: Get ID, and collection for all available classification schemes. :) (: Availability is checked against user credentials and access permisions. :) (: Returns an element containing a sequence of empty elements with the following structure: ... :) declare function dictmenu:get-classcolls($user as xs:string) as element()+ { let $count := count(/classmeta) let $groups := if ($user = "all") then /classmeta/id/text() else ( /auth/users/user[@name=$user]/group ) return (: $count is the count of all existing class collections, not only those available to the current user. This could be reconsidered, if needed. :) { for $r in /classmeta let $coll := util:collection-name($r) let $collgroup := xmldb:get-group($coll) return (: we need to lower-case the ID string - groups are always lower-case :) if (contains( $groups, lower-case($r/id/text()) ) ) then (: when the group is different from the Coll. ID, use the group of the collection :) else if (contains( $groups, $collgroup ) ) then else if (contains( $groups, $r/id/text() ) ) then (: no lowercase when the user is 'all' :) else () } };