index-processor.xqm 43.6 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 f-misc="http://fontane-nb.dariah.eu/ns/SADE/misc" at "misc.xqm";
13
import module namespace code="http://bdn-edition.de/ns/code-view";
14

15
declare namespace foaf="http://xmlns.com/foaf/0.1/";
16
declare namespace gndo="http://d-nb.info/standards/elementset/gnd#";
Mathias Goebel's avatar
Mathias Goebel committed
17
18
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
19
declare namespace tei="http://www.tei-c.org/ns/1.0";
Mathias Goebel's avatar
Mathias Goebel committed
20
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
Mathias Goebel's avatar
Mathias Goebel committed
21
declare namespace xhtml="http://www.w3.org/1999/xhtml";
Mathias Goebel's avatar
Mathias Goebel committed
22

Mathias Goebel's avatar
Mathias Goebel committed
23
24
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
25
26
27
28
(: 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
29
30
31
32
33
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);

34
declare variable $f-indexproc:BeaconMap := map:merge((
Mathias Goebel's avatar
Mathias Goebel committed
35
        local:beacon-parser(xs:anyURI("http://www.historische-kommission-muenchen-editionen.de/beacon_db_register.txt")),
36
37
38
        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
39
40
41
(:~
 : Helper function to collect all main nodes from the index files.
:)
Mathias Goebel's avatar
Mathias Goebel committed
42
declare function local:getNodes()
Mathias Goebel's avatar
   
Mathias Goebel committed
43
as array(*) {
Mathias Goebel's avatar
Mathias Goebel committed
44
45
46
47
48
49
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
50
return
Mathias Goebel's avatar
Mathias Goebel committed
51
    [
Mathias Goebel's avatar
Mathias Goebel committed
52
    $docs//tei:body/tei:listEvent,
Mathias Goebel's avatar
Mathias Goebel committed
53
    $docs//tei:body/tei:listOrg,
Mathias Goebel's avatar
Mathias Goebel committed
54
55
56
57
    $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
58
    $docs//tei:body//tei:list[@type="Fontane"]
Mathias Goebel's avatar
Mathias Goebel committed
59
    ]
Mathias Goebel's avatar
Mathias Goebel committed
60
61
62
};

(:~
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
63
64
65
66
67
68
69
 : 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
70
71
72
73
74
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
75
    case "person" return
Mathias Goebel's avatar
Mathias Goebel committed
76
77
78
        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
79
    case "personGrp" return
Mathias Goebel's avatar
Mathias Goebel committed
80
81
82
83
84
85
86
87
88
89
        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)
};

Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
90
91
92
(:~
 : Helper function to use an efficient map data type to store the model.
 :)
Mathias Goebel's avatar
Mathias Goebel committed
93
declare function local:main-map($index as xs:string+)
Mathias Goebel's avatar
Mathias Goebel committed
94
as map() {
Mathias Goebel's avatar
Mathias Goebel committed
95
96
let $nodes := local:getNodes()
return
Mathias Goebel's avatar
Mathias Goebel committed
97
map:new(
Mathias Goebel's avatar
Mathias Goebel committed
98
99
    for $n in 1 to array:size($nodes)
    let $node := $nodes?($n)
Mathias Goebel's avatar
Mathias Goebel committed
100
101
    let $localId := string-join(($node/local-name(), $node/@type), "-")
    let $content :=
Mathias Goebel's avatar
Mathias Goebel committed
102
        for $node in $node return
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
103
        switch ($node/local-name())
Mathias Goebel's avatar
   
Mathias Goebel committed
104
105
106
107
108
109
110
111
112
            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
113
                f-indexproc:works($node)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
114
            default return error(QName("FONTANE", "INDEX1"), "unknown node-name: " || $node/local-name())
Mathias Goebel's avatar
Mathias Goebel committed
115
116
117
118
    return
        map:entry(
            $localId,
            map:new((
Mathias Goebel's avatar
Mathias Goebel committed
119
                map:entry("content", $content)
Mathias Goebel's avatar
Mathias Goebel committed
120
121
122
123
124
            ))
        )
    )
};

Mathias Goebel's avatar
   
Mathias Goebel committed
125
126
127
128
129
declare function local:main-map()
as map() {
    local:main-map(("listEvent", "listOrg", "listPerson", "listPlace", "list-"))
};

Mathias Goebel's avatar
Mathias Goebel committed
130
131
132
133
134
(:~
 : Main function to create a complete index, contains some template specific
 : code.
 :   :)
declare function f-indexproc:register()
Mathias Goebel's avatar
Mathias Goebel committed
135
as element(xhtml:div)+ {
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
136
let $map := local:main-map()
Mathias Goebel's avatar
Mathias Goebel committed
137
return
Mathias Goebel's avatar
   
Mathias Goebel committed
138
    $map?*?("content")
Mathias Goebel's avatar
Mathias Goebel committed
139
};
Mathias Goebel's avatar
Mathias Goebel committed
140

Mathias Goebel's avatar
   
Mathias Goebel committed
141
142
143
144
145
146
147
148
149
150
(:~
 : 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")
};
151

Mathias Goebel's avatar
Mathias Goebel committed
152
153
154
155
156
(:~
 : 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
157
158
declare function local:resolve-name($uri as xs:string)
as xs:string {
Mathias Goebel's avatar
   
Mathias Goebel committed
159
    let $title := string(doc($f-indexproc:metaCollection || $uri || '.xml')//tgmd:title)
Mathias Goebel's avatar
Mathias Goebel committed
160
    return
Mathias Goebel's avatar
   
Mathias Goebel committed
161
162
163
        if($title = "")
        then $uri
        else $title
Mathias Goebel's avatar
Mathias Goebel committed
164
165
166
};

(:~
Mathias Goebel's avatar
Mathias Goebel committed
167
 : tests for a given ID to appear in all @xml:id in a given node
Mathias Goebel's avatar
Mathias Goebel committed
168
169
170
 : @param – $id the id to search for
 : @param – $node the document or xml fragment
 : :)
171
172
declare function local:check-active($id as xs:string, $node as element(*)+)
as xs:boolean {
173
    exists($node/id($id))
Mathias Goebel's avatar
Mathias Goebel committed
174
175
};

Mathias Goebel's avatar
Mathias Goebel committed
176
177
178
179
(:~
 : checks if a target entity is in the current node set
 : @param $node – any node set
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
180
181
declare function local:check-entity($node as node()+)
as xs:string? {
Mathias Goebel's avatar
Mathias Goebel committed
182
    if(local:check-active($f-indexproc:getEntity, $node))
Mathias Goebel's avatar
Mathias Goebel committed
183
184
185
186
    then "active"
    else ()
};

187
188
(:~
 : creates a generic xhtml:class attribute mandatory for every entry
Mathias Goebel's avatar
Mathias Goebel committed
189
 : @param $id – ID to check for
190
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
191
declare function local:entry-class($id as attribute(xml:id))
Mathias Goebel's avatar
Mathias Goebel committed
192
as attribute(class)? {
193
194
    attribute class {
        "registerEintrag",
Mathias Goebel's avatar
Mathias Goebel committed
195
        $id/parent::*/local-name()
196
197
198
199
    }
};

(:~
Mathias Goebel's avatar
Mathias Goebel committed
200
201
202
 : creates a list for label or name
 : @param $variant – a tei element containing any secondary label or name variant
 :)
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
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 ",")
                }
        }
    }
};

