Skip to content

Commit

Permalink
fix and improve query
Browse files Browse the repository at this point in the history
which was failing with "HTTP ERROR 500 javax.servlet.ServletException: javax.servlet.ServletException: An error occurred while processing request to /modules/tools/location_index.xq: An error occurred: class org.exist.xquery.value.ValueSequence cannot be cast to class org.exist.dom.persistent.NodeSet (org.exist.xquery.value.ValueSequence and org.exist.dom.persistent.NodeSet are in unnamed module of loader 'app')"
  • Loading branch information
peterstadler committed Jan 4, 2024
1 parent 0672ad4 commit 167618c
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions modules/tools/location_index.xq
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ declare namespace loop="http://kb.dk/this/getlist";
declare namespace request="http://exist-db.org/xquery/request";
declare namespace response="http://exist-db.org/xquery/response";
declare namespace fn="http://www.w3.org/2005/xpath-functions";
declare namespace file="http://exist-db.org/xquery/file";
declare namespace util="http://exist-db.org/xquery/util";
declare namespace ft="http://exist-db.org/xquery/lucene";
declare namespace ht="http://exist-db.org/xquery/httpclient";
(:declare namespace file="http://exist-db.org/xquery/file";:)
(:declare namespace util="http://exist-db.org/xquery/util";:)
(:declare namespace ft="http://exist-db.org/xquery/lucene";:)
(:declare namespace ht="http://exist-db.org/xquery/httpclient";:)
declare namespace marc="http://www.loc.gov/MARC21/slim";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";

declare namespace local="http://kb.dk/this/app";
(:declare namespace local="http://kb.dk/this/app";:)
declare namespace m="http://www.music-encoding.org/ns/mei";

import module namespace config="https://github.com/edirom/mermeid/config" at "../config.xqm";
Expand Down Expand Up @@ -44,7 +44,6 @@ declare function loop:sort-key ($identifier as xs:string) as xs:string
declare function loop:lookup ($location as xs:string) as xs:string
{
let $country_code:=substring-before($location,'-')
let $filename:=concat($country_code,'.xml')
let $txt:=
if($country_codes/m:list/m:li/m:geogName[@codedval=$country_code])
then
Expand Down Expand Up @@ -86,24 +85,23 @@ declare function loop:lookup-archive ($location as xs:string, $country_code as x
<p>Please choose a file collection/catalogue by adding &apos;?c=[your collection name]&apos;
(for instance, ?c=CNW) to the URL</p>
else
for $c in distinct-values(
for $c in
collection($database)/m:mei/m:meiHead[m:fileDesc/m:seriesStmt/m:identifier[@type="file_collection"] = $collection]/
m:manifestationList/m:manifestation//m:physLoc/m:repository/
(m:identifier[@authority='RISM' and normalize-space(.)] | m:corpName[normalize-space(.)]) )
order by normalize-space(string($c))
(m:identifier[@auth='RISM' and normalize-space(.)] | m:corpName[normalize-space(.)])
group by $ident := normalize-space($c)
order by loop:lookup($ident)
return
<div>
{concat(loop:lookup($c),' &#160; ',$collection,' ')}
{concat(loop:lookup($ident),' &#160; ',$collection,' ')}
{let $numbers :=
for $n in collection($database)/m:mei/m:meiHead[m:fileDesc/m:seriesStmt/m:identifier[@type="file_collection"] = $collection]
where $n/m:manifestationList/m:manifestation//m:physLoc/m:repository/
(m:identifier[@authority='RISM' and normalize-space(.)] | m:corpName[normalize-space(.)]) = $c
order by loop:sort-key($n/m:workList/m:work/m:identifier[@label=$collection]/string())
return $n/m:workList/m:work/m:identifier[@label=$collection]/string()
for $n in $c
let $number := $n/ancestor::m:meiHead/m:workList/m:work/m:identifier[@label=$collection] => normalize-space()
order by loop:sort-key($number)
return $number
return string-join($numbers,', ')
}
</div>

}
</div>

Expand Down

0 comments on commit 167618c

Please sign in to comment.