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

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

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

(:~
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
61
62
63
64
65
66
67
 : 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
68
69
70
71
72
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
73
    case "person" return
Mathias Goebel's avatar
Mathias Goebel committed
74
75
76
        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
77
    case "personGrp" return
Mathias Goebel's avatar
Mathias Goebel committed
78
79
80
81
82
83
84
85
86
87
        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
88
89
90
(:~
 : Helper function to use an efficient map data type to store the model.
 :)
Mathias Goebel's avatar
Mathias Goebel committed
91
declare function local:main-map($index as xs:string+)
Mathias Goebel's avatar
Mathias Goebel committed
92
as map() {
Mathias Goebel's avatar
Mathias Goebel committed
93
94
let $nodes := local:getNodes()
return
Mathias Goebel's avatar
Mathias Goebel committed
95
map:new(
Mathias Goebel's avatar
Mathias Goebel committed
96
97
    for $n in 1 to array:size($nodes)
    let $node := $nodes?($n)
Mathias Goebel's avatar
Mathias Goebel committed
98
99
    let $localId := string-join(($node/local-name(), $node/@type), "-")
    let $content :=
Mathias Goebel's avatar
Mathias Goebel committed
100
        for $node in $node return
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
101
        switch ($node/local-name())
Mathias Goebel's avatar
   
Mathias Goebel committed
102
103
104
105
106
107
108
109
110
            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
111
                f-indexproc:works($node)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
112
            default return error(QName("FONTANE", "INDEX1"), "unknown node-name: " || $node/local-name())
Mathias Goebel's avatar
Mathias Goebel committed
113
114
115
116
    return
        map:entry(
            $localId,
            map:new((
Mathias Goebel's avatar
Mathias Goebel committed
117
                map:entry("content", $content)
Mathias Goebel's avatar
Mathias Goebel committed
118
119
120
121
122
            ))
        )
    )
};

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

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

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

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

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

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

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

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

(:~
218
 : transforms tei:idno to xhtml:li
Mathias Goebel's avatar
Mathias Goebel committed
219
 : @param $idnos – tei element (idno and label) with reference to authority file
220
221
222
 : 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
223
as element(xhtml:li)* {
224
225
226
227
228
229
230
231
232
233
for $idno in $idnos
let $str := string($idno)
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>
234
235
236
237
238
239
240
241
242
243
244
        },
        (: ADB :)
        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
245
                    else "NDB-Eintrag basierend auf GND"
246
247
248
249
250
251
252
                },
                attribute href {$url},
                if(ends-with($url, "adbcontent"))
                then "ADB"
                else "NDB"
            })
        else ()
253
254
255
256
257
258
259
    }
};

(:~
 : transformation from tei:note to xhtml:li
 :  :)
declare function local:note($note as element(tei:note)*)
Mathias Goebel's avatar
Mathias Goebel committed
260
as element(xhtml:li)* {
261
262
263
264
for $n in $note
    return
        element xhtml:li {
            attribute class { "tei-note" },
Mathias Goebel's avatar
Mathias Goebel committed
265
266
267
268
269
270
271
            $n/text(),
            for $ptr in $n/tei:ptr[@type = "Figurenlexikon"]
            return
                element xhtml:a {
                    attribute href { string($ptr/@target) },
                    string($n/@type)
                }
272
273
274
        }
};

275
276
277
278
279
(:~
 : 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) {
280
281
282
283
284
285
286
287

if($creators[1]/parent::*/parent::tei:person)
then
    (: person item that is the creator :)
element xhtml:li {
    attribute class { "creator" },
    "Urheber:",
    element xhtml:ul {
288
        attribute class {"workList"},
289
290
291
292
293
294
295
296
297
298
299
300
301
302
        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 {
303
                attribute class {"item"},
304
305
306
307
308
                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])
309
310
311
312
313
314
315
316
317
                },
                element xhtml:span {
                    attribute class { "load-entity" },
                    attribute data-load { $targetId },
                    text {" "},
                    element xhtml:i {
                        attribute class {"fa fa-plus-square-o"},
                        attribute aria-hidden {"true"}
                    }
318
319
320
321
322
323
                }
            }
    }
}
else
    (: work item with creator :)