(:~
220
 : transforms tei:idno to xhtml:li
Mathias Goebel's avatar
Mathias Goebel committed
221
 : @param $idnos – tei element (idno and label) with reference to authority file
222
223
224
 : 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
225
as element(xhtml:li)* {
226
227
for $idno in $idnos
let $str := string($idno)
Mathias Goebel's avatar
Mathias Goebel committed
228
229
230
let $wikipedia :=
  if($idno/@type = "GND") then local:gnd-wikipedia($str) else
  if($idno/@type = "Wikidata") then local:wikidata-wikipedia($str) else ()
231
232
233
234
235
236
237
238
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>
239
        },
Mathias Goebel's avatar
Mathias Goebel committed
240
        (: Deutsche Biografie :)
241
242
243
244
245
246
247
248
249
        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
250
251
252
                    else if (ends-with($url, "ndbcontent"))
                    then "NDB-Eintrag basierend auf GND"
                    else "Eintrag in Deutscher Biografie basierend auf GND"
253
254
255
256
                },
                attribute href {$url},
                if(ends-with($url, "adbcontent"))
                then "ADB"
Mathias Goebel's avatar
Mathias Goebel committed
257
258
259
                else if (ends-with($url, "ndbcontent"))
                then "NDB"
                else "DB"
260
            })
