index-processor.xqm 44.5 KB
Newer Older
Mathias Goebel's avatar
Mathias Goebel committed
1
xquery version "3.1";
Mathias Goebel's avatar
Mathias Goebel committed
2
3
(:~
: This module prepares the index html.
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
4
5
6
: It is used for preparing a cached version and also called when preparing
: the index for a single notebook.
: The corresponding viewer module is `index-viewer.xqm`.
Mathias Goebel's avatar
Mathias Goebel committed
7
8
9
10
: @author Mathias Göbel
: @version 1.0
: @see https://fontane-nb.dariah.eu/register.html
:)
Mathias Goebel's avatar
Mathias Goebel committed
11
module namespace f-indexproc="http://fontane-nb.dariah.eu/indexproc";
12
import module namespace code="http://bdn-edition.de/ns/code-view";
Mathias Goebel's avatar
minor    
Mathias Goebel committed
13
14
15
import module namespace config="http://textgrid.de/ns/SADE/config" at "../config/config.xqm";

import module namespace f-misc="http://fontane-nb.dariah.eu/ns/SADE/misc" at "misc.xqm";
16

17
declare namespace foaf="http://xmlns.com/foaf/0.1/";
18
declare namespace gndo="http://d-nb.info/standards/elementset/gnd#";
Mathias Goebel's avatar
Mathias Goebel committed
19
20
declare namespace ore="http://www.openarchives.org/ore/terms/";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
Mathias Goebel's avatar
Mathias Goebel committed
21
declare namespace tei="http://www.tei-c.org/ns/1.0";
Mathias Goebel's avatar
Mathias Goebel committed
22
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
Mathias Goebel's avatar
Mathias Goebel committed
23
declare namespace xhtml="http://www.w3.org/1999/xhtml";
Mathias Goebel's avatar
Mathias Goebel committed
24

Mathias Goebel's avatar
Mathias Goebel committed
25
26
declare variable $f-indexproc:metaCollection := '/db/sade-projects/textgrid/data/xml/meta/';
declare variable $f-indexproc:targetStart := "http://textgridrep.org/textgrid:";
Mathias Goebel's avatar
   
Mathias Goebel committed
27
28
29
30
(: try/catch here, to pass the tests when no request object is available :)
declare variable $f-indexproc:getEntity := try {request:get-parameter('e', '')} catch * {""};
declare variable $f-indexproc:getIndex := try {request:get-parameter('i', '')} catch * {""};
declare variable $f-indexproc:notebookParam := try {request:get-parameter('nb', '')} catch * {""};
Mathias Goebel's avatar
Mathias Goebel committed
31
32
33
34
35
declare variable $f-indexproc:getNotebook := $f-indexproc:targetStart || $f-indexproc:notebookParam;

declare variable $f-indexproc:dataPath := '/db/sade-projects/textgrid/data/xml/data/';
declare variable $f-indexproc:dataCollection := collection($f-indexproc:dataPath);

36
declare variable $f-indexproc:BeaconMap := map:merge((
Mathias Goebel's avatar
Mathias Goebel committed
37
        local:beacon-parser(xs:anyURI("http://www.historische-kommission-muenchen-editionen.de/beacon_db_register.txt")),
38
39
40
        local:beacon-parser(xs:anyURI("http://www.historische-kommission-muenchen-editionen.de/beacon_ndb.txt")),
        local:beacon-parser(xs:anyURI("http://www.historische-kommission-muenchen-editionen.de/beacon_adb.txt"))
        ));
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
41
42
43
(:~
 : Helper function to collect all main nodes from the index files.
:)
Mathias Goebel's avatar
Mathias Goebel committed
44
declare function local:getNodes()
Mathias Goebel's avatar
   
Mathias Goebel committed
45
as array(*) {
Mathias Goebel's avatar
Mathias Goebel committed
46
47
48
49
50
51
let $agg := '253st.xml' (: TextGrid Aggregation containing all index files :)
let $uris := (doc('/db/sade-projects/textgrid/data/xml/agg/' || $agg)
          //ore:aggregates/substring-after(@rdf:resource, 'textgrid:')
        )[. != "25547"] (: omit the bibliography here :)
let $docs := $uris ! doc($f-indexproc:dataPath || . || '.xml')

Mathias Goebel's avatar
   
Mathias Goebel committed
52
return
Mathias Goebel's avatar
Mathias Goebel committed
53
    [
Mathias Goebel's avatar
Mathias Goebel committed
54
    $docs//tei:body/tei:listEvent,
Mathias Goebel's avatar
Mathias Goebel committed
55
    $docs//tei:body/tei:listOrg,
Mathias Goebel's avatar
Mathias Goebel committed
56
57
58
59
    $docs//tei:body/tei:listPerson,
    $docs//tei:body/tei:listPlace,
    $docs//tei:body//tei:list[@type="works"],
    $docs//tei:body//tei:list[@type="periodicals"],
Mathias Goebel's avatar
   
Mathias Goebel committed
60
    $docs//tei:body//tei:list[@type="Fontane"]
Mathias Goebel's avatar
Mathias Goebel committed
61
    ]
Mathias Goebel's avatar
Mathias Goebel committed
62
63
64
};

(:~
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
65
66
67
68
69
70
71
 : the list type an entity is listed in.
 : This is used when preparing the html resource name.
 : @param $entity – on of tei:item, tei:place, tei:person, tei:gersonGrp,
 : tei:event or tei:org
 : @return on of listEvent, listOrg, listPlace, listPerson, list-works,
 : list-Fontane, list-periodicals
 :)
Mathias Goebel's avatar
Mathias Goebel committed
72
73
74
75
76
declare function local:get-list-by-entity($entity as node())
as xs:string {
switch ( $entity/local-name() )
    case "event" return "listEvent"
    case "org" return "listOrg"
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
77
    case "person" return
Mathias Goebel's avatar
Mathias Goebel committed
78
79
80
        if($entity/ancestor::tei:item)
        then local:get-list-by-entity( $entity/ancestor::tei:item[last()] )
        else "listPerson"
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
81
    case "personGrp" return
Mathias Goebel's avatar
Mathias Goebel committed
82
83
84
85
86
87
88
89
90
91
        if($entity/ancestor::tei:item)
        then local:get-list-by-entity( $entity/ancestor::tei:item[last()] )
        else "listPerson"
    case "place" return "listPlace"
    default return
        let $list := ($entity/ancestor::tei:list[@type])[last()]
        return
            $list/local-name() || "-" || string($list/@type)
};

