xquery version "1.0"; declare namespace request="http://exist-db.org/xquery/request"; declare namespace util="http://exist-db.org/xquery/util"; declare namespace dc="http://purl.org/dc/elements/1.1/"; declare namespace i18n="http://apache.org/cocoon/i18n/2.1"; import module namespace ristenutil="http://www.risten.no/shared/util" at "../xquery/ristenutil.xqm"; (: Create filter expression from query term, field and mode :) declare function local:filter-expr($record as xs:string) as xs:string { let $t := concat("'", $record, "'") return concat("@id = ", $t) }; (: Assemble the query string :) declare function local:build-query($record as xs:string, $collID) as xs:string { let $expr := local:filter-expr($record), $collpath := ristenutil:get-collection($collID), $docs := concat($collpath, "/termcenter.xml") return concat("for $r in document('", $docs, "')//entry[", $expr, "] return $r") }; (: Modify/enhance the query results before display: Main purpose: to add classification labels, and to remove unwanted senses before display. Does not work due to limitations in eXist (XIncludes are not expanded until serialisation time - thus not available for inspection at this point. Solution: Only classification labels added, the sense filtering is deferred to XSLT processing, when the XIncludes are available :) declare function local:display($hits as node()+) as element() { let $current := item-at($hits, 1), $top := $current/topicClass/@top, $mid := $current/topicClass/@mid, $botm := $current/topicClass/@botm, $count := count($current/entryref) return { for $p in 1 to $count let $entry := item-at($current/entryref, $p), $lang := $entry/@xml:lang, $common := $entry return {$common (: , for $sense in $entry/senses/sense let $sensetop := $sense/topicClass/@top, $sensemid := $sense/topicClass/@mid, $sensebotm := $sense/topicClass/@botm return if ( ($top = $sensetop) and ($mid = $sensemid) and ($botm = $sensebotm) ) then $sense else () :) } } }; (: Main function - retrieves some request attributes, forks further processing to other defined functions depending on the retrieved values :) declare function local:main() as element()+ { let $record := request:get-parameter("record", ""), $collID := request:get-parameter("collection", "") return if(string-length($record) = 0) then

WARNING: There was an error with this request! Please check with the webmaster. Cause: No request record value.

else let $query := local:build-query($record, $collID), $hits := util:eval( $query ) return if (empty($hits)) then (

ERROR! Record {$record} not found!

,

Your search query:

) else ( (:

Your search query:

, :) $hits (: local:display($hits) :) ) }; (: The double style declaration is needed to work around an unidentified bug that appears in MS IE/Win - the last CSS import statement in the import / inheritance chain, risten.css, is not applied, leading to a mostly unstyled term record display. Thus, it is explicitly added here. It is declared first, to let overriding styles in the regular CSS chain take precedence. In other browsers than IE, it means that risten.css is read twice, which is unneccessary but unproblematic. :)