261
        else (),
262
        if(string($wikipedia) = "") then ()
263
264
265
266
267
268
        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>
            })
269
270
271
    }
};

272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
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]
};

306
307
308
309
(:~
 : transformation from tei:note to xhtml:li
 :  :)
declare function local:note($note as element(tei:note)*)
Mathias Goebel's avatar
Mathias Goebel committed
310
as element(xhtml:li)* {
311
312
313
314
for $n in $note
    return
        element xhtml:li {
            attribute class { "tei-note" },
Mathias Goebel's avatar
Mathias Goebel committed
315
316
317
318
319
320
321
            $n/text(),
            for $ptr in $n/tei:ptr[@type = "Figurenlexikon"]
            return
                element xhtml:a {
                    attribute href { string($ptr/@target) },
                    string($n/@type)
                }
322
323
324
        }
};

325
326
327
328
329
(:~
 : 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) {
330
331
332
333
334
335

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
336
    "",
337
    element xhtml:ul {
338
        attribute class {"workList"},
339
340
341
342
343
344
345
346
347
348
349
350
351
352
        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 {
353
                attribute class {"item"},
354
355
356
357
358
                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])
359
                },
Mathias Goebel's avatar
fix    
Mathias Goebel committed
360
                text{ "&#8195;" },
361
362
363
364
365
366
367
                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"}
                    }
368
369
370
371
372
373
                }
            }
    }
}
else
    (: work item with creator :)
374
375
element xhtml:li {
    attribute class { "creator" },
Mathias Goebel's avatar
Mathias Goebel committed
376
    "",
377
    element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
378
        attribute class {"listPerson"},
379
380
        for $creator in $creators
        let $target := $creator/@target => substring-after(" ")
Mathias Goebel's avatar
Mathias Goebel committed
381
        let $targetId := $target => substring-after(":")
382
        let $targetNode := $f-indexproc:dataCollection/id($targetId)
Mathias Goebel's avatar
   
Mathias Goebel committed
383
384
385
        let $htmlResource :=
(: TODO remove condition for final production release :)
            if($targetNode)
386
387
388
389
            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
390
            else "target-not-available"
391
392
        return
            element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
393
                attribute class {"person"},
394
                element xhtml:a {
395
396
397
398
                    attribute href { "register-" || $htmlResource || ".html?e=" || string-join($targetId) },
                    if($targetNode[2])
                    then "two entities with same ID: " || $targetId
                    else string($targetNode/*[1])
399
400
401
402
403
404
                }
            }
    }
}
};

405
406
407
declare function local:has-former-or-current-location($links as element(tei:link)*)
as element(xhtml:li)* {
for $link in $links
408
409
let $id := $link/@target => substring-after(" ") => substring-after(":")
let $targetNode := $f-indexproc:dataCollection/id($id)
410
411
412
413
return
    element xhtml:li {
        attribute class { "former-or-current-location" },
        element xhtml:a {
Mathias Goebel's avatar
Mathias Goebel committed
414
        attribute href { "register-listPlace.html?e=" || $id },
415
416
        <xhtml:i class="fa fa-map-marker" aria-hidden="true"></xhtml:i>,
        "&#160;",
417
418
419
420
421
422
423
424
        $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 ()))
425
426
427
428
        }
    }
};

429
430
(:~
 : a list item with a list of links
Mathias Goebel's avatar
Mathias Goebel committed
431
 :)
Mathias Goebel's avatar
Mathias Goebel committed
432
declare function local:links($links as element(tei:link)*)
Mathias Goebel's avatar
Mathias Goebel committed
433
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
434
let $notebookUris := $links ! (substring-after(./@target, $f-indexproc:targetStart) => substring(1,5) => distinct-values())
Mathias Goebel's avatar
Mathias Goebel committed
435
436
437
438
439
440
441
442
443
444
445
446
447
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)
        }
448
449
450
451
452
453
454
    }
};

(:~
 : create list items containing links
 :   :)
declare function local:link($map as map()*)
Mathias Goebel's avatar
Mathias Goebel committed
455
as element(xhtml:li)* {
456
457
    for $tguri in map:keys($map)
    let $resolve := local:resolve-name($tguri)
Mathias Goebel's avatar
   
Mathias Goebel committed
458
    order by $resolve
459
460
    return
        element xhtml:li {
Mathias Goebel's avatar
   
Mathias Goebel committed
461
            replace($resolve, "([A-E])0(\d)", "$1$2") || ": ",
462
463
            element xhtml:ul {
                attribute class {"link-list-horizontal"},
464
465
466
                let $this-map := $map($tguri)
                let $surface-sequence := $this-map ! (./@target => substring-after("surface[@n='") => substring-before("']//"))
                for $link at $pos in $this-map
467
                let $page := $link/@target => substring-after("surface[@n='") => substring-before("']//")
468
469
470
                let $index-of := index-of($surface-sequence, $page)
                let $count := count( $index-of )
                where $pos = $index-of[1]
471
472
473
474
475
476
                return
                    element xhtml:li {
                        element xhtml:a {
                            attribute href {
                                "edition.html?id=%2Fxml%2Fdata%2F" || $tguri
                                || ".xml&amp;page=" || $page
477
                                || "&amp;target=" || string($link/parent::tei:*/parent::tei:*/@xml:id)
478
                            },
479
480
481
                            f-misc:n-translate($page),
                            if($count eq 1) then ()
                            else (" ", <xhtml:span title="Anzahl an Vorkommnissen auf dieser Seite">({$count})</xhtml:span>)
482
483
484
485
486
487
                        }
                    }
            }
        }
};