92
93
94
95
96
97
98
99
100
101
102
103
104
declare function local:get-icon-by-entity($entity as node())
as xs:string {
switch ( $entity/local-name() )
    case "event" return "fa-flag"
    case "org" return "fa-university"
    case "person" return "fa-user"
    case "personGrp" return "fa-users"
    case "place" return "fa-map-marker"
    case "item" return "fa-book"
    default return
        "fa-exclamation-triangle"
};

Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
105
106
107
(:~
 : Helper function to use an efficient map data type to store the model.
 :)
Mathias Goebel's avatar
Mathias Goebel committed
108
declare function local:main-map($index as xs:string+)
Mathias Goebel's avatar
Mathias Goebel committed
109
as map() {
Mathias Goebel's avatar
Mathias Goebel committed
110
111
let $nodes := local:getNodes()
return
Mathias Goebel's avatar
Mathias Goebel committed
112
map:new(
Mathias Goebel's avatar
Mathias Goebel committed
113
114
    for $n in 1 to array:size($nodes)
    let $node := $nodes?($n)
Mathias Goebel's avatar
Mathias Goebel committed
115
116
    let $localId := string-join(($node/local-name(), $node/@type), "-")
    let $content :=
Mathias Goebel's avatar
Mathias Goebel committed
117
        for $node in $node return
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
118
        switch ($node/local-name())
Mathias Goebel's avatar
   
Mathias Goebel committed
119
120
121
122
123
124
125
126
127
            case "listEvent" return
                if($index = "listEvent") then f-indexproc:events($node) else ()
            case "listOrg" return
                if($index = "listOrg") then f-indexproc:orgs($node) else ()
            case "listPerson" return
                if($index = "listPerson") then f-indexproc:persons($node) else ()
            case "listPlace" return
                if($index = "listPlace") then f-indexproc:places($node) else ()
            case "list" return
Mathias Goebel's avatar
Mathias Goebel committed
128
                f-indexproc:works($node)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
129
            default return error(QName("FONTANE", "INDEX1"), "unknown node-name: " || $node/local-name())
Mathias Goebel's avatar
Mathias Goebel committed
130
131
132
133
    return
        map:entry(
            $localId,
            map:new((
Mathias Goebel's avatar
Mathias Goebel committed
134
                map:entry("content", $content)
Mathias Goebel's avatar
Mathias Goebel committed
135
136
137
138
139
            ))
        )
    )
};

Mathias Goebel's avatar
   
Mathias Goebel committed
140
141
142
143
144
declare function local:main-map()
as map() {
    local:main-map(("listEvent", "listOrg", "listPerson", "listPlace", "list-"))
};

Mathias Goebel's avatar
Mathias Goebel committed
145
146
147
148
149
(:~
 : Main function to create a complete index, contains some template specific
 : code.
 :   :)
declare function f-indexproc:register()
Mathias Goebel's avatar
Mathias Goebel committed
150
as element(xhtml:div)+ {
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
151
let $map := local:main-map()
Mathias Goebel's avatar
Mathias Goebel committed
152
return
Mathias Goebel's avatar
   
Mathias Goebel committed
153
    $map?*?("content")
Mathias Goebel's avatar
Mathias Goebel committed
154
};
Mathias Goebel's avatar
Mathias Goebel committed
155

Mathias Goebel's avatar
   
Mathias Goebel committed
156
157
158
159
160
161
162
163
164
165
(:~
 : Main function to create a complete index, contains some template specific
 : code.
 :   :)
declare function f-indexproc:register($index as xs:string?)
as element(xhtml:div)+ {
let $map := local:main-map($index)
return
    $map?*?("content")
};
166

