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"; (: 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, $entrylang as xs:string) as xs:string { let $expr := local:filter-expr($record), $doc := concat('/db/ordbase/terms/SD-terms/terms-',$entrylang,'.xml') return concat("for $r in document('", $doc, "')//entry[", $expr, "] return $r") }; (: 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 $quotedrecord := request:get-parameter("record", ""), $entrylang := request:get-parameter("entrylang", ""), $record := substring-before(substring($quotedrecord,2), "'"), $centerid := request:get-parameter("termid", ""), $otherlangs := count( document('/db/ordbase/terms/SD-terms/termcenter.xml') //entry[@id = $centerid] /entryref[@xml:lang != $entrylang] ) 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, $entrylang), $hits := util:eval( $query ), $numofsenses := count($hits//sense) return if (empty($hits)) then (

ERROR! Record {$record} not found!

,

Your language: {$entrylang}

,

Your request: {$record}

,

Your search query:

) else ( (: DEBUG:

Your search query:

, :) ristenutil:display($entrylang, $hits, $centerid), if ( $otherlangs > 0 ) then

There are other languages in the term record, only this language will be deleted

else

There are no other languages in the related term record, the whole term record will be deleted

, if ( $numofsenses > 1 ) then

There are other senses of this entry, only this sense will be deleted.

else

There are no other senses for the entry word, the whole dictionary entry will be deleted!

) };
{ let $start := util:system-time() return ( local:main(),

SearchTime { round-half-to-even( seconds-from-duration( util:system-time()-$start) , 3)}

) }