Mercurial > hg > mpdl-group
diff software/eXist/webapp/mpdl/interface/xquery.xql @ 7:5589d865af7a
Erstellung XQL/XSL Applikation
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 08 Feb 2011 15:16:46 +0100 |
parents | |
children | d6f528ad5d96 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/software/eXist/webapp/mpdl/interface/xquery.xql Tue Feb 08 15:16:46 2011 +0100 @@ -0,0 +1,98 @@ +xquery version "1.0"; + +declare namespace request = "http://exist-db.org/xquery/request"; +declare namespace util = "http://exist-db.org/xquery/util"; +declare namespace echo="http://www.mpiwg-berlin.mpg.de/ns/echo/1.0/"; + +(: ToDo wenn eine pn gegeben ist (also im Fragment untersucht werden soll) geht es momentan nicht s.u. :) +(: ToDo wenn eine pn gegeben ist, wird momentan der namespace ignoriert wie z.B. xquery=//echo:s&pn=14 :) +let $xQuery := request:get-parameter("xquery", "") +let $xQueryPath := request:get-parameter("xqueryPath", "") +let $mpdlDocUri := request:get-parameter("document", "") +let $pn := number(request:get-parameter("pn", "-1")) +let $startRecord := number(request:get-parameter("startRecord", "1")) +let $maximumRecords := number(request:get-parameter("maximumRecords", "-1")) +let $output := request:get-parameter("output", "") +let $options := request:get-parameter("options", "") + +let $documentName := substring-before(substring-after(substring-after(substring-after($mpdlDocUri, "/"), "/"), "/"), ".") +let $docbase := substring-before(substring-after($mpdlDocUri, "/"), "/") +let $fullDocumentUri := concat('/db/mpdl/documents/morph', $mpdlDocUri) +let $document := doc($fullDocumentUri) +let $pageBreaks := + if ($docbase = 'archimedes') + then $document//pb + else if ($docbase = 'echo') + then $document//echo:pb + else $document//pb +let $countPBs := count($pageBreaks) +let $pb1 := subsequence($pageBreaks, $pn, 1) +let $pb2 := subsequence($pageBreaks, $pn + 1, 1) +let $pageFragmentStr := + if ($pn != -1 and $countPBs > 0) + then util:get-fragment-between($pb1, $pb2, true()) + else if ($pn != -1 and $countPBs = 0) + then "" + else "" +let $pageFragment := + if ($countPBs > 0) + then util:parse($pageFragmentStr) + else $document +(: ToDo im Fragment geht es nur mit vorn angehÃĪngtem Punkt. Das gibt aber Probleme, wenn es komplizierte XQueries gibt: let $xPathFragment := concat(".", $xpath) :) +let $resultEval := + if ($xQueryPath != "" and $document != "" and $pn > 0) + then util:eval-inline($pageFragment, $xQueryPath) + else if ($xQueryPath != "" and $document != "" and $pn = -1) + then util:eval-inline($document, $xQueryPath) + else if ($xQueryPath != "" and $mpdlDocUri = "") + then util:eval($xQueryPath) + else if ($xQueryPath = "" and $document != "" and $pn > 0) + then util:eval-inline($pageFragment, $xQuery) + else if ($xQueryPath = "" and $document != "" and $pn = -1) + then util:eval-inline($document, $xQuery) + else if ($xQueryPath = "" and $mpdlDocUri = "") + then util:eval($xQuery) + else () +let $size := count($resultEval) +let $from := $startRecord +let $to := + if ($maximumRecords != -1) + then $startRecord + $maximumRecords - 1 + else $size +let $resultEvalPage := + for $entry at $pos in $resultEval + where $pos >= $from and $pos <= $to + return + <record> + <id>{$pos}</id> + <content>{$entry}</content> + </record> + +let $resDocument := + if ($document != '' and $pn != -1) + then <document><id>{$mpdlDocUri}</id><pn>{$pn}</pn></document> + else if ($document != '' and $pn = -1) + then <document><id>{$mpdlDocUri}</id></document> + else '' +let $result := + <result> + <xquery>{$xQuery}</xquery> + {$resDocument} + <queryResult> + <size>{$size}</size> + <startRecord>{$startRecord}</startRecord> + <maximumRecords>{$maximumRecords}</maximumRecords> + <records> + {$resultEvalPage} + </records> + </queryResult> + </result> + + + +let $declare := + if ($output != "html") + then util:declare-option("exist:serialize", "method=xml media-type=text/xml omit-xml-declaration=no indent=yes encoding=utf-8") + else util:declare-option("exist:serialize", "method=html media-type=text/html omit-xml-declaration=no indent=yes encoding=utf-8") + +return $result \ No newline at end of file