324
325
326
327
element xhtml:li {
    attribute class { "creator" },
    "Urheber:",
    element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
328
        attribute class {"listPerson"},
329
330
        for $creator in $creators
        let $target := $creator/@target => substring-after(" ")
Mathias Goebel's avatar
Mathias Goebel committed
331
        let $targetId := $target => substring-after(":")
332
        let $targetNode := $f-indexproc:dataCollection/id($targetId)
Mathias Goebel's avatar
   
Mathias Goebel committed
333
334
335
        let $htmlResource :=
(: TODO remove condition for final production release :)
            if($targetNode)
336
337
338
339
            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
340
            else "target-not-available"
341
342
        return
            element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
343
                attribute class {"person"},
344
                element xhtml:a {
345
346
347
348
                    attribute href { "register-" || $htmlResource || ".html?e=" || string-join($targetId) },
                    if($targetNode[2])
                    then "two entities with same ID: " || $targetId
                    else string($targetNode/*[1])
349
350
351
352
353
354
                }
            }
    }
}
};

355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
declare function local:has-former-or-current-location($links as element(tei:link)*)
as element(xhtml:li)* {
for $link in $links
let $id := $link/@target => substring-after(":") => substring-before(" ")
return
    element xhtml:li {
        attribute class { "former-or-current-location" },
        element xhtml:a {
        attribute href { "?e=" || $id },
        <xhtml:i class="fa fa-map-marker" aria-hidden="true"></xhtml:i>,
        "&#160;",
        $f-indexproc:dataCollection/id($id)/*[1]/string()
        }
    }
};

371
372
(:~
 : a list item with a list of links
Mathias Goebel's avatar
Mathias Goebel committed
373
 :)
Mathias Goebel's avatar
Mathias Goebel committed
374
declare function local:links($links as element(tei:link)*)
Mathias Goebel's avatar
Mathias Goebel committed
375
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
376
let $notebookUris := $links ! (substring-after(./@target, $f-indexproc:targetStart) => substring(1,5) => distinct-values())
Mathias Goebel's avatar
Mathias Goebel committed
377
378
379
380
381
382
383
384
385
386
387
388
389
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)
        }
390
391
392
393
394
395
396
    }
};

(:~
 : create list items containing links
 :   :)
declare function local:link($map as map()*)
Mathias Goebel's avatar
Mathias Goebel committed
397
as element(xhtml:li)* {
398
399
    for $tguri in map:keys($map)
    let $resolve := local:resolve-name($tguri)
Mathias Goebel's avatar
   
Mathias Goebel committed
400
    order by $resolve
401
402
    return
        element xhtml:li {
Mathias Goebel's avatar
   
Mathias Goebel committed
403
            replace($resolve, "([A-E])0(\d)", "$1$2") || ": ",
404
405
            element xhtml:ul {
                attribute class {"link-list-horizontal"},
406
407
408
                let $this-map := $map($tguri)
                let $surface-sequence := $this-map ! (./@target => substring-after("surface[@n='") => substring-before("']//"))
                for $link at $pos in $this-map
409
                let $page := $link/@target => substring-after("surface[@n='") => substring-before("']//")
410
411
412
                let $index-of := index-of($surface-sequence, $page)
                let $count := count( $index-of )
                where $pos = $index-of[1]
413
414
415
416
417
418
                return
                    element xhtml:li {
                        element xhtml:a {
                            attribute href {
                                "edition.html?id=%2Fxml%2Fdata%2F" || $tguri
                                || ".xml&amp;page=" || $page
419
                                || "&amp;target=" || string($link/parent::tei:*/parent::tei:*/@xml:id)
420
                            },
421
422
423
                            f-misc:n-translate($page),
                            if($count eq 1) then ()
                            else (" ", <xhtml:span title="Anzahl an Vorkommnissen auf dieser Seite">({$count})</xhtml:span>)
424
425
426
427
428
429
                        }
                    }
            }
        }
};