Mathias Goebel's avatar
Mathias Goebel committed
488
489
(:~
 : prepares a link to the current entry
Mathias Goebel's avatar
Mathias Goebel committed
490
 : @param $id – the xml:id of the currently processed element
Mathias Goebel's avatar
Mathias Goebel committed
491
:)
Mathias Goebel's avatar
Mathias Goebel committed
492
declare function local:entry-link($id as attribute(xml:id))
Mathias Goebel's avatar
Mathias Goebel committed
493
494
495
496
497
as element(xhtml:span) {
    element xhtml:span {
        attribute class {"registerLink"},
        element xhtml:a {
            attribute href {
Mathias Goebel's avatar
Mathias Goebel committed
498
                "register-" || local:get-list-by-entity($id/parent::*) || ".html?e=" || $id
Mathias Goebel's avatar
Mathias Goebel committed
499
500
501
502
503
504
                },
            <xhtml:i title="Link zu diesem Eintrag" class="fa fa-link"></xhtml:i>
        }
    }
};

Mathias Goebel's avatar
Mathias Goebel committed
505
506
507
508
(:~
 : creates a xhtml list item containing serialized code.
 : @param $node – a single element
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
509
510
declare function local:li-code($node as element(*))
as element(xhtml:li) {
511
512
513
514
element xhtml:li {
    attribute class {"register-code"},
    element xhtml:span {
        attribute class {"registerCode"},
Mathias Goebel's avatar
Mathias Goebel committed
515
516
            <xhtml:i title="Zeige XML" class="fa fa-code"></xhtml:i>
    },
517
518

    code:main($node)
Mathias Goebel's avatar
Mathias Goebel committed
519
}
Mathias Goebel's avatar
Mathias Goebel committed
520
521
};

522
523
524
525
526
(:~
 : 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
527
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
528
    let $labelMain := ($entry/*)[1]
529
    let $target := $entry/tei:note/tei:ptr/@target => substring-after('#')
Mathias Goebel's avatar
Mathias Goebel committed
530
    let $targetNode := $f-indexproc:dataCollection/id($target)
531
532
533
534
    return
        element xhtml:li {
            attribute class {
                "registerEintrag",
Mathias Goebel's avatar
Mathias Goebel committed
535
                if( $entry >> $targetNode )
536
537
538
539
540
                then "up"
                else "down"
            },
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
541
                    $labelMain/text()
542
543
544
545
546
547
548
            },
            element xhtml:ul {
                element xhtml:li {
                attribute class { "pointer" },
                "siehe: ",
                    element xhtml:a {
                        attribute href { "?e=" || $target },
549
550
551
                        try {
                             string($targetNode/*[1])
                         } catch * {
Mathias Goebel's avatar
Mathias Goebel committed
552
                             (: TODO remove try catch when the data is better :)
553
554
                             "multiple entities found: " || string-join(($targetNode ! serialize(.)), " AND ")
                         }
555
556
557
558
559
                    }
                }
            }
        }
};
560

Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
561
562
563
(:
 : parses a tei:bibl and mainly prepares a list item with a link to the entity
 :)
564
565
566
567
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
568
    let $targetNode := $f-indexproc:dataCollection/id($biblId)[. instance of element(tei:bibl)]
569
570
571
572
573
574
575
    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
576
            $targetNode/tei:choice/tei:abbr/string() ||
577
578
579
580
581
582
583
            (if($bibl/tei:citedRange)
            then ":&#160;" || $bibl/tei:citedRange
            else ())
            }
        }
};

584
585
586
587
588
589
590
591
592
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
593
594
(:~
 : parser for listEvents/event entities
595
 : @param $eventDoc – the tei:listEvent containing all entries
Mathias Goebel's avatar
Mathias Goebel committed
596
 :  :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
597
declare function f-indexproc:events($eventDoc as element(tei:listEvent))
598
as element(xhtml:div) {
Mathias Goebel's avatar
   
Mathias Goebel committed
599
<xhtml:div id="{ string-join(($eventDoc/local-name(), $eventDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
600
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
601
602
    {for $eventList in $eventDoc/tei:listEvent
    return
Mathias Goebel's avatar
Mathias Goebel committed
603
604
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
605
                <h4 class="panel-title">{$eventList/tei:head/text()}</h4>
Mathias Goebel's avatar
Mathias Goebel committed
606
607
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
608
                <ul class="listEvent">
609
{
Mathias Goebel's avatar
Mathias Goebel committed
610
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
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)
628
}
Mathias Goebel's avatar
Mathias Goebel committed
629
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
630
631
            </xhtml:div>
        </xhtml:div>
632
    }
Mathias Goebel's avatar
Mathias Goebel committed
633
634
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
635
636
};

637
declare function local:prepare-event($event as element(tei:event))
638
as element(xhtml:li) {
639
640
641
642
643
644
645
(: 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
646
    let $wheres := tokenize($event/@where, " ") ! substring-after(., ":")
647
648
649
650
651
652
    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
653
return
654
655
656
    element xhtml:li {
        attribute id { string($id) },
        local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
657
        (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
658
        local:entry-link($id),
659
660
        element xhtml:span {
                attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
661
                $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
662
            },
663
        element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
664
            (: variant :)
665
            local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
666
            (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
667
            local:idno($labelAlt),
Mathias Goebel's avatar
Mathias Goebel committed
668
            (: note :)
669
            local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
670
            (: where :)
Mathias Goebel's avatar
Mathias Goebel committed
671
            for $where in $wheres return
672
673
674
            element xhtml:li {
                attribute class { "where" },
                element xhtml:a {
Mathias Goebel's avatar
Mathias Goebel committed
675
                attribute href { "register-listPlace.html?e="|| $where },
Mathias Goebel's avatar
Mathias Goebel committed
676
677
                <xhtml:i class="fa fa-map-marker" aria-hidden="true"></xhtml:i>,
                "&#160;",
Mathias Goebel's avatar
Mathias Goebel committed
678
                $f-indexproc:dataCollection/id($where)/*[1]/string()
Mathias Goebel's avatar
Mathias Goebel committed
679
680
681
                }
            },
            (: bibl :)
682
            local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
683
            (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
684
            local:links($links),
685
            local:li-code($event)
Mathias Goebel's avatar
Mathias Goebel committed
686
687
        }
    }
Mathias Goebel's avatar
Mathias Goebel committed
688
689
};

Mathias Goebel's avatar
Mathias Goebel committed
690
(:~
Mathias Goebel's avatar
Mathias Goebel committed
691
 : parser for tei:listOrg, returns the index of orgnaisations.
Mathias Goebel's avatar
Mathias Goebel committed
692
 :  :)
Mathias Goebel's avatar
   
Mathias Goebel committed
693
694
695
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
696
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
697
698
    {for $orgList in $orgDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
699
700
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
701
                <h4 class="panel-title">{ $orgList/tei:head/text() }</h4>
Mathias Goebel's avatar
Mathias Goebel committed
702
703
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
704
                <ul class="listOrg">
705
{
Mathias Goebel's avatar
Mathias Goebel committed
706
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
707
708
709
710
711
712
713
714
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
715
else
Mathias Goebel's avatar
Mathias Goebel committed
716
717
718
719
720
721
722
  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)
723
}
Mathias Goebel's avatar
Mathias Goebel committed
724
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
725
726
            </xhtml:div>
        </xhtml:div>
727
    }
Mathias Goebel's avatar
Mathias Goebel committed
728
729
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
   
Mathias Goebel committed
730
731
return
    $result
Mathias Goebel's avatar
Mathias Goebel committed
732
733
};

Mathias Goebel's avatar
Mathias Goebel committed
734
735
736
737
(:~
 : transforms a single tei:org element to a xhtml:li
 : @since 1.0
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
738
739
declare function local:prepare-org($org as element(tei:org))
as element(xhtml:li) {
740
741
742
743
744
745
(: 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
746
    let $id := $org/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
747
    let $labelMain := ($org/tei:orgName)[1]
Mathias Goebel's avatar
Mathias Goebel committed
748
    let $idnos := $org/tei:idno
Mathias Goebel's avatar
Mathias Goebel committed
749
    let $variant := $org/tei:orgName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
750
751
752
753
    let $note := $org/tei:note
    let $bibl := $org/tei:bibl
    let $links := $org/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
return
754
755
756
    element xhtml:li {
        attribute id { string($id) },
        local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
757
        (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
758
        local:entry-link($id),
759
760
        element xhtml:span {
                attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
761
                $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
762
            },
763
        element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
764
            (: variant :)
765
            local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
766
            (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
767
            local:idno($idnos),
Mathias Goebel's avatar
Mathias Goebel committed
768
            (: note :)
769
            local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
770
            (: bibl :)
771
            local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
772
            (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
773
            local:links($links),
Mathias Goebel's avatar
Mathias Goebel committed
774
            local:li-code($org)
Mathias Goebel's avatar
Mathias Goebel committed
775
776
        }
    }
Mathias Goebel's avatar
Mathias Goebel committed
777
778
};

Mathias Goebel's avatar
Mathias Goebel committed
779
(:~
Mathias Goebel's avatar
Mathias Goebel committed
780
 : parser for tei:listPerson, returns the index of persons
Mathias Goebel's avatar
Mathias Goebel committed
781
 :   :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
782
declare function f-indexproc:persons($persDoc as element(tei:listPerson))
Mathias Goebel's avatar
Mathias Goebel committed
783
as element(xhtml:div) {
Mathias Goebel's avatar
Mathias Goebel committed
784
(: main tab :)
Mathias Goebel's avatar
   
Mathias Goebel committed
785
<xhtml:div id="{ string-join(($persDoc/local-name(), $persDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
786
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
787
788
    {for $persList in $persDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
789
790
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
791
792
                <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
793
794
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
795
                <ul class="listPerson">
796
{
Mathias Goebel's avatar
Mathias Goebel committed
797
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
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)
814
}
Mathias Goebel's avatar
Mathias Goebel committed
815
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
816
817
            </xhtml:div>
        </xhtml:div>
818
    }
Mathias Goebel's avatar
Mathias Goebel committed
819
820
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
821
822
};

Mathias Goebel's avatar
Mathias Goebel committed
823
824
declare function local:prepare-person($pers as element(*)+)
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
825
826
827
828
(: check if the item points to another entity :)
if( not(exists($pers/@xml:id)) )
then
    (: pointer :)
829
    local:pointer($pers)
Mathias Goebel's avatar
Mathias Goebel committed
830
831
832
else
    (: entity :)
    let $id := $pers/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
833
834
    let $labelMain := $pers/tei:persName[1]
    let $labelAlt := $pers/tei:persName[not(@type="variant")][position() gt 1]
Mathias Goebel's avatar
Mathias Goebel committed
835
    let $variant := $pers/tei:persName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
836
837
838
839
840
841
842
    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
843
844
    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
845
846
    let $links := $pers/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
    return
847
848
849
        element xhtml:li {
            attribute id { string($id) },
            local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
850
            (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
851
            local:entry-link($id),
852
853
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
854
                    $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
855
                },
856
            element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
857
                (: variant :)
858
                local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
859
                (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
860
                for $l in $labelAlt
Mathias Goebel's avatar
Mathias Goebel committed
861
                return
862
863
                    element xhtml:li {
                    attribute class {"label-" || string($l/@type)},
Mathias Goebel's avatar
Mathias Goebel committed
864
865
866
867
868
                    $l/text(),
                    if($l/@type = "variant")
                    then ()
                    else (
                        "&#160;",
869
870
                        element xhtml:a {
                            attribute href { string($l/@xml:base) || string($l) },
Mathias Goebel's avatar
Mathias Goebel committed
871
872
873
874
875
                            <xhtml:i title="Link zu externer Ressource" class="fa fa-external-link"></xhtml:i>
                        }
                    )
                },
                (: idno :)
876
                local:idno($idnos),
Mathias Goebel's avatar
Mathias Goebel committed
877
878
                (: birth, death :)
                if( not($birth or $death) ) then () else
879
                    element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
880
881
882
883
884
885
886
                        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
887
888
                    element xhtml:li {
                        attribute class { "occupation" },
Mathias Goebel's avatar
Mathias Goebel committed
889
890
891
892
                        $o/text()
                    },
                for $s in $state
                return
893
894
                    element xhtml:li {
                        attribute class { "state" },
Mathias Goebel's avatar
Mathias Goebel committed
895
896
                        $s/text()
                    },
897
898
899
900
901
902
903
904
905
906
907
908
909
910
                (: 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
911
                                $f-indexproc:dataCollection/id($memberId)/*[1]/string()
912
913
914
915
916
917
                                }
                            }
                    }
                },
                if (not(exists($creator))) then () else
                local:creator($creator),
Mathias Goebel's avatar
Mathias Goebel committed
918
                (: note :)
919
                local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
920
                (: bibl :)
921
                local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
922
                (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
923
                local:links($links),
Mathias Goebel's avatar
Mathias Goebel committed
924
                local:li-code($pers)
Mathias Goebel's avatar
Mathias Goebel committed
925
926
927
928
            }
        }
};

Mathias Goebel's avatar
Mathias Goebel committed
929
930
931
(:~
 : prepares the index of geographical references
 :  :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
932
declare function f-indexproc:places($listPlace as element(tei:listPlace))
Mathias Goebel's avatar
Mathias Goebel committed
933
as element(xhtml:div) {
Mathias Goebel's avatar
   
Mathias Goebel committed
934
<xhtml:div id="{ string-join(($listPlace/local-name(), $listPlace/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
935
936
937
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
938
939
                <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
940
941
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
942
                <ul class="listPlace">
943
{
Mathias Goebel's avatar
Mathias Goebel committed
944
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
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)
964
}
Mathias Goebel's avatar
Mathias Goebel committed
965
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
966
967
968
969
            </xhtml:div>
        </xhtml:div>
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
970
971
};

Mathias Goebel's avatar
Mathias Goebel committed
972
973
(:~
 : transformation of a single geographical reference item  :)
Mathias Goebel's avatar
Mathias Goebel committed
974
975
declare function local:prepare-place($place as element(tei:place))
as element(xhtml:ul) {
Mathias Goebel's avatar
Mathias Goebel committed
976
977
978
979
(: check if the item points to another entity :)
if( not(exists($place/@xml:id)) )
then
    (: pointer :)
980
    local:pointer($place)
Mathias Goebel's avatar
Mathias Goebel committed
981
982
983
else
    (: entity :)
    let $id := $place/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
984
985
    let $labelMain := $place/tei:placeName[1]
    let $labelAlt := $place/tei:placeName[not(@type="variant")][position() gt 1]
Mathias Goebel's avatar
Mathias Goebel committed
986
    let $variant := $place/tei:placeName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
987
988
    let $idnos := $place/tei:idno
    let $note := $place/tei:note
989
    let $creator := $place/tei:linkGrp/tei:link[@corresp="http://purl.org/dc/terms/creator"]
Mathias Goebel's avatar
Mathias Goebel committed
990
    let $bibl := $place/tei:bibl
Mathias Goebel's avatar
Mathias Goebel committed
991
    let $tookPlaceAt := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P7_took_place_at"]
992
    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
993
994
    let $links := $place/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
    return
995
996
997
        element xhtml:li {
            attribute id { string($id) },
            local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
998
            (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
999
            local:entry-link($id),
1000
1001
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
1002
                    $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
1003
                },
1004
            element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
1005
                (: variant :)
1006
                local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
1007
                (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
1008
                for $l in $labelAlt
Mathias Goebel's avatar
Mathias Goebel committed
1009
                return
1010
1011
                    element xhtml:li {
                    attribute class {"label-" || string($l/@type)},
Mathias Goebel's avatar
Mathias Goebel committed
1012
1013
1014
1015
1016
                    $l/text(),
                    if($l/@type = "variant")
                    then ()
                    else (
                        "&#160;",
1017
1018
                        element xhtml:a {
                            attribute href { string($l/@xml:base) || string($l) },
Mathias Goebel's avatar
Mathias Goebel committed
1019
1020
1021
1022
1023
                            <xhtml:i title="Link zu externer Ressource" class="fa fa-external-link"></xhtml:i>
                        }
                    )
                },
                (: idno :)
1024
                local:idno($idnos),
1025
1026
1027
                (: creator :)
                if (not(exists($creator))) then () else
                local:creator($creator),
Mathias Goebel's avatar
Mathias Goebel committed
1028
                (: note :)
1029
                local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
1030
                (: bibl :)
1031
                local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
1032
1033
                (: events took place :)
                for $l in $tookPlaceAt
1034
                let $id := $l/@target => substring-after(":") => substring-before(" ")
Mathias Goebel's avatar
Mathias Goebel committed
1035
1036
1037
1038
1039
                return
                    element xhtml:li {
                        attribute class { "took-place-at" },
                        element xhtml:a {
                        attribute href { "?e=" || $id },
Mathias Goebel's avatar
Mathias Goebel committed
1040
                        <xhtml:i class="fa fa-flag" aria-hidden="true"></xhtml:i>,
Mathias Goebel's avatar
Mathias Goebel committed
1041
                        "&#160;",
Mathias Goebel's avatar
Mathias Goebel committed
1042
                        $f-indexproc:dataCollection/id($id)/*[1]/string()
Mathias Goebel's avatar
Mathias Goebel committed
1043
1044
                        }
                    },
1045
                (: former_or_current_location :)
1046
                local:has-former-or-current-location($formerCurrentLocation),
Mathias Goebel's avatar
Mathias Goebel committed
1047
                (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
1048
                local:links($links),
Mathias Goebel's avatar
Mathias Goebel committed
1049
                local:li-code($place),
1050
                element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
1051
1052
1053
1054
1055
1056
1057
                  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
1058
1059
1060
1061
1062
                }
            }
        }
};

Mathias Goebel's avatar
Mathias Goebel committed
1063
1064
(:~
 : prepares the list of works :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
1065
declare function f-indexproc:works($wrkDoc as element(tei:list))
Mathias Goebel's avatar
Mathias Goebel committed
1066
as element(xhtml:div) {
Mathias Goebel's avatar
   
Mathias Goebel committed
1067
<xhtml:div id="{ string-join(($wrkDoc/local-name(), $wrkDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
1068
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
1069
1070
    {for $wrkList in $wrkDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
1071
1072
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
1073
1074
                <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
1075
1076
            </xhtml:div>
            <xhtml:div class="panel-body">
1077
                <ul class="workList">
1078
{
Mathias Goebel's avatar
Mathias Goebel committed
1079
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
1080
then
1081
for $i in $wrkList//tei:item[not(tei:list)]
Mathias Goebel's avatar
Mathias Goebel committed
1082
order by (lower-case(($i/tei:name[not(@type)]/text())[1]) => replace("ä", "ae") => replace("ö", "oe") => replace("ü", "ue") )
1083
return local:prepare-work($i)
1084
else
1085
1086
1087
for $i in $wrkList//tei:item
    [not(tei:list)]
    [tei:linkGrp/tei:link
Mathias Goebel's avatar
Mathias Goebel committed
1088
        [starts-with(@target, $f-indexproc:getNotebook)]]
Mathias Goebel's avatar
Mathias Goebel committed
1089
order by (lower-case(($i/tei:name[not(@type)]/text())[1]) => replace("ä", "ae") => replace("ö", "oe") => replace("ü", "ue") )
1090
return local:prepare-work($i)
1091
}
1092
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
1093
1094
            </xhtml:div>
        </xhtml:div>
1095
    }
Mathias Goebel's avatar
Mathias Goebel committed
1096
1097
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
1098
1099
};

Mathias Goebel's avatar
Mathias Goebel committed
1100
1101
(:~
 : prepares a single work item :)
Mathias Goebel's avatar
Mathias Goebel committed
1102
1103
declare function local:prepare-work($work as element(tei:item))
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
1104
1105
1106
1107
(: check if the item points to another entity :)
if( not(exists($work/@xml:id)) )
then
    (: pointer :)
1108
    local:pointer($work)
Mathias Goebel's avatar
Mathias Goebel committed
1109
1110
1111
else
    (: entity :)
    let $id := $work/@xml:id