xquery version "1.0"; declare namespace request="http://exist-db.org/xquery/request"; declare namespace util="http://exist-db.org/xquery/util"; declare namespace i18n="http://apache.org/cocoon/i18n/2.1"; import module namespace ristenutil="http://www.risten.no/shared/util" at "../xquery/ristenutil.xqm"; (: Assemble the query string :) declare function local:build-query($record as xs:string, $lang as xs:string) as xs:string { let $doc := ristenutil:get-doc($lang) return concat("for $r in document('", $doc, "') //entry[@id &= '", $record, "'] return $r") }; (: Modify the query results before display - in this case just add the language of the entry: :) declare function local:display($entrylang as xs:string, $hits as node()+) as element() { let $entry := item-at($hits, 1), $rest := $entry/*, $id := $entry/@id return {$rest} }; (: 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 $entrylang := request:get-parameter("entrylang", ""), $request := request:get-parameter("request", "") return if(string-length($request) = 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($request, $entrylang), $hits := util:eval( $query ) return if (empty($hits)) then (

ERROR! Record {$request} not found!

,

Your language: {$entrylang}

,

Your request: {$request}

,

Your search query:

) else ( local:display($entrylang, $hits) ) };