Mathias Goebel's avatar
Mathias Goebel committed
430
431
(:~
 : prepares a link to the current entry
Mathias Goebel's avatar
Mathias Goebel committed
432
 : @param $id – the xml:id of the currently processed element
Mathias Goebel's avatar
Mathias Goebel committed
433
:)
Mathias Goebel's avatar
Mathias Goebel committed
434
declare function local:entry-link($id as attribute(xml:id))
Mathias Goebel's avatar
Mathias Goebel committed
435
436
437
438
439
as element(xhtml:span) {
    element xhtml:span {
        attribute class {"registerLink"},
        element xhtml:a {
            attribute href {
Mathias Goebel's avatar
Mathias Goebel committed
440
                "register-" || local:get-list-by-entity($id/parent::*) || ".html?e=" || $id
Mathias Goebel's avatar
Mathias Goebel committed
441
442
443
444
445
446
                },
            <xhtml:i title="Link zu diesem Eintrag" class="fa fa-link"></xhtml:i>
        }
    }
};

Mathias Goebel's avatar
Mathias Goebel committed
447
448
449
450
(:~
 : creates a xhtml list item containing serialized code.
 : @param $node – a single element
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
451
452
declare function local:li-code($node as element(*))
as element(xhtml:li) {
453
454
455
456
element xhtml:li {
    attribute class {"register-code"},
    element xhtml:span {
        attribute class {"registerCode"},
Mathias Goebel's avatar
Mathias Goebel committed
457
458
            <xhtml:i title="Zeige XML" class="fa fa-code"></xhtml:i>
    },
459
460

    code:main($node)
Mathias Goebel's avatar
Mathias Goebel committed
461
}
Mathias Goebel's avatar
Mathias Goebel committed
462
463
};

464
465
466
467
468
(:~
 : 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
469
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
470
    let $labelMain := ($entry/*)[1]
471
    let $target := $entry/tei:note/tei:ptr/@target => substring-after('#')
Mathias Goebel's avatar
Mathias Goebel committed
472
    let $targetNode := $f-indexproc:dataCollection/id($target)
473
474
475
476
    return
        element xhtml:li {
            attribute class {
                "registerEintrag",
Mathias Goebel's avatar
Mathias Goebel committed
477
                if( $entry >> $targetNode )
478
479
480
481
482
                then "up"
                else "down"
            },
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
483
                    $labelMain/text()
484
485
486
487
488
489
490
            },
            element xhtml:ul {
                element xhtml:li {
                attribute class { "pointer" },
                "siehe: ",
                    element xhtml:a {
                        attribute href { "?e=" || $target },
491
492
493
                        try {
                             string($targetNode/*[1])
                         } catch * {
Mathias Goebel's avatar
Mathias Goebel committed
494
                             (: TODO remove try catch when the data is better :)
495
496
                             "multiple entities found: " || string-join(($targetNode ! serialize(.)), " AND ")
                         }
497
498
499
500
501
                    }
                }
            }
        }
};
502

Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
503
504
505
(:
 : parses a tei:bibl and mainly prepares a list item with a link to the entity
 :)
506
507
508
509
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
510
    let $targetNode := $f-indexproc:dataCollection/id($biblId)[. instance of element(tei:bibl)]
511
512
513
514
515
516
517
    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
518
            $targetNode/tei:choice/tei:abbr/string() ||
519
520
521
522
523
524
525
            (if($bibl/tei:citedRange)
            then ":&#160;" || $bibl/tei:citedRange
            else ())
            }
        }
};

526
527
528
529
530
531
532
533
534
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
535
536
(:~
 : parser for listEvents/event entities
537
 : @param $eventDoc – the tei:listEvent containing all entries
Mathias Goebel's avatar
Mathias Goebel committed
538
 :  :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
539
declare function f-indexproc:events($eventDoc as element(tei:listEvent))
540
as element(xhtml:div) {
Mathias Goebel's avatar
   
Mathias Goebel committed
541
<xhtml:div id="{ string-join(($eventDoc/local-name(), $eventDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
542
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
543
544
    {for $eventList in $eventDoc/tei:listEvent
    return
Mathias Goebel's avatar
Mathias Goebel committed
545
546
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
547
                <h4 class="panel-title">{$eventList/tei:head/text()}</h4>
Mathias Goebel's avatar
Mathias Goebel committed
548
549
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
550
                <ul class="listEvent">
551
{
Mathias Goebel's avatar
Mathias Goebel committed
552
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
553
554
then $eventList/tei:event ! local:prepare-event(.)
else $eventList/tei:event
555
    [tei:linkGrp/tei:link
Mathias Goebel's avatar
Mathias Goebel committed
556
    [starts-with(@target, $f-indexproc:getNotebook)]] ! local:prepare-event(.)
557
}
Mathias Goebel's avatar
Mathias Goebel committed
558
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
559
560
            </xhtml:div>
        </xhtml:div>
561
    }
Mathias Goebel's avatar
Mathias Goebel committed
562
563
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
564
565
};

566
declare function local:prepare-event($event as element(tei:event))
567
as element(xhtml:li) {
568
569
570
571
572
573
574
(: 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
575
    let $wheres := tokenize($event/@where, " ") ! substring-after(., ":")
576
577
578
579
580
581
    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
582
return
583
584
585
    element xhtml:li {
        attribute id { string($id) },
        local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
586
        (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
587
        local:entry-link($id),
588
589
        element xhtml:span {
                attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
590
                $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
591
            },
592
        element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
593
            (: variant :)
594
            local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
595
            (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
596
            local:idno($labelAlt),
Mathias Goebel's avatar
Mathias Goebel committed
597
            (: note :)
598
            local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
599
            (: where :)
Mathias Goebel's avatar
Mathias Goebel committed
600
            for $where in $wheres return
601
602
603
            element xhtml:li {
                attribute class { "where" },
                element xhtml:a {
Mathias Goebel's avatar
Mathias Goebel committed
604
                attribute href { "register-listPlace.html?e="|| $where },
Mathias Goebel's avatar
Mathias Goebel committed
605
606
                <xhtml:i class="fa fa-map-marker" aria-hidden="true"></xhtml:i>,
                "&#160;",
Mathias Goebel's avatar
Mathias Goebel committed
607
                $f-indexproc:dataCollection/id($where)/*[1]/string()
Mathias Goebel's avatar
Mathias Goebel committed
608
609
610
                }
            },
            (: bibl :)
611
            local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
612
            (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
613
            local:links($links),
614
            local:li-code($event)
Mathias Goebel's avatar
Mathias Goebel committed
615
616
        }
    }
Mathias Goebel's avatar
Mathias Goebel committed
617
618
};

Mathias Goebel's avatar
Mathias Goebel committed
619
(:~
Mathias Goebel's avatar
Mathias Goebel committed
620
 : parser for tei:listOrg, returns the index of orgnaisations.
Mathias Goebel's avatar
Mathias Goebel committed
621
 :  :)
Mathias Goebel's avatar
   
Mathias Goebel committed
622
623
624
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
625
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
626
627
    {for $orgList in $orgDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
628
629
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
630
                <h4 class="panel-title">{ $orgList/tei:head/text() }</h4>
Mathias Goebel's avatar
Mathias Goebel committed
631
632
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
633
                <ul class="listOrg">
634
{
Mathias Goebel's avatar
Mathias Goebel committed
635
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
636
then $orgList/tei:org ! local:prepare-org(.)
Mathias Goebel's avatar
   
Mathias Goebel committed
637
638
else
    $orgList/tei:org
639
    [tei:linkGrp/tei:link
Mathias Goebel's avatar
Mathias Goebel committed
640
    [starts-with(@target, $f-indexproc:getNotebook)]] ! local:prepare-org(.)
641
}
Mathias Goebel's avatar
Mathias Goebel committed
642
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
643
644
            </xhtml:div>
        </xhtml:div>
645
    }
Mathias Goebel's avatar
Mathias Goebel committed
646
647
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
   
Mathias Goebel committed
648
649
return
    $result
Mathias Goebel's avatar
Mathias Goebel committed
650
651
};

Mathias Goebel's avatar
Mathias Goebel committed
652
653
654
655
(:~
 : transforms a single tei:org element to a xhtml:li
 : @since 1.0
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
656
657
declare function local:prepare-org($org as element(tei:org))
as element(xhtml:li) {
658
659
660
661
662
663
(: 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
664
    let $id := $org/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
665
    let $labelMain := ($org/tei:orgName)[1]
Mathias Goebel's avatar
Mathias Goebel committed
666
    let $idnos := $org/tei:idno
Mathias Goebel's avatar
Mathias Goebel committed
667
    let $variant := $org/tei:orgName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
668
669
670
671
    let $note := $org/tei:note
    let $bibl := $org/tei:bibl
    let $links := $org/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
return
672
673
674
    element xhtml:li {
        attribute id { string($id) },
        local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
675
        (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
676
        local:entry-link($id),
677
678
        element xhtml:span {
                attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
679
                $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
680
            },
681
        element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
682
            (: variant :)
683
            local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
684
            (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
685
            local:idno($idnos),
Mathias Goebel's avatar
Mathias Goebel committed
686
            (: note :)
687
            local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
688
            (: bibl :)
689
            local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
690
            (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
691
            local:links($links),
Mathias Goebel's avatar
Mathias Goebel committed
692
            local:li-code($org)
Mathias Goebel's avatar
Mathias Goebel committed
693
694
        }
    }
Mathias Goebel's avatar
Mathias Goebel committed
695
696
};

Mathias Goebel's avatar
Mathias Goebel committed
697
(:~
Mathias Goebel's avatar
Mathias Goebel committed
698
 : parser for tei:listPerson, returns the index of persons
Mathias Goebel's avatar
Mathias Goebel committed
699
 :   :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
700
declare function f-indexproc:persons($persDoc as element(tei:listPerson))
Mathias Goebel's avatar
Mathias Goebel committed
701
as element(xhtml:div) {
Mathias Goebel's avatar
Mathias Goebel committed
702
(: main tab :)
Mathias Goebel's avatar
   
Mathias Goebel committed
703
<xhtml:div id="{ string-join(($persDoc/local-name(), $persDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
704
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
705
706
    {for $persList in $persDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
707
708
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
709
710
                <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
711
712
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
713
                <ul class="listPerson">
714
{
Mathias Goebel's avatar
Mathias Goebel committed
715
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
716
717
then $persList/tei:* ! local:prepare-person(.)
else $persList/tei:*
718
    [tei:linkGrp/tei:link
Mathias Goebel's avatar
Mathias Goebel committed
719
    [starts-with(@target, $f-indexproc:getNotebook)]] ! local:prepare-person(.)
720
}
Mathias Goebel's avatar
Mathias Goebel committed
721
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
722
723
            </xhtml:div>
        </xhtml:div>
724
    }
Mathias Goebel's avatar
Mathias Goebel committed
725
726
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
727
728
};

Mathias Goebel's avatar
Mathias Goebel committed
729
730
declare function local:prepare-person($pers as element(*)+)
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
731
732
733
734
(: check if the item points to another entity :)
if( not(exists($pers/@xml:id)) )
then
    (: pointer :)
735
    local:pointer($pers)
Mathias Goebel's avatar
Mathias Goebel committed
736
737
738
else
    (: entity :)
    let $id := $pers/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
739
740
    let $labelMain := $pers/tei:persName[1]
    let $labelAlt := $pers/tei:persName[not(@type="variant")][position() gt 1]
Mathias Goebel's avatar
Mathias Goebel committed
741
    let $variant := $pers/tei:persName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
742
743
744
745
746
747
748
    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
749
750
    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
751
752
    let $links := $pers/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
    return
753
754
755
        element xhtml:li {
            attribute id { string($id) },
            local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
756
            (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
757
            local:entry-link($id),
758
759
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
760
                    $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
761
                },
762
            element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
763
                (: variant :)
764
                local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
765
                (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
766
                for $l in $labelAlt
Mathias Goebel's avatar
Mathias Goebel committed
767
                return
768
769
                    element xhtml:li {
                    attribute class {"label-" || string($l/@type)},
Mathias Goebel's avatar
Mathias Goebel committed
770
771
772
773
774
                    $l/text(),
                    if($l/@type = "variant")
                    then ()
                    else (
                        "&#160;",
775
776
                        element xhtml:a {
                            attribute href { string($l/@xml:base) || string($l) },
Mathias Goebel's avatar
Mathias Goebel committed
777
778
779
780
781
                            <xhtml:i title="Link zu externer Ressource" class="fa fa-external-link"></xhtml:i>
                        }
                    )
                },
                (: idno :)
782
                local:idno($idnos),
Mathias Goebel's avatar
Mathias Goebel committed
783
784
                (: birth, death :)
                if( not($birth or $death) ) then () else
785
                    element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
786
787
788
789
790
791
792
                        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
793
794
                    element xhtml:li {
                        attribute class { "occupation" },
Mathias Goebel's avatar
Mathias Goebel committed
795
796
797
798
                        $o/text()
                    },
                for $s in $state
                return
799
800
                    element xhtml:li {
                        attribute class { "state" },
Mathias Goebel's avatar
Mathias Goebel committed
801
802
                        $s/text()
                    },
803
804
805
806
807
808
809
810
811
812
813
814
815
816
                (: 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
817
                                $f-indexproc:dataCollection/id($memberId)/*[1]/string()
818
819
820
821
822
823
                                }
                            }
                    }
                },
                if (not(exists($creator))) then () else
                local:creator($creator),
Mathias Goebel's avatar
Mathias Goebel committed
824
                (: note :)
825
                local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
826
                (: bibl :)
827
                local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
828
                (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
829
                local:links($links),
Mathias Goebel's avatar
Mathias Goebel committed
830
                local:li-code($pers)
Mathias Goebel's avatar
Mathias Goebel committed
831
832
833
834
            }
        }
};

Mathias Goebel's avatar
Mathias Goebel committed
835
836
837
(:~
 : prepares the index of geographical references
 :  :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
838
declare function f-indexproc:places($listPlace as element(tei:listPlace))
Mathias Goebel's avatar
Mathias Goebel committed
839
as element(xhtml:div) {
Mathias Goebel's avatar
   
Mathias Goebel committed
840
<xhtml:div id="{ string-join(($listPlace/local-name(), $listPlace/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
841
842
843
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
844
845
                <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
846
847
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
848
                <ul class="listPlace">
849
{
Mathias Goebel's avatar
Mathias Goebel committed
850
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
851
852
then $listPlace/tei:place ! local:prepare-place(.)
else $listPlace/tei:place
853
    [tei:linkGrp/tei:link
Mathias Goebel's avatar
Mathias Goebel committed
854
    [starts-with(@target, $f-indexproc:getNotebook)]] ! local:prepare-place(.)
855
}
Mathias Goebel's avatar
Mathias Goebel committed
856
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
857
858
859
860
            </xhtml:div>
        </xhtml:div>
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
861
862
};

Mathias Goebel's avatar
Mathias Goebel committed
863
864
(:~
 : transformation of a single geographical reference item  :)
Mathias Goebel's avatar
Mathias Goebel committed
865
866
declare function local:prepare-place($place as element(tei:place))
as element(xhtml:ul) {
Mathias Goebel's avatar
Mathias Goebel committed
867
868
869
870
(: check if the item points to another entity :)
if( not(exists($place/@xml:id)) )
then
    (: pointer :)
871
    local:pointer($place)
Mathias Goebel's avatar
Mathias Goebel committed
872
873
874
else
    (: entity :)
    let $id := $place/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
875
876
    let $labelMain := $place/tei:placeName[1]
    let $labelAlt := $place/tei:placeName[not(@type="variant")][position() gt 1]
Mathias Goebel's avatar
Mathias Goebel committed
877
    let $variant := $place/tei:placeName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
878
879
    let $idnos := $place/tei:idno
    let $note := $place/tei:note
880
    let $creator := $place/tei:linkGrp/tei:link[@corresp="http://purl.org/dc/terms/creator"]
Mathias Goebel's avatar
Mathias Goebel committed
881
    let $bibl := $place/tei:bibl
Mathias Goebel's avatar
Mathias Goebel committed
882
    let $tookPlaceAt := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P7_took_place_at"]
883
    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
884
885
    let $links := $place/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
    return
886
887
888
        element xhtml:li {
            attribute id { string($id) },
            local:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
889
            (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
890
            local:entry-link($id),
891
892
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
893
                    $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
894
                },
895
            element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
896
                (: variant :)
897
                local:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
898
                (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
899
                for $l in $labelAlt
Mathias Goebel's avatar
Mathias Goebel committed
900
                return
901
902
                    element xhtml:li {
                    attribute class {"label-" || string($l/@type)},
Mathias Goebel's avatar
Mathias Goebel committed
903
904
905
906
907
                    $l/text(),
                    if($l/@type = "variant")
                    then ()
                    else (
                        "&#160;",
908
909
                        element xhtml:a {
                            attribute href { string($l/@xml:base) || string($l) },
Mathias Goebel's avatar
Mathias Goebel committed
910
911
912
913
914
                            <xhtml:i title="Link zu externer Ressource" class="fa fa-external-link"></xhtml:i>
                        }
                    )
                },
                (: idno :)
915
                local:idno($idnos),
916
917
918
                (: creator :)
                if (not(exists($creator))) then () else
                local:creator($creator),
Mathias Goebel's avatar
Mathias Goebel committed
919
                (: note :)
920
                local:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
921
                (: bibl :)
922
                local:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
923
924
                (: events took place :)
                for $l in $tookPlaceAt
925
                let $id := $l/@target => substring-after(":") => substring-before(" ")
Mathias Goebel's avatar
Mathias Goebel committed
926
927
928
929
930
                return
                    element xhtml:li {
                        attribute class { "took-place-at" },
                        element xhtml:a {
                        attribute href { "?e=" || $id },
Mathias Goebel's avatar
Mathias Goebel committed
931
                        <xhtml:i class="fa fa-flag" aria-hidden="true"></xhtml:i>,
Mathias Goebel's avatar
Mathias Goebel committed
932
                        "&#160;",
Mathias Goebel's avatar
Mathias Goebel committed
933
                        $f-indexproc:dataCollection/id($id)/*[1]/string()
Mathias Goebel's avatar
Mathias Goebel committed
934
935
                        }
                    },
936
                (: former_or_current_location :)
937
                local:has-former-or-current-location($formerCurrentLocation),
Mathias Goebel's avatar
Mathias Goebel committed
938
                (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
939
                local:links($links),
Mathias Goebel's avatar
Mathias Goebel committed
940
                local:li-code($place),
941
                element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
942
943
944
945
946
947
                    $place/tei:place ! local:prepare-place(.)
                }
            }
        }
};

Mathias Goebel's avatar
Mathias Goebel committed
948
949
(:~
 : prepares the list of works :)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
950
declare function f-indexproc:works($wrkDoc as element(tei:list))
Mathias Goebel's avatar
Mathias Goebel committed
951
as element(xhtml:div) {
Mathias Goebel's avatar
   
Mathias Goebel committed
952
<xhtml:div id="{ string-join(($wrkDoc/local-name(), $wrkDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
953
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
954
955
    {for $wrkList in $wrkDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
956
957
        <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">{$wrkList/tei:head/text()}</a>
                </h4>
Mathias Goebel's avatar
Mathias Goebel committed
960
961
            </xhtml:div>
            <xhtml:div class="panel-body">
962
                <ul class="workList">
963
{
Mathias Goebel's avatar
Mathias Goebel committed
964
if($f-indexproc:getNotebook = $f-indexproc:targetStart)
965
then
966
967
968
for $i in $wrkList//tei:item[not(tei:list)]
order by lower-case(($i/tei:name[not(@type)]/text())[1])
return local:prepare-work($i)
969
else
970
971
972
for $i in $wrkList//tei:item
    [not(tei:list)]
    [tei:linkGrp/tei:link
Mathias Goebel's avatar
Mathias Goebel committed
973
        [starts-with(@target, $f-indexproc:getNotebook)]]
974
975
order by lower-case(($i/tei:name[not(@type)]/text())[1])
return local:prepare-work($i)
976
}
977
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
978
979
            </xhtml:div>
        </xhtml:div>
980
    }
Mathias Goebel's avatar
Mathias Goebel committed
981
982
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
983
984
};

Mathias Goebel's avatar
Mathias Goebel committed
985
986
(:~
 : prepares a single work item :)
Mathias Goebel's avatar
Mathias Goebel committed
987
988
declare function local:prepare-work($work as element(tei:item))
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
989
990
991
992
(: check if the item points to another entity :)
if( not(exists($work/@xml:id)) )
then
    (: pointer :)
993
    local:pointer($work)
Mathias Goebel's avatar
Mathias Goebel committed
994
995
996
else
    (: entity :)
    let $id := $work/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
997
998
    let $labelMain := $work/tei:name[1]
    let $labelAlt := $work/tei:name[not(@type="variant")][position() gt 1]
Mathias Goebel's avatar
Mathias Goebel committed
999
    let $variant := $work/tei:name[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
1000
    let $idnos := $work/tei:idno
For faster browsing, not all history is shown. View entire blame