xquery version "1.0";
declare option exist:serialize "expand-xincludes=no";
declare namespace session="http://exist-db.org/xquery/session";
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:save-entry( $classID as xs:string,
$lang as xs:string)
as xs:string
{
let $coll := ristenutil:get-collection(),
$label:= request:get-parameter("label", "")
return (
if ( collection($coll)//*[@id eq $classID]/* ) then
(: We want new labels to be added after existing ones... :)
if ( collection($coll)//*[@id eq $classID]/label ) then
update insert
following
collection($coll)//*[@id eq $classID]/label[last()]
(: ... but before sublevels (micro/nano) when there are no labels: :)
else
update insert
preceding
collection($coll)//*[@id eq $classID]/*[1]
(: When there are no labels or sublevels, it is just inserted: :)
else
update insert
into
collection($coll)//*[@id eq $classID]
,
"true")
};
(: Assemble the query string :)
declare function local:build-query($id as xs:string,
$lang as xs:string)
as xs:string
{
let $coll := ristenutil:get-collection()
return
concat("for $r in collection('",
$coll,
"')//label[../@id eq '",
$id,
"'][@xml:lang eq '",
$lang,
"'] return $r")
};
(: Present an overview of query results :)
declare function local:displayHitlist($hits as node()+, $classID as xs:string)
as element()
{
let $lang := request:get-parameter("showlang", "all"),
$collID:= session:get-attribute("collection"),
$classlangs := ristenutil:get-class-langs( $collID )
return
{$query}
) else ( (: DEBUG only - output some extra info :) (:Your session attributes: {$session}
Your request attributes: {$request}
Your old/short search query: {$queryOld}
Your complete search query:
{$query}
{$query}
, :) local:displayHitlist($hits, $class) ) };