Mathias Goebel's avatar
Mathias Goebel committed
167
168
169
170
171
(:~
 : helper function to get the tgmd:title by URI
 : @param – $uri the textgrid-URI without prefix
 : TODO: may this function should be placed in a generic module
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
172
173
declare function local:resolve-name($uri as xs:string)
as xs:string {
Mathias Goebel's avatar
   
Mathias Goebel committed
174
    let $title := string(doc($f-indexproc:metaCollection || $uri || '.xml')//tgmd:title)
Mathias Goebel's avatar
Mathias Goebel committed
175
    return
Mathias Goebel's avatar
   
Mathias Goebel committed
176
177
178
        if($title = "")
        then $uri
        else $title
Mathias Goebel's avatar
Mathias Goebel committed
179
180
181
};

(:~
Mathias Goebel's avatar
Mathias Goebel committed
182
 : tests for a given ID to appear in all @xml:id in a given node
Mathias Goebel's avatar
Mathias Goebel committed
183
184
185
 : @param – $id the id to search for
 : @param – $node the document or xml fragment
 : :)
186
187
declare function local:check-active($id as xs:string, $node as element(*)+)
as xs:boolean {
188
    exists($node/id($id))
Mathias Goebel's avatar
Mathias Goebel committed
189
190
};

Mathias Goebel's avatar
Mathias Goebel committed
191
192
193
194
(:~
 : checks if a target entity is in the current node set
 : @param $node – any node set
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
195
196
declare function local:check-entity($node as node()+)
as xs:string? {
Mathias Goebel's avatar
Mathias Goebel committed
197
    if(local:check-active($f-indexproc:getEntity, $node))
Mathias Goebel's avatar
Mathias Goebel committed
198
199
200
201
    then "active"
    else ()
};

202
203
(:~
 : creates a generic xhtml:class attribute mandatory for every entry
Mathias Goebel's avatar
Mathias Goebel committed
204
 : @param $id – ID to check for
205
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
206
declare function local:entry-class($id as attribute(xml:id))
Mathias Goebel's avatar
Mathias Goebel committed
207
as attribute(class)? {
208
209
    attribute class {
        "registerEintrag",
Mathias Goebel's avatar
Mathias Goebel committed
210
        $id/parent::*/local-name()
211
212
213
214
    }
};

(:~
Mathias Goebel's avatar
Mathias Goebel committed
215
216
217
 : creates a list for label or name
 : @param $variant – a tei element containing any secondary label or name variant
 :)
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
declare function local:variant($variant as element()*)
as element(xhtml:li)? {
if(not(exists($variant))) then () else
    element xhtml:li {
        attribute class { "variant" },
        "Im Text: ",
        element xhtml:ul {
            for $var at $pos in $variant
            return
                element xhtml:li {
                    string($var) || (if($pos = count($variant)) then () else ",")
                }
        }
    }
};

(:~
235
 : transforms tei:idno to xhtml:li
Mathias Goebel's avatar
Mathias Goebel committed
236
 : @param $idnos – tei element (idno and label) with reference to authority file
237
238
239
 : TODO: declare element(tei:idno), currently wrong encoding with tei:label
 :  :)
declare function local:idno($idnos as element()*)
Mathias Goebel's avatar
Mathias Goebel committed
240
as element(xhtml:li)* {
241
242
for $idno in $idnos
let $str := string($idno)
Mathias Goebel's avatar
Mathias Goebel committed
243
244
245
let $wikipedia :=
  if($idno/@type = "GND") then local:gnd-wikipedia($str) else
  if($idno/@type = "Wikidata") then local:wikidata-wikipedia($str) else ()
246
247
248
249
250
251
252
253
return
    element xhtml:li {
        attribute class {"idno"},
        string($idno/@type) || ": " || $str,
        " ",
        element xhtml:a {
            attribute href { string($idno/@xml:base) || $str },
            <xhtml:i title="Link zu externer Ressource" class="fa fa-external-link"></xhtml:i>
254
        },
Mathias Goebel's avatar
Mathias Goebel committed
255
        (: Deutsche Biografie :)
256
257
258
259
260
261
262
263
264
        if($idno/parent::tei:person and $f-indexproc:BeaconMap($str))
        then
          (",&#160;",
            let $url := $f-indexproc:BeaconMap($str)
            return
              element xhtml:a {
                attribute title {
                    if(ends-with($url, "adbcontent"))
                    then "ADB-Eintrag basierend auf GND"
Mathias Goebel's avatar
Mathias Goebel committed
265
266
267
                    else if (ends-with($url, "ndbcontent"))
                    then "NDB-Eintrag basierend auf GND"
                    else "Eintrag in Deutscher Biografie basierend auf GND"
268
269
270
271
                },
                attribute href {$url},
                if(ends-with($url, "adbcontent"))
                then "ADB"
Mathias Goebel's avatar
Mathias Goebel committed
272
273
274
                else if (ends-with($url, "ndbcontent"))
                then "NDB"
                else "DB"
275
            })
276
        else (),
277
        if(string($wikipedia) = "") then ()
278
279
280
281
282
283
        else (",&#160;",
            element xhtml:a {
                attribute title {"Link zu Wikipedia basierend auf GND"},
                attribute href { $wikipedia },
                <i class="fa fa-wikipedia-w" aria-hidden="true"></i>
            })
284
285
286
    }
};

287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
declare function local:gnd-wikipedia($gndid-orig as xs:string)
as xs:string?{
let $gndid := replace($gndid-orig, "[^A-Za-z0-9\-]", "+")
let $gndCollection := "/db/sade-projects/textgrid/data/xml/gnd/"
let $filename := $gndid || ".xml"
let $docname := $gndCollection || $filename
let $url := "https://d-nb.info/gnd/" || $gndid || "/about/lds.rdf"
let $persist := false()
let $request-headers := ()
let $response :=
    if( doc-available( $docname ))
    then doc( $docname )
    else
        httpclient:get(xs:anyURI($url), $persist, $request-headers)
let $store := xmldb:store($gndCollection, $filename, $response)
return
    string($response//foaf:page/@rdf:resource)
};

Mathias Goebel's avatar
Mathias Goebel committed
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
declare function local:wikidata-wikipedia($wikidata-id as xs:string)
as xs:string?{
  let $query := escape-uri("SELECT ?s WHERE{?s schema:about wd:" || $wikidata-id || ".}", true())
  let $url := "https://query.wikidata.org/sparql?query=" || $query
  let $persist := false()
  let $request-headers := ()
  let $uris := httpclient:get(xs:anyURI($url), $persist, $request-headers)//*:uri/string()
  return (
    $uris[matches(., "de\.wikipedia")],
    $uris[matches(., "en\.wikipedia")],
    $uris[matches(., "fr\.wikipedia")],
    $uris[matches(., "it\.wikipedia")],
    $uris[1])[1]
};

321
322
323
324
(:~
 : transformation from tei:note to xhtml:li
 :  :)
declare function local:note($note as element(tei:note)*)
Mathias Goebel's avatar
Mathias Goebel committed
325
as element(xhtml:li)* {
326
327
328
329
for $n in $note
    return
        element xhtml:li {
            attribute class { "tei-note" },
Mathias Goebel's avatar
Mathias Goebel committed
330
331
332
333
334
335
336
            $n/text(),
            for $ptr in $n/tei:ptr[@type = "Figurenlexikon"]
            return
                element xhtml:a {
                    attribute href { string($ptr/@target) },
                    string($n/@type)
                }
337
338
339
        }
};

340
341
342
343
344
(:~
 : creates a list of all creations or points to the creator of a work
 : :)
declare function local:creator($creators as element(tei:link)+)
as element(xhtml:li) {
345
346
347
348
349
350

if($creators[1]/parent::*/parent::tei:person)
then
    (: person item that is the creator :)
element xhtml:li {
    attribute class { "creator" },
Mathias Goebel's avatar
Mathias Goebel committed
351
    "",
352
    element xhtml:ul {
353
        attribute class {"workList"},
354
355
356
357
358
359
360
361
362
363
364
365
366
367
        for $creator in $creators
        let $target := $creator/@target => substring-before(" ")
        let $targetId := $target => substring-after(":")
        let $targetNode := $f-indexproc:dataCollection/id($targetId)
        let $htmlResource :=
(: TODO remove condition_s_ for final production release :)
            if($targetNode)
            then
                if($targetNode[2])
                then "two entities with same ID: " || $targetId
                else local:get-list-by-entity( $targetNode )
            else "target-not-available"
        return
            element xhtml:li {
368
                attribute class {"item"},
369
370
371
372
373
                element xhtml:a {
                    attribute href { "register-" || $htmlResource || ".html?e=" || string-join($targetId) },
                    if($targetNode[2])
                    then "two entities with same ID: " || $targetId
                    else string($targetNode/*[1])
374
                },
Mathias Goebel's avatar
fix    
Mathias Goebel committed
375
                text{ "&#8195;" },
376
377
378
379
380
381
382
                element xhtml:span {
                    attribute class { "load-entity" },
                    attribute data-load { $targetId },
                    element xhtml:i {
                        attribute class {"fa fa-plus-square-o"},
                        attribute aria-hidden {"true"}
                    }
383
384
385
386
387
388
                }
            }
    }
}
else
    (: work item with creator :)
389
390
element xhtml:li {
    attribute class { "creator" },
Mathias Goebel's avatar
Mathias Goebel committed
391
    "",
392
    element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
393
        attribute class {"listPerson"},
394
395
        for $creator in $creators
        let $target := $creator/@target => substring-after(" ")
Mathias Goebel's avatar
Mathias Goebel committed
396
        let $targetId := $target => substring-after(":")
397
        let $targetNode := $f-indexproc:dataCollection/id($targetId)
Mathias Goebel's avatar
   
Mathias Goebel committed
398
399
400
        let $htmlResource :=
(: TODO remove condition for final production release :)
            if($targetNode)
401
402
403
404
            then
                if($targetNode[2])
                then "two entities with same ID: " || $targetId
                else local:get-list-by-entity( $targetNode )
Mathias Goebel's avatar
   
Mathias Goebel committed
405
            else "target-not-available"
406
407
        return
            element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
408
                attribute class {"person"},
409
                element xhtml:a {
410
411
412
413
                    attribute href { "register-" || $htmlResource || ".html?e=" || string-join($targetId) },
                    if($targetNode[2])
                    then "two entities with same ID: " || $targetId
                    else string($targetNode/*[1])
414
415
416
417
418
419
                }
            }
    }
}
};

420
(:  -> A (irgendein Ding) hat_derzeitigen_Aufbewahrungsort B (irgendein Ort) :)
421
422
423
declare function local:has-former-or-current-location($links as element(tei:link)*)
as element(xhtml:li)* {
for $link in $links
424
425
let $thisId := string($link/parent::tei:linkGrp/parent::tei:*/@xml:id)
let $id := ($link/@target => replace("#|\w{3}:", "") => tokenize(" "))[. != $thisId]
426
let $targetNode := $f-indexproc:dataCollection/id($id)
427
428
let $list := local:get-list-by-entity($targetNode)
let $icon := local:get-icon-by-entity($targetNode)
429
430
431
432
return
    element xhtml:li {
        attribute class { "former-or-current-location" },
        element xhtml:a {
433
434
        attribute href { "register-" || $list || ".html?e=" || $id },
        <xhtml:i class="fa {$icon}" aria-hidden="true"></xhtml:i>,
435
        "&#160;",
436
437
438
439
440
441
442
443
        $targetNode/*[1]/string(),
        let $ancestors := $targetNode/ancestor::tei:place
        for $parentPlace at $pos in $ancestors
        let $name := $parentPlace/*[1]/string()
        return
          ((if($pos = 1) then "(" else ", ") ||
          $name ||
          (if($pos = count($ancestors)) then ")" else ()))
444
445
446
447
        }
    }
};

448
449
(:~
 : a list item with a list of links
Mathias Goebel's avatar
Mathias Goebel committed
450
 :)
Mathias Goebel's avatar
Mathias Goebel committed
451
declare function local:links($links as element(tei:link)*)
Mathias Goebel's avatar
Mathias Goebel committed
452
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
453
let $notebookUris := $links ! (substring-after(./@target, $f-indexproc:targetStart) => substring(1,5) => distinct-values())
Mathias Goebel's avatar
Mathias Goebel committed
454
455
456
457
458
459
460
461
462
463
464
465
466
let $linkMap as map() :=
    map:new(
        for $nb in $notebookUris
        return
            map:entry($nb, $links[contains(@target, $nb)])
    )
return
    element xhtml:li {
        attribute class { "links" },
        if(count(map:keys($linkMap)) lt 2) then 'In Notizbuch' else 'In den Notizbüchern',
        element xhtml:ul {
            local:link($linkMap)
        }
467
468
469
470
471
472
473
    }
};

(:~
 : create list items containing links
 :   :)
declare function local:link($map as map()*)
Mathias Goebel's avatar
Mathias Goebel committed
474
as element(xhtml:li)* {
475
476
    for $tguri in map:keys($map)
    let $resolve := local:resolve-name($tguri)
Mathias Goebel's avatar
   
Mathias Goebel committed
477
    order by $resolve
478
479
    return
        element xhtml:li {
Mathias Goebel's avatar
   
Mathias Goebel committed
480
            replace($resolve, "([A-E])0(\d)", "$1$2") || ": ",
481
482
            element xhtml:ul {
                attribute class {"link-list-horizontal"},
483
                let $this-map := $map($tguri)
484
                let $surface-sequence := $this-map ! (./@target => substring-after("surface[@n='") => substring-before("']/"))
485
                for $link at $pos in $this-map
486
                let $page := $link/@target => substring-after("surface[@n='") => substring-before("']/")
487
488
489
                let $index-of := index-of($surface-sequence, $page)
                let $count := count( $index-of )
                where $pos = $index-of[1]
490
491
492
493
494
495
                return
                    element xhtml:li {
                        element xhtml:a {
                            attribute href {
                                "edition.html?id=%2Fxml%2Fdata%2F" || $tguri
                                || ".xml&amp;page=" || $page
496
                                || "&amp;target=" || string($link/parent::tei:*/parent::tei:*/@xml:id)
497
                            },
498
499
500
                            f-misc:n-translate($page),
                            if($count eq 1) then ()
                            else (" ", <xhtml:span title="Anzahl an Vorkommnissen auf dieser Seite">({$count})</xhtml:span>)
501
502
503
504
505
506
                        }
                    }
            }
        }
};

Mathias Goebel's avatar
Mathias Goebel committed
507
508
(:~
 : prepares a link to the current entry
Mathias Goebel's avatar
Mathias Goebel committed
509
 : @param $id – the xml:id of the currently processed element
Mathias Goebel's avatar
Mathias Goebel committed
510
:)
Mathias Goebel's avatar
Mathias Goebel committed
511
declare function local:entry-link($id as attribute(xml:id))
Mathias Goebel's avatar
Mathias Goebel committed
512
513
514
515
516
as element(xhtml:span) {
    element xhtml:span {
        attribute class {"registerLink"},
        element xhtml:a {
            attribute href {
Mathias Goebel's avatar
Mathias Goebel committed
517
                "register-" || local:get-list-by-entity($id/parent::*) || ".html?e=" || $id
Mathias Goebel's avatar
Mathias Goebel committed
518
519
520
521
522
523
                },
            <xhtml:i title="Link zu diesem Eintrag" class="fa fa-link"></xhtml:i>
        }
    }
};

Mathias Goebel's avatar
Mathias Goebel committed
524
525
526
527
(:~
 : creates a xhtml list item containing serialized code.
 : @param $node – a single element
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
528
529
declare function local:li-code($node as element(*))
as element(xhtml:li) {
530
531
532
533
element xhtml:li {
    attribute class {"register-code"},
    element xhtml:span {
        attribute class {"registerCode"},
Mathias Goebel's avatar
Mathias Goebel committed
534
535
            <xhtml:i title="Zeige XML" class="fa fa-code"></xhtml:i>
    },
Mathias Goebel's avatar
minor    
Mathias Goebel committed
536
    if(config:get("sade.develop") = "true")
Mathias Goebel's avatar
Mathias Goebel committed
537
    then code:main($node)
Mathias Goebel's avatar
minor    
Mathias Goebel committed
538
    else code:main($node, false(), "hljs-", true())
Mathias Goebel's avatar
Mathias Goebel committed
539
}
Mathias Goebel's avatar
Mathias Goebel committed
540
541
};

542
543
544
545
546
(:~
 : generic function for entries with tei:note/tei:ptr.
 : @return link to the corresponding index entry
 :   :)
declare function local:pointer($entry as element())
Mathias Goebel's avatar
Mathias Goebel committed
547
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
548
    let $labelMain := ($entry/*)[1]
549
    let $target := $entry/tei:note/tei:ptr/@target => substring-after('#')
Mathias Goebel's avatar
Mathias Goebel committed
550
    let $targetNode := $f-indexproc:dataCollection/id($target)
551
552
553
554
    return
        element xhtml:li {
            attribute class {
                "registerEintrag",
Mathias Goebel's avatar
Mathias Goebel committed
555
                if( $entry >> $targetNode )
556
557
558
559
560
                then "up"
                else "down"
            },
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
561
                    $labelMain/text()
562
563
564
565
566
567
568
            },
            element xhtml:ul {
                element xhtml:li {
                attribute class { "pointer" },
                "siehe: ",
                    element xhtml:a {
                        attribute href { "?e=" || $target },
569
570
571
                        try {
                             string($targetNode/*[1])
                         } catch * {
Mathias Goebel's avatar
Mathias Goebel committed
572
                             (: TODO remove try catch when the data is better :)
573
574
                             "multiple entities found: " || string-join(($targetNode ! serialize(.)), " AND ")
                         }
575
576
577
578
579
                    }
                }
            }
        }
};
580

Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
581
582
583
(:
 : parses a tei:bibl and mainly prepares a list item with a link to the entity
 :)
584
585
586
587
declare function local:bibl($bibls as element(tei:bibl)*)
as element(xhtml:li)* {
for $bibl in $bibls
    let $biblId := $bibl/tei:ptr/@target => substring-after(":")
Mathias Goebel's avatar
Mathias Goebel committed
588
    let $targetNode := $f-indexproc:dataCollection/id($biblId)[. instance of element(tei:bibl)]
589
590
591
592
593
594
595
    return
        element xhtml:li {
            attribute class { "bibl" },
            element xhtml:a {
            attribute href { "literaturvz.html?id=" || $biblId },
            <xhtml:i class="fa fa-book" aria-hidden="true"></xhtml:i>,
            "&#160;",
Mathias Goebel's avatar
Mathias Goebel committed
596
            $targetNode/tei:choice/tei:abbr/string() ||
597
598
599
600
601
602
603
            (if($bibl/tei:citedRange)
            then ":&#160;" || $bibl/tei:citedRange
            else ())
            }
        }
};

604
605
606
607
608
609
610
611
612
declare function local:get-gnd-data($url as xs:string)
as element(rdf:RDF){
httpclient:get(xs:anyURI($url || "/about/rdf"), false(), ())//rdf:RDF
};

(: ################################################### :)
(: ################################################### :)
(: ################################################### :)

Mathias Goebel's avatar
Mathias Goebel committed
613
614
(:~
 : parser for listEvents/event entities
615
 : @param $eventDoc – the tei:listEvent containing all entries
Mathias Goebel's avatar
Mathias Goebel committed
616
 :  :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
617
declare function f-indexproc:events($eventDoc as element(tei:listEvent))
618
as element(xhtml:div) {
Mathias Goebel's avatar
   
Mathias Goebel committed
619
<xhtml:div id="{ string-join(($eventDoc/local-name(), $eventDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
620
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
621
622
    {for $eventList in $eventDoc/tei:listEvent
    return
Mathias Goebel's avatar
Mathias Goebel committed
623
624
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
625
                <h4 class="panel-title">{$eventList/tei:head/text()}</h4>
Mathias Goebel's avatar
Mathias Goebel committed
626
627
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
628
                <ul class="listEvent">
629
{
Mathias Goebel's avatar
Mathias Goebel committed
630
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
then
  for $event in $eventList/tei:event
  let $sort := string($event/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
  return local:prepare-event($event)
else
  for $event in $eventList/tei:event[tei:linkGrp/tei:link
  [starts-with(@target, $f-indexproc:getNotebook)]]
  let $sort := string($event/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
  return local:prepare-event($event)
648
}
Mathias Goebel's avatar
Mathias Goebel committed
649
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
650
651
            </xhtml:div>
        </xhtml:div>
652
    }
Mathias Goebel's avatar
Mathias Goebel committed
653
654
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
655
656
};

657
declare function local:prepare-event($event as element(tei:event))
658
as element(xhtml:li) {
659
660
661
662
663
664
665
(: check if the item points to another entity :)
if( not(exists($event/@xml:id)) )
then
    (: pointer :)
    local:pointer($event)
else
    let $id := $event/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
666
    let $wheres := tokenize($event/@where, " ") ! substring-after(., ":")
667
668
669
670
671
672
    let $labelMain := ($event/tei:label)[1]
    let $labelAlt := ($event/tei:label[not(@type="variant")])[position() gt 1]
    let $variant := $event/tei:label[@type="variant"]
    let $note := $event/tei:note
    let $bibl := $event/tei:bibl
    let $links := $event/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
Mathias Goebel's avatar
Mathias Goebel committed
673
return
674
675
676
    element xhtml:li {
        attribute id { string($id) },
        local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
677
        (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
678
        local:entry-link($id),
679
680
        element xhtml:span {
                attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
681
                $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
682
            },
683
        element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
684
            (: variant :)
685
            local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
686
            (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
687
            local:idno($labelAlt),
Mathias Goebel's avatar
Mathias Goebel committed
688
            (: note :)
689
            local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
690
            (: where :)
Mathias Goebel's avatar
Mathias Goebel committed
691
            for $where in $wheres return
692
693
694
            element xhtml:li {
                attribute class { "where" },
                element xhtml:a {
Mathias Goebel's avatar
Mathias Goebel committed
695
                attribute href { "register-listPlace.html?e="|| $where },
Mathias Goebel's avatar
Mathias Goebel committed
696
697
                <xhtml:i class="fa fa-map-marker" aria-hidden="true"></xhtml:i>,
                "&#160;",
Mathias Goebel's avatar
Mathias Goebel committed
698
                $f-indexproc:dataCollection/id($where)/*[1]/string()
Mathias Goebel's avatar
Mathias Goebel committed
699
700
701
                }
            },
            (: bibl :)
702
            local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
703
            (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
704
            local:links($links),
705
            local:li-code($event)
Mathias Goebel's avatar
Mathias Goebel committed
706
707
        }
    }
Mathias Goebel's avatar
Mathias Goebel committed
708
709
};

Mathias Goebel's avatar
Mathias Goebel committed
710
(:~
Mathias Goebel's avatar
Mathias Goebel committed
711
 : parser for tei:listOrg, returns the index of orgnaisations.
Mathias Goebel's avatar
Mathias Goebel committed
712
 :  :)
Mathias Goebel's avatar
   
Mathias Goebel committed
713
714
715
declare function f-indexproc:orgs($orgDoc as element(tei:listOrg)+) {
let $result :=
<xhtml:div id="{ string-join(($orgDoc/local-name(), $orgDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
716
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
717
718
    {for $orgList in $orgDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
719
720
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
721
                <h4 class="panel-title">{ $orgList/tei:head/text() }</h4>
Mathias Goebel's avatar
Mathias Goebel committed
722
723
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
724
                <ul class="listOrg">
725
{
Mathias Goebel's avatar
Mathias Goebel committed
726
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
727
728
729
730
731
732
733
734
then
  for $org in $orgList/tei:org
  let $sort := string($org/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
  return local:prepare-org($org)
Mathias Goebel's avatar
   
Mathias Goebel committed
735
else
Mathias Goebel's avatar
Mathias Goebel committed
736
737
738
739
740
741
742
  for $org in $orgList/tei:org[tei:linkGrp/tei:link[starts-with(@target, $f-indexproc:getNotebook)]]
  let $sort := string($org/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
  return local:prepare-org($org)
743
}
Mathias Goebel's avatar
Mathias Goebel committed
744
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
745
746
            </xhtml:div>
        </xhtml:div>
747
    }
Mathias Goebel's avatar
Mathias Goebel committed
748
749
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
   
Mathias Goebel committed
750
751
return
    $result
Mathias Goebel's avatar
Mathias Goebel committed
752
753
};

Mathias Goebel's avatar
Mathias Goebel committed
754
755
756
757
(:~
 : transforms a single tei:org element to a xhtml:li
 : @since 1.0
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
758
759
declare function local:prepare-org($org as element(tei:org))
as element(xhtml:li) {
760
761
762
763
764
765
(: check if the item points to another entity :)
if( not(exists($org/@xml:id)) )
then
    (: pointer :)
    local:pointer($org)
else
Mathias Goebel's avatar
Mathias Goebel committed
766
    let $id := $org/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
767
    let $labelMain := ($org/tei:orgName)[1]
Mathias Goebel's avatar
Mathias Goebel committed
768
    let $idnos := $org/tei:idno
Mathias Goebel's avatar
Mathias Goebel committed
769
    let $variant := $org/tei:orgName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
770
771
772
773
    let $note := $org/tei:note
    let $bibl := $org/tei:bibl
    let $links := $org/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
return
774
775
776
    element xhtml:li {
        attribute id { string($id) },
        local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
777
        (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
778
        local:entry-link($id),
779
780
        element xhtml:span {
                attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
781
                $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
782
            },
783
        element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
784
            (: variant :)
785
            local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
786
            (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
787
            local:idno($idnos),
Mathias Goebel's avatar
Mathias Goebel committed
788
            (: note :)
789
            local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
790
            (: bibl :)
791
            local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
792
            (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
793
            local:links($links),
Mathias Goebel's avatar
Mathias Goebel committed
794
            local:li-code($org)
Mathias Goebel's avatar
Mathias Goebel committed
795
796
        }
    }
Mathias Goebel's avatar
Mathias Goebel committed
797
798
};

Mathias Goebel's avatar
Mathias Goebel committed
799
(:~
Mathias Goebel's avatar
Mathias Goebel committed
800
 : parser for tei:listPerson, returns the index of persons
Mathias Goebel's avatar
Mathias Goebel committed
801
 :   :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
802
declare function f-indexproc:persons($persDoc as element(tei:listPerson))
Mathias Goebel's avatar
Mathias Goebel committed
803
as element(xhtml:div) {
Mathias Goebel's avatar
Mathias Goebel committed
804
(: main tab :)
Mathias Goebel's avatar
   
Mathias Goebel committed
805
<xhtml:div id="{ string-join(($persDoc/local-name(), $persDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
806
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
807
808
    {for $persList in $persDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
809
810
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
811
812
                <h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">Personen und Werke</a>
                </h4>
Mathias Goebel's avatar
Mathias Goebel committed
813
814
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
815
                <ul class="listPerson">
816
{
Mathias Goebel's avatar
Mathias Goebel committed
817
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
then
  for $pers in $persList/tei:*
  let $sort := string($pers/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
  return local:prepare-person($pers)
else
  for $pers in $persList/tei:*[tei:linkGrp/tei:link[starts-with(@target, $f-indexproc:getNotebook)]]
  let $sort := string($pers/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
  return local:prepare-person($pers)
834
}
Mathias Goebel's avatar
Mathias Goebel committed
835
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
836
837
            </xhtml:div>
        </xhtml:div>
838
    }
Mathias Goebel's avatar
Mathias Goebel committed
839
840
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
841
842
};

Mathias Goebel's avatar
Mathias Goebel committed
843
844
declare function local:prepare-person($pers as element(*)+)
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
845
846
847
848
(: check if the item points to another entity :)
if( not(exists($pers/@xml:id)) )
then
    (: pointer :)
849
    local:pointer($pers)
Mathias Goebel's avatar
Mathias Goebel committed
850
851
852
else
    (: entity :)
    let $id := $pers/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
853
854
    let $labelMain := $pers/tei:persName[1]
    let $labelAlt := $pers/tei:persName[not(@type="variant")][position() gt 1]
Mathias Goebel's avatar
Mathias Goebel committed
855
    let $variant := $pers/tei:persName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
856
857
858
859
860
861
862
    let $idnos := $pers/tei:idno
    let $birth := $pers/tei:birth
    let $death := $pers/tei:death
    let $occupation := $pers/tei:occupation
    let $state := $pers/tei:state/tei:desc
    let $note := $pers/tei:note
    let $bibl := $pers/tei:bibl
863
864
    let $members := $pers/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P107_has_current_or_former_member"]
    let $creator := $pers/tei:linkGrp/tei:link[@corresp="http://purl.org/dc/terms/creator"]
Mathias Goebel's avatar
Mathias Goebel committed
865
866
    let $links := $pers/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
    return
867
868
869
        element xhtml:li {
            attribute id { string($id) },
            local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
870
            (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
871
            local:entry-link($id),
872
873
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
874
                    $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
875
                },
876
            element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
877
                (: variant :)
878
                local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
879
                (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
880
                for $l in $labelAlt
Mathias Goebel's avatar
Mathias Goebel committed
881
                return
882
883
                    element xhtml:li {
                    attribute class {"label-" || string($l/@type)},
Mathias Goebel's avatar
Mathias Goebel committed
884
885
886
887
888
                    $l/text(),
                    if($l/@type = "variant")
                    then ()
                    else (
                        "&#160;",
889
890
                        element xhtml:a {
                            attribute href { string($l/@xml:base) || string($l) },
Mathias Goebel's avatar
Mathias Goebel committed
891
892
893
894
895
                            <xhtml:i title="Link zu externer Ressource" class="fa fa-external-link"></xhtml:i>
                        }
                    )
                },
                (: idno :)
896
                local:idno($idnos),
Mathias Goebel's avatar
Mathias Goebel committed
897
898
                (: birth, death :)
                if( not($birth or $death) ) then () else
899
                    element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
900
901
902
903
904
905
906
                        if($birth) then ('&#8727;', $birth/text()) else (),
                        if( $birth and $death ) then " " else (),
                        if($death) then ('✝', $death/text()) else()
                    },
                (: occupation :)
                for $o in $occupation
                return
907
908
                    element xhtml:li {
                        attribute class { "occupation" },
Mathias Goebel's avatar
Mathias Goebel committed
909
910
911
912
                        $o/text()
                    },
                for $s in $state
                return
913
914
                    element xhtml:li {
                        attribute class { "state" },
Mathias Goebel's avatar
Mathias Goebel committed
915
916
                        $s/text()
                    },
917
918
919
920
921
922
923
924
925
926
927
928
929
930
                (: current or former member :)
                if(not(exists($members))) then () else
                element xhtml:li {
                    attribute class { "member" },
                    "Mitglieder:",
                    element xhtml:ul {
                        for $member in $members
                        let $memberId := $members/@target => substring-after(" ") => substring-after("#")
                        return
                            element xhtml:li {
                                element xhtml:a {
                                attribute href { "?e=" || $memberId },
                                <xhtml:i class="fa fa-user" aria-hidden="true"></xhtml:i>,
                                "&#160;",
Mathias Goebel's avatar
Mathias Goebel committed
931
                                $f-indexproc:dataCollection/id($memberId)/*[1]/string()
932
933
934
935
936
937
                                }
                            }
                    }
                },
                if (not(exists($creator))) then () else
                local:creator($creator),
Mathias Goebel's avatar
Mathias Goebel committed
938
                (: note :)
939
                local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
940
                (: bibl :)
941
                local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
942
                (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
943
                local:links($links),
Mathias Goebel's avatar
Mathias Goebel committed
944
                local:li-code($pers)
Mathias Goebel's avatar
Mathias Goebel committed
945
946
947
948
            }
        }
};

Mathias Goebel's avatar
Mathias Goebel committed
949
950
951
(:~
 : prepares the index of geographical references
 :  :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
952
declare function f-indexproc:places($listPlace as element(tei:listPlace))
Mathias Goebel's avatar
Mathias Goebel committed
953
as element(xhtml:div) {
Mathias Goebel's avatar
   
Mathias Goebel committed
954
<xhtml:div id="{ string-join(($listPlace/local-name(), $listPlace/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
955
956
957
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
958
959
                <h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">Geographisches Register</a>
                </h4>
Mathias Goebel's avatar
Mathias Goebel committed
960
961
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
962
                <ul class="listPlace">
963
{
Mathias Goebel's avatar
Mathias Goebel committed
964
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
then
  for $place in $listPlace/tei:place
  let $sort := string($place/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
  return local:prepare-place($place)

else
  for $place in $listPlace/tei:place
      [tei:linkGrp/tei:link
      [starts-with(@target, $f-indexproc:getNotebook)]]
  let $sort := string($place/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
  return local:prepare-place($place)
984
}
Mathias Goebel's avatar
Mathias Goebel committed
985
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
986
987
988
989
            </xhtml:div>
        </xhtml:div>
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
990
991
};

Mathias Goebel's avatar
Mathias Goebel committed
992
993
(:~
 : transformation of a single geographical reference item  :)
Mathias Goebel's avatar
Mathias Goebel committed
994
995
declare function local:prepare-place($place as element(tei:place))
as element(xhtml:ul) {
Mathias Goebel's avatar
Mathias Goebel committed
996
997
998
999
(: check if the item points to another entity :)
if( not(exists($place/@xml:id)) )
then
    (: pointer :)
1000
    local:pointer($place)
Mathias Goebel's avatar
Mathias Goebel committed
1001
1002
1003
else
    (: entity :)
    let $id := $place/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
1004
1005
    let $labelMain := $place/tei:placeName[1]
    let $labelAlt := $place/tei:placeName[not(@type="variant")][position() gt 1]
Mathias Goebel's avatar
Mathias Goebel committed
1006
    let $variant := $place/tei:placeName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
1007
1008
    let $idnos := $place/tei:idno
    let $note := $place/tei:note
1009
    let $creator := $place/tei:linkGrp/tei:link[@corresp="http://purl.org/dc/terms/creator"]
Mathias Goebel's avatar
Mathias Goebel committed
1010
    let $bibl := $place/tei:bibl
Mathias Goebel's avatar
Mathias Goebel committed
1011
    let $tookPlaceAt := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P7_took_place_at"]
1012
    let $formerCurrentLocation := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P53_has_former_or_current_location"]
Mathias Goebel's avatar
Mathias Goebel committed
1013
1014
    let $links := $place/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
    return
1015
1016
1017
        element xhtml:li {
            attribute id { string($id) },
            local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
1018
            (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
1019
            local:entry-link($id),
1020
1021
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
1022
                    $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
1023
                },
1024
            element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
1025
                (: variant :)
1026
                local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
1027
                (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
1028
                for $l in $labelAlt
Mathias Goebel's avatar
Mathias Goebel committed
1029
                return
1030
1031
                    element xhtml:li {
                    attribute class {"label-" || string($l/@type)},
Mathias Goebel's avatar
Mathias Goebel committed
1032
1033
1034
1035
1036
                    $l/text(),
                    if($l/@type = "variant")
                    then ()
                    else (
                        "&#160;",
1037
1038
                        element xhtml:a {
                            attribute href { string($l/@xml:base) || string($l) },
Mathias Goebel's avatar
Mathias Goebel committed
1039
1040
1041
1042
1043
                            <xhtml:i title="Link zu externer Ressource" class="fa fa-external-link"></xhtml:i>
                        }
                    )
                },
                (: idno :)
1044
                local:idno($idnos),
1045
1046
1047
                (: creator :)
                if (not(exists($creator))) then () else
                local:creator($creator),
Mathias Goebel's avatar
Mathias Goebel committed
1048
                (: note :)
1049
                local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
1050
                (: bibl :)
1051
                local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
1052
1053
                (: events took place :)
                for $l in $tookPlaceAt
1054
                let $id := $l/@target => substring-after(":") => substring-before(" ")
Mathias Goebel's avatar
Mathias Goebel committed
1055
1056
1057
1058
1059
                return
                    element xhtml:li {
                        attribute class { "took-place-at" },
                        element xhtml:a {
                        attribute href { "?e=" || $id },
Mathias Goebel's avatar
Mathias Goebel committed
1060
                        <xhtml:i class="fa fa-flag" aria-hidden="true"></xhtml:i>,
Mathias Goebel's avatar
Mathias Goebel committed
1061
                        "&#160;",
Mathias Goebel's avatar
Mathias Goebel committed
1062
                        $f-indexproc:dataCollection/id($id)/*[1]/string()
Mathias Goebel's avatar
Mathias Goebel committed
1063
1064
                        }
                    },
1065
                (: former_or_current_location :)
1066
                local:has-former-or-current-location($formerCurrentLocation),
Mathias Goebel's avatar
Mathias Goebel committed
1067
                (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
1068
                local:links($links),
Mathias Goebel's avatar
Mathias Goebel committed
1069
                local:li-code($place),
1070
                element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
1071
1072
1073
1074
1075
1076
1077
                  for $plac in $place/tei:place
                  let $sort := string($plac/*[1])
                                => replace("ä", "ae")
                                => replace("ö", "oe")
                                => replace("ü", "ue")
                  order by $sort
                  return local:prepare-place($plac)
Mathias Goebel's avatar
Mathias Goebel committed
1078
1079
1080
1081
1082
                }
            }
        }
};

Mathias Goebel's avatar
Mathias Goebel committed
1083
1084
(:~
 : prepares the list of works :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
1085
declare function f-indexproc:works($wrkDoc as element(tei:list))
Mathias Goebel's avatar
Mathias Goebel committed
1086
as element(xhtml:div) {
Mathias Goebel's avatar
   
Mathias Goebel committed
1087
<xhtml:div id="{ string-join(($wrkDoc/local-name(), $wrkDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
1088
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
1089
1090
    {for $wrkList in $wrkDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
1091
1092
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
1093
1094
                <h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">{$wrkList/tei:head/text()}</a>
                </h4>
Mathias Goebel's avatar
Mathias Goebel committed
1095
1096
            </xhtml:div>
            <xhtml:div class="panel-body">
1097
                <ul class="workList">
1098
{
Mathias Goebel's avatar
Mathias Goebel committed
1099
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
1100
then
1101
for $i in $wrkList//tei:item[not(tei:list)]
Mathias Goebel's avatar
Mathias Goebel committed
1102
order by (lower-case(($i/tei:name[not(@type)]/text())[1]) => replace("ä", "ae") => replace("ö", "oe") => replace("ü", "ue") )
1103
return local:prepare-work($i)
1104
else
1105
1106
1107
for $i in $wrkList//tei:item
    [not(tei:list)]
    [tei:linkGrp/tei:link
Mathias Goebel's avatar
Mathias Goebel committed
1108
        [starts-with(@target, $f-indexproc:getNotebook)]]
Mathias Goebel's avatar
Mathias Goebel committed
1109
order by (lower-case(($i/tei:name[not(@type)]/text())[1]) => replace("ä", "ae") => replace("ö", "oe") => replace("ü", "ue") )
1110
return local:prepare-work($i)
1111
}
1112
                </ul>