index-processor.xqm 47 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 ixp="http://fontane-nb.dariah.eu/index-processor";
12
import module namespace code="http://bdn-edition.de/ns/code-view";
Mathias Goebel's avatar
minor    
Mathias Goebel committed
13
14
import module namespace config="http://textgrid.de/ns/SADE/config" at "../config/config.xqm";
import module namespace f-misc="http://fontane-nb.dariah.eu/ns/SADE/misc" at "misc.xqm";
Mathias Goebel's avatar
Mathias Goebel committed
15
16
import module namespace functx="http://www.functx.com";

17

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

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

Mathias Goebel's avatar
Mathias Goebel committed
34
35
declare variable $ixp:dataPath := '/db/sade-projects/textgrid/data/xml/data/';
declare variable $ixp:dataCollection := collection($ixp:dataPath);
Mathias Goebel's avatar
Mathias Goebel committed
36

Mathias Goebel's avatar
Mathias Goebel committed
37
38
39
40
declare variable $ixp:BeaconMap := map:merge((
        ixp:beacon-parser(xs:anyURI("http://www.historische-kommission-muenchen-editionen.de/beacon_db_register.txt")),
        ixp:beacon-parser(xs:anyURI("http://www.historische-kommission-muenchen-editionen.de/beacon_ndb.txt")),
        ixp:beacon-parser(xs:anyURI("http://www.historische-kommission-muenchen-editionen.de/beacon_adb.txt"))
41
        ));
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
42
43
44
(:~
 : Helper function to collect all main nodes from the index files.
:)
Mathias Goebel's avatar
Mathias Goebel committed
45
declare function ixp:getNodes()
Mathias Goebel's avatar
   
Mathias Goebel committed
46
as array(*) {
Mathias Goebel's avatar
Mathias Goebel committed
47
48
49
50
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 :)
Mathias Goebel's avatar
Mathias Goebel committed
51
let $docs := $uris ! doc($ixp:dataPath || . || '.xml')
Mathias Goebel's avatar
Mathias Goebel committed
52

Mathias Goebel's avatar
   
Mathias Goebel committed
53
return
Mathias Goebel's avatar
Mathias Goebel committed
54
    [
Mathias Goebel's avatar
Mathias Goebel committed
55
    $docs//tei:body/tei:listEvent,
Mathias Goebel's avatar
Mathias Goebel committed
56
    $docs//tei:body/tei:listOrg,
Mathias Goebel's avatar
Mathias Goebel committed
57
58
59
60
    $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
61
    $docs//tei:body//tei:list[@type="Fontane"]
Mathias Goebel's avatar
Mathias Goebel committed
62
    ]
Mathias Goebel's avatar
Mathias Goebel committed
63
64
65
};

(:~
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
66
67
68
69
70
71
72
 : 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
73
declare function ixp:get-list-by-entity($entity as node()?)
Mathias Goebel's avatar
Mathias Goebel committed
74
75
76
77
as xs:string {
switch ( $entity/local-name() )
    case "event" return "listEvent"
    case "org" return "listOrg"
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
78
    case "person" return
Mathias Goebel's avatar
Mathias Goebel committed
79
        if($entity/ancestor::tei:item)
Mathias Goebel's avatar
Mathias Goebel committed
80
        then ixp:get-list-by-entity( $entity/ancestor::tei:item[last()] )
Mathias Goebel's avatar
Mathias Goebel committed
81
        else "listPerson"
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
82
    case "personGrp" return
Mathias Goebel's avatar
Mathias Goebel committed
83
        if($entity/ancestor::tei:item)
Mathias Goebel's avatar
Mathias Goebel committed
84
        then ixp:get-list-by-entity( $entity/ancestor::tei:item[last()] )
Mathias Goebel's avatar
Mathias Goebel committed
85
86
87
88
89
90
91
92
        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
Mathias Goebel committed
93
declare function ixp:get-icon-by-entity($entity as node())
Mathias Goebel's avatar
Mathias Goebel committed
94
95
96
97
98
99
100
101
102
103
104
105
as xs:string {
switch ( $entity/local-name() )
    case "event" return "fa-flag"
    case "org" return "fa-university"
    case "person" return "fa-user"
    case "personGrp" return "fa-users"
    case "place" return "fa-map-marker"
    case "item" return "fa-book"
    default return
        "fa-exclamation-triangle"
};

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

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

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

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

Mathias Goebel's avatar
Mathias Goebel committed
168
169
170
171
172
(:~
 : 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
173
declare function ixp:resolve-name($uri as xs:string)
Mathias Goebel's avatar
Mathias Goebel committed
174
as xs:string {
Mathias Goebel's avatar
Mathias Goebel committed
175
    let $title := string(doc($ixp:metaCollection || $uri || '.xml')//tgmd:title)
Mathias Goebel's avatar
Mathias Goebel committed
176
    return
Mathias Goebel's avatar
   
Mathias Goebel committed
177
178
179
        if($title = "")
        then $uri
        else $title
Mathias Goebel's avatar
Mathias Goebel committed
180
181
182
};

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

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

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

(:~
Mathias Goebel's avatar
Mathias Goebel committed
216
217
218
 : creates a list for label or name
 : @param $variant – a tei element containing any secondary label or name variant
 :)
Mathias Goebel's avatar
Mathias Goebel committed
219
declare function ixp:variant($variant as element()*)
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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 ",")
                }
        }
    }
};

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

Mathias Goebel's avatar
Mathias Goebel committed
288
declare function ixp:gnd-wikipedia($gndid-orig as xs:string)
289
290
291
292
293
294
295
296
297
298
299
300
301
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)
Mathias Goebel's avatar
Mathias Goebel committed
302
303
let $store :=
    if(config:get("sade.develop") = "true")
Mathias Goebel's avatar
Mathias Goebel committed
304
305
306
307
308
    then
        if(doc-available($gndCollection || $filename))
        then $gndCollection || $filename
        else
            xmldb:store($gndCollection, $filename, $response)
Mathias Goebel's avatar
Mathias Goebel committed
309
    else ()
310
311
312
313
return
    string($response//foaf:page/@rdf:resource)
};

Mathias Goebel's avatar
Mathias Goebel committed
314
declare function ixp:wikidata-wikipedia($wikidata-id as xs:string)
Mathias Goebel's avatar
Mathias Goebel committed
315
316
317
318
319
320
321
322
323
324
325
326
327
328
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]
};

329
330
331
(:~
 : transformation from tei:note to xhtml:li
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
332
declare function ixp:note($note as element(tei:note)*)
Mathias Goebel's avatar
Mathias Goebel committed
333
as element(xhtml:li)* {
334
335
336
337
for $n in $note
    return
        element xhtml:li {
            attribute class { "tei-note" },
Mathias Goebel's avatar
Mathias Goebel committed
338
339
340
341
342
343
344
            $n/text(),
            for $ptr in $n/tei:ptr[@type = "Figurenlexikon"]
            return
                element xhtml:a {
                    attribute href { string($ptr/@target) },
                    string($n/@type)
                }
345
346
347
        }
};

348
349
350
(:~
 : creates a list of all creations or points to the creator of a work
 : :)
Mathias Goebel's avatar
Mathias Goebel committed
351
declare function ixp:creator($creators as element(tei:link)+)
352
as element(xhtml:li) {
353
354
355
356
357
358

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
359
    "",
360
    element xhtml:ul {
361
        attribute class {"workList"},
362
363
364
        for $creator in $creators
        let $target := $creator/@target => substring-before(" ")
        let $targetId := $target => substring-after(":")
Mathias Goebel's avatar
Mathias Goebel committed
365
        let $targetNode := $ixp:dataCollection/id($targetId)
366
367
368
369
370
371
        let $htmlResource :=
(: TODO remove condition_s_ for final production release :)
            if($targetNode)
            then
                if($targetNode[2])
                then "two entities with same ID: " || $targetId
Mathias Goebel's avatar
Mathias Goebel committed
372
                else ixp:get-list-by-entity( $targetNode )
373
374
375
            else "target-not-available"
        return
            element xhtml:li {
376
                attribute class {"item"},
377
                element xhtml:a {
378
                    attribute href { "register.html?e=" || string-join($targetId) },
379
380
381
                    if($targetNode[2])
                    then "two entities with same ID: " || $targetId
                    else string($targetNode/*[1])
382
                },
Mathias Goebel's avatar
fix    
Mathias Goebel committed
383
                text{ "&#8195;" },
384
385
386
387
388
389
390
                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"}
                    }
391
392
393
394
395
396
                }
            }
    }
}
else
    (: work item with creator :)
397
398
element xhtml:li {
    attribute class { "creator" },
Mathias Goebel's avatar
Mathias Goebel committed
399
    "",
400
    element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
401
        attribute class {"listPerson"},
402
403
        for $creator in $creators
        let $target := $creator/@target => substring-after(" ")
Mathias Goebel's avatar
Mathias Goebel committed
404
        let $targetId := $target => substring-after(":")
Mathias Goebel's avatar
Mathias Goebel committed
405
        let $targetNode := $ixp:dataCollection/id($targetId)
Mathias Goebel's avatar
   
Mathias Goebel committed
406
407
408
        let $htmlResource :=
(: TODO remove condition for final production release :)
            if($targetNode)
409
410
411
            then
                if($targetNode[2])
                then "two entities with same ID: " || $targetId
Mathias Goebel's avatar
Mathias Goebel committed
412
                else ixp:get-list-by-entity( $targetNode )
Mathias Goebel's avatar
   
Mathias Goebel committed
413
            else "target-not-available"
414
415
        return
            element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
416
                attribute class {"person"},
417
                element xhtml:a {
418
                    attribute href { "register.html?e=" || string-join($targetId) },
419
420
421
                    if($targetNode[2])
                    then "two entities with same ID: " || $targetId
                    else string($targetNode/*[1])
422
423
424
425
426
427
                }
            }
    }
}
};

Mathias Goebel's avatar
Mathias Goebel committed
428
declare function ixp:has-former-or-current-location($links as element(tei:link)*)
429
430
as element(xhtml:li)* {
for $link in $links
Mathias Goebel's avatar
Mathias Goebel committed
431
432
433
434
435
436
437
let $thisId := string($link/parent::tei:linkGrp/parent::tei:*/@xml:id)
let $id := ($link/@target => replace("\w{3}:|#", "") => tokenize(" "))[. != ""][. != $thisId]
return
    if(count($id) != 1) then
        (update insert comment {"unable to parse target: "  || serialize($link)} following $link,
        update delete $link)
        else
Mathias Goebel's avatar
Mathias Goebel committed
438
let $targetNode := $ixp:dataCollection/id($id)
Mathias Goebel's avatar
Mathias Goebel committed
439
440
441
442
443
444
445
446
447
448
449
return
    if(count($targetNode) gt 1)
    then (update insert comment {"xml:id used multiple times. this occurence is removed. please check and reinsert item when xml:id is unique. "  || serialize($id[2])} following $id[2],
        update delete $id[2]
        )
    else if(count($targetNode) = 0)
    then
        (update insert comment {"ID " || $id || " not found: Please create an appropriate item. "  || serialize($link)} following $link,
        update delete $link
        )
    else
Mathias Goebel's avatar
Mathias Goebel committed
450
let $list := ixp:get-list-by-entity($targetNode)
451
452
453
454
return
    element xhtml:li {
        attribute class { "former-or-current-location" },
        element xhtml:a {
455
        attribute href { "register.html?e=" || $id },
456
457
        <xhtml:i class="fa fa-map-marker" aria-hidden="true"></xhtml:i>,
        "&#160;",
458
459
460
461
462
463
464
465
        $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 ()))
466
467
468
469
        }
    }
};

470
471
(:~
 : a list item with a list of links
Mathias Goebel's avatar
Mathias Goebel committed
472
 :)
Mathias Goebel's avatar
Mathias Goebel committed
473
declare function ixp:links($links as element(tei:link)*)
Mathias Goebel's avatar
Mathias Goebel committed
474
as element(xhtml:li) {
475
476
let $notebookUris :=

Mathias Goebel's avatar
Mathias Goebel committed
477
$links ! (substring-after(./@target, $ixp:targetStart) => substring(1,5) => distinct-values())
Mathias Goebel's avatar
Mathias Goebel committed
478
479
480
481
482
483
484
485
486
487
488
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 {
Mathias Goebel's avatar
Mathias Goebel committed
489
            ixp:link($linkMap)
Mathias Goebel's avatar
Mathias Goebel committed
490
        }
491
492
493
494
495
496
    }
};

(:~
 : create list items containing links
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
497
declare function ixp:link($map as map()*)
Mathias Goebel's avatar
Mathias Goebel committed
498
as element(xhtml:li)* {
499
    for $tguri in map:keys($map)
Mathias Goebel's avatar
Mathias Goebel committed
500
    let $resolve := ixp:resolve-name($tguri)
Mathias Goebel's avatar
   
Mathias Goebel committed
501
    order by $resolve
502
503
    return
        element xhtml:li {
Mathias Goebel's avatar
   
Mathias Goebel committed
504
            replace($resolve, "([A-E])0(\d)", "$1$2") || ": ",
505
506
            element xhtml:ul {
                attribute class {"link-list-horizontal"},
507
                let $this-map := $map($tguri)
508
                let $surface-sequence := $this-map ! (./@target => substring-after("surface[@n='") => substring-before("']/"))
509
                for $link at $pos in $this-map
510
                let $page := $link/@target => substring-after("surface[@n='") => substring-before("']/")
511
512
513
                let $index-of := index-of($surface-sequence, $page)
                let $count := count( $index-of )
                where $pos = $index-of[1]
514
515
516
517
518
519
                return
                    element xhtml:li {
                        element xhtml:a {
                            attribute href {
                                "edition.html?id=%2Fxml%2Fdata%2F" || $tguri
                                || ".xml&amp;page=" || $page
520
                                || "&amp;target=" || string($link/parent::tei:*/parent::tei:*/@xml:id)
521
                            },
522
523
524
                            f-misc:n-translate($page),
                            if($count eq 1) then ()
                            else (" ", <xhtml:span title="Anzahl an Vorkommnissen auf dieser Seite">({$count})</xhtml:span>)
525
526
527
528
529
530
                        }
                    }
            }
        }
};

531
532
533
534
(:~ renewed version of the linking function
 : generates a XHTML list with all links without using the tei:link[@corresp]
 : from the entity. it queries the database for what is really mentioned.
 :)
Mathias Goebel's avatar
Mathias Goebel committed
535
declare function ixp:links-new($entity as element()) {
536
    let $id := string($entity/@xml:id)
Mathias Goebel's avatar
Mathias Goebel committed
537
    let $mentions := $ixp:dataCollection//tei:rs[contains(@ref, ":" || $id)][not(@prev)]
538
539
540
541
542
543
    let $base-uris := ($mentions ! base-uri()) => distinct-values()
return
    element xhtml:li {
        attribute class { "links" },
        if(count($base-uris) = 1) then 'In Notizbuch' else 'In den Notizbüchern',
        element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
544
        (: main list :)
545
546
            for $uri in $base-uris
            let $tguri := ($uri => tokenize("/"))[last()]
Mathias Goebel's avatar
Mathias Goebel committed
547
            let $resolve := ixp:resolve-name(substring-before($tguri, ".xml"))
548
549
550
551
552
553
554
555
556
557
558
            let $name := $resolve => replace("([A-E])0(\d)", "$1$2")
            order by $resolve
            return
                element xhtml:li {
                $name || ": ",
        element xhtml:ul {
            attribute class {"link-list-horizontal"},
            for $mention in $mentions
            let $surface := $mention/ancestor::tei:surface[last()]
            let $page := string($surface/@n)
            let $count := $surface//tei:rs[contains(@ref, ":" || $id)][not(@prev)] => count()
Mathias Goebel's avatar
Mathias Goebel committed
559
            where $mention/base-uri() = $uri
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
            return
                element xhtml:li {
                    element xhtml:a {
                        attribute href {
                            "edition.html?id=%2Fxml%2Fdata%2F" || $tguri
                            || "&amp;page=" || $page
                            || "&amp;target=" || $id
                        },
                        f-misc:n-translate($page),
                        if($count eq 1) then ()
                        else (" ", <xhtml:span title="Anzahl an Vorkommnissen auf dieser Seite">({$count})</xhtml:span>)
                    }
                }
        }
        }
    }
}
};

Mathias Goebel's avatar
Mathias Goebel committed
579
580
(:~
 : prepares a link to the current entry
Mathias Goebel's avatar
Mathias Goebel committed
581
 : @param $id – the xml:id of the currently processed element
Mathias Goebel's avatar
Mathias Goebel committed
582
:)
Mathias Goebel's avatar
Mathias Goebel committed
583
declare function ixp:entry-link($id as attribute(xml:id))
Mathias Goebel's avatar
Mathias Goebel committed
584
585
586
587
588
as element(xhtml:span) {
    element xhtml:span {
        attribute class {"registerLink"},
        element xhtml:a {
            attribute href {
589
                "register.html?e=" || $id
Mathias Goebel's avatar
Mathias Goebel committed
590
591
592
593
594
595
                },
            <xhtml:i title="Link zu diesem Eintrag" class="fa fa-link"></xhtml:i>
        }
    }
};

Mathias Goebel's avatar
Mathias Goebel committed
596
597
598
599
(:~
 : creates a xhtml list item containing serialized code.
 : @param $node – a single element
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
600
declare function ixp:li-code($node as element(*))
Mathias Goebel's avatar
Mathias Goebel committed
601
as element(xhtml:li) {
602
603
604
605
element xhtml:li {
    attribute class {"register-code"},
    element xhtml:span {
        attribute class {"registerCode"},
Mathias Goebel's avatar
Mathias Goebel committed
606
607
            <xhtml:i title="Zeige XML" class="fa fa-code"></xhtml:i>
    },
Mathias Goebel's avatar
minor    
Mathias Goebel committed
608
    if(config:get("sade.develop") = "true")
Mathias Goebel's avatar
Mathias Goebel committed
609
610
611
612
613
    then
        code:main($node) => functx:change-element-ns-deep("", "")
    else
        code:main($node, false(), "hljs-", true())
            => functx:change-element-ns-deep("", "")
Mathias Goebel's avatar
Mathias Goebel committed
614
}
Mathias Goebel's avatar
Mathias Goebel committed
615
616
};

617
618
619
620
(:~
 : generic function for entries with tei:note/tei:ptr.
 : @return link to the corresponding index entry
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
621
declare function ixp:pointer($entry as element())
Mathias Goebel's avatar
Mathias Goebel committed
622
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
623
624
    let $labelMain := $entry/*[1]
    let $target := substring-after(($entry/tei:note/tei:ptr/@target), '#')
Mathias Goebel's avatar
Mathias Goebel committed
625
    let $targetNode := $ixp:dataCollection/id($target)
626
    return
Mathias Goebel's avatar
Mathias Goebel committed
627
        if(not($targetNode)) then <div>target not found</div> else
628
629
630
        element xhtml:li {
            attribute class {
                "registerEintrag",
Mathias Goebel's avatar
Mathias Goebel committed
631
                if( $entry >> $targetNode )
632
633
634
635
636
                then "up"
                else "down"
            },
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
637
                    $labelMain/text()
638
639
640
641
642
643
644
            },
            element xhtml:ul {
                element xhtml:li {
                attribute class { "pointer" },
                "siehe: ",
                    element xhtml:a {
                        attribute href { "?e=" || $target },
645
646
647
                        try {
                             string($targetNode/*[1])
                         } catch * {
Mathias Goebel's avatar
Mathias Goebel committed
648
                             (: TODO remove try catch when the data is better :)
649
650
                             "multiple entities found: " || string-join(($targetNode ! serialize(.)), " AND ")
                         }
651
652
653
654
655
                    }
                }
            }
        }
};
656

Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
657
658
659
(:
 : parses a tei:bibl and mainly prepares a list item with a link to the entity
 :)
Mathias Goebel's avatar
Mathias Goebel committed
660
declare function ixp:bibl($bibls as element(tei:bibl)*)
661
662
663
as element(xhtml:li)* {
for $bibl in $bibls
    let $biblId := $bibl/tei:ptr/@target => substring-after(":")
Mathias Goebel's avatar
Mathias Goebel committed
664
    let $targetNode := $ixp:dataCollection/id($biblId)[. instance of element(tei:bibl)]
665
666
667
668
669
670
671
    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
672
            $targetNode/tei:choice/tei:abbr/string() ||
673
674
675
676
677
678
679
            (if($bibl/tei:citedRange)
            then ":&#160;" || $bibl/tei:citedRange
            else ())
            }
        }
};

Mathias Goebel's avatar
Mathias Goebel committed
680
declare function ixp:get-gnd-data($url as xs:string)
681
682
683
684
685
686
687
688
as element(rdf:RDF){
httpclient:get(xs:anyURI($url || "/about/rdf"), false(), ())//rdf:RDF
};

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

Mathias Goebel's avatar
Mathias Goebel committed
689
690
(:~
 : parser for listEvents/event entities
691
 : @param $eventDoc – the tei:listEvent containing all entries
Mathias Goebel's avatar
Mathias Goebel committed
692
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
693
declare function ixp:events($eventDoc as element(tei:listEvent))
694
as element(xhtml:div) {
Mathias Goebel's avatar
   
Mathias Goebel committed
695
<xhtml:div id="{ string-join(($eventDoc/local-name(), $eventDoc/@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 $eventList in $eventDoc/tei:listEvent
    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">{$eventList/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="listEvent">
705
{
Mathias Goebel's avatar
Mathias Goebel committed
706
if($ixp:getNotebook = $ixp:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
707
708
709
710
711
712
713
then
  for $event in $eventList/tei:event
  let $sort := string($event/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
Mathias Goebel's avatar
Mathias Goebel committed
714
  return ixp:prepare-event($event)
Mathias Goebel's avatar
Mathias Goebel committed
715
716
else
  for $event in $eventList/tei:event[tei:linkGrp/tei:link
Mathias Goebel's avatar
Mathias Goebel committed
717
  [starts-with(@target, $ixp:getNotebook)]]
Mathias Goebel's avatar
Mathias Goebel committed
718
719
720
721
722
  let $sort := string($event/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
Mathias Goebel's avatar
Mathias Goebel committed
723
  return ixp:prepare-event($event)
724
}
Mathias Goebel's avatar
Mathias Goebel committed
725
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
726
727
            </xhtml:div>
        </xhtml:div>
728
    }
Mathias Goebel's avatar
Mathias Goebel committed
729
730
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
731
732
};

Mathias Goebel's avatar
Mathias Goebel committed
733
declare function ixp:prepare-event($event as element(tei:event))
734
as element(xhtml:li) {
735
736
737
738
(: check if the item points to another entity :)
if( not(exists($event/@xml:id)) )
then
    (: pointer :)
Mathias Goebel's avatar
Mathias Goebel committed
739
    ixp:pointer($event)
740
741
else
    let $id := $event/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
742
    let $wheres := tokenize($event/@where, " ") ! substring-after(., ":")
743
744
745
746
747
748
    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
749
return
750
751
    element xhtml:li {
        attribute id { string($id) },
Mathias Goebel's avatar
Mathias Goebel committed
752
        ixp:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
753
        (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
754
        ixp:entry-link($id),
755
756
        element xhtml:span {
                attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
757
                $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
758
            },
759
        element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
760
            (: variant :)
Mathias Goebel's avatar
Mathias Goebel committed
761
            ixp:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
762
            (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
763
            ixp:idno($labelAlt),
Mathias Goebel's avatar
Mathias Goebel committed
764
            (: note :)
Mathias Goebel's avatar
Mathias Goebel committed
765
            ixp:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
766
            (: where :)
Mathias Goebel's avatar
Mathias Goebel committed
767
            for $where in $wheres return
768
769
770
            element xhtml:li {
                attribute class { "where" },
                element xhtml:a {
771
                attribute href { "register.html?e="|| $where },
Mathias Goebel's avatar
Mathias Goebel committed
772
773
                <xhtml:i class="fa fa-map-marker" aria-hidden="true"></xhtml:i>,
                "&#160;",
Mathias Goebel's avatar
Mathias Goebel committed
774
                $ixp:dataCollection/id($where)/*[1]/string()
Mathias Goebel's avatar
Mathias Goebel committed
775
776
777
                }
            },
            (: bibl :)
Mathias Goebel's avatar
Mathias Goebel committed
778
            ixp:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
779
            (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
780
781
            ixp:links-new($event),
            ixp:li-code($event)
Mathias Goebel's avatar
Mathias Goebel committed
782
783
        }
    }
Mathias Goebel's avatar
Mathias Goebel committed
784
785
};

Mathias Goebel's avatar
Mathias Goebel committed
786
(:~
Mathias Goebel's avatar
Mathias Goebel committed
787
 : parser for tei:listOrg, returns the index of orgnaisations.
Mathias Goebel's avatar
Mathias Goebel committed
788
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
789
declare function ixp:orgs($orgDoc as element(tei:listOrg)+) {
Mathias Goebel's avatar
   
Mathias Goebel committed
790
791
let $result :=
<xhtml:div id="{ string-join(($orgDoc/local-name(), $orgDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
792
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
793
794
    {for $orgList in $orgDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
795
796
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
797
                <h4 class="panel-title">{ $orgList/tei:head/text() }</h4>
Mathias Goebel's avatar
Mathias Goebel committed
798
799
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
800
                <ul class="listOrg">
801
{
Mathias Goebel's avatar
Mathias Goebel committed
802
if($ixp:getNotebook = $ixp:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
803
804
805
806
807
808
809
then
  for $org in $orgList/tei:org
  let $sort := string($org/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
Mathias Goebel's avatar
Mathias Goebel committed
810
  return ixp:prepare-org($org)
Mathias Goebel's avatar
   
Mathias Goebel committed
811
else
Mathias Goebel's avatar
Mathias Goebel committed
812
  for $org in $orgList/tei:org[tei:linkGrp/tei:link[starts-with(@target, $ixp:getNotebook)]]
Mathias Goebel's avatar
Mathias Goebel committed
813
814
815
816
817
  let $sort := string($org/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
Mathias Goebel's avatar
Mathias Goebel committed
818
  return ixp:prepare-org($org)
819
}
Mathias Goebel's avatar
Mathias Goebel committed
820
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
821
822
            </xhtml:div>
        </xhtml:div>
823
    }
Mathias Goebel's avatar
Mathias Goebel committed
824
825
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
   
Mathias Goebel committed
826
827
return
    $result
Mathias Goebel's avatar
Mathias Goebel committed
828
829
};

Mathias Goebel's avatar
Mathias Goebel committed
830
831
832
833
(:~
 : transforms a single tei:org element to a xhtml:li
 : @since 1.0
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
834
declare function ixp:prepare-org($org as element(tei:org))
Mathias Goebel's avatar
Mathias Goebel committed
835
as element(xhtml:li) {
836
837
838
839
(: check if the item points to another entity :)
if( not(exists($org/@xml:id)) )
then
    (: pointer :)
Mathias Goebel's avatar
Mathias Goebel committed
840
    ixp:pointer($org)
841
else
Mathias Goebel's avatar
Mathias Goebel committed
842
    let $id := $org/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
843
    let $labelMain := ($org/tei:orgName)[1]
Mathias Goebel's avatar
Mathias Goebel committed
844
    let $idnos := $org/tei:idno
Mathias Goebel's avatar
Mathias Goebel committed
845
    let $variant := $org/tei:orgName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
846
847
848
849
    let $note := $org/tei:note
    let $bibl := $org/tei:bibl
    let $links := $org/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
return
850
851
    element xhtml:li {
        attribute id { string($id) },
Mathias Goebel's avatar
Mathias Goebel committed
852
        ixp:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
853
        (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
854
        ixp:entry-link($id),
855
856
        element xhtml:span {
                attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
857
                $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
858
            },
859
        element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
860
            (: variant :)
Mathias Goebel's avatar
Mathias Goebel committed
861
            ixp:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
862
            (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
863
            ixp:idno($idnos),
Mathias Goebel's avatar
Mathias Goebel committed
864
            (: note :)
Mathias Goebel's avatar
Mathias Goebel committed
865
            ixp:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
866
            (: bibl :)
Mathias Goebel's avatar
Mathias Goebel committed
867
            ixp:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
868
            (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
869
870
            ixp:links-new($org),
            ixp:li-code($org)
Mathias Goebel's avatar
Mathias Goebel committed
871
872
        }
    }
Mathias Goebel's avatar
Mathias Goebel committed
873
874
};

Mathias Goebel's avatar
Mathias Goebel committed
875
(:~
Mathias Goebel's avatar
Mathias Goebel committed
876
 : parser for tei:listPerson, returns the index of persons
Mathias Goebel's avatar
Mathias Goebel committed
877
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
878
declare function ixp:persons($persDoc as element(tei:listPerson))
Mathias Goebel's avatar
Mathias Goebel committed
879
as element(xhtml:div) {
Mathias Goebel's avatar
Mathias Goebel committed
880
(: main tab :)
Mathias Goebel's avatar
   
Mathias Goebel committed
881
<xhtml:div id="{ string-join(($persDoc/local-name(), $persDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
882
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
883
884
    {for $persList in $persDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
885
886
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
887
888
                <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
889
890
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
891
                <ul class="listPerson">
892
{
Mathias Goebel's avatar
Mathias Goebel committed
893
if($ixp:getNotebook = $ixp:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
894
895
896
897
898
899
900
then
  for $pers in $persList/tei:*
  let $sort := string($pers/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
Mathias Goebel's avatar
Mathias Goebel committed
901
  return ixp:prepare-person($pers)
Mathias Goebel's avatar
Mathias Goebel committed
902
else
Mathias Goebel's avatar
Mathias Goebel committed
903
  for $pers in $persList/tei:*[tei:linkGrp/tei:link[starts-with(@target, $ixp:getNotebook)]]
Mathias Goebel's avatar
Mathias Goebel committed
904
905
906
907
908
  let $sort := string($pers/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
Mathias Goebel's avatar
Mathias Goebel committed
909
  return ixp:prepare-person($pers)
910
}
Mathias Goebel's avatar
Mathias Goebel committed
911
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
912
913
            </xhtml:div>
        </xhtml:div>
914
    }
Mathias Goebel's avatar
Mathias Goebel committed
915
916
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
917
918
};

Mathias Goebel's avatar
Mathias Goebel committed
919
declare function ixp:prepare-person($pers as element(*)+)
Mathias Goebel's avatar
Mathias Goebel committed
920
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
921
922
923
924
(: check if the item points to another entity :)
if( not(exists($pers/@xml:id)) )
then
    (: pointer :)
Mathias Goebel's avatar
Mathias Goebel committed
925
    ixp:pointer($pers)
Mathias Goebel's avatar
Mathias Goebel committed
926
927
928
else
    (: entity :)
    let $id := $pers/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
929
930
    let $labelMain := $pers/tei:persName[1]
    let $labelAlt := $pers/tei:persName[not(@type="variant")][position() gt 1]
Mathias Goebel's avatar
Mathias Goebel committed
931
    let $variant := $pers/tei:persName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
932
933
934
935
936
937
938
    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
939
940
    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
941
942
    let $links := $pers/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
    return
943
944
        element xhtml:li {
            attribute id { string($id) },
Mathias Goebel's avatar
Mathias Goebel committed
945
            ixp:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
946
            (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
947
            ixp:entry-link($id),
948
949
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
950
                    $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
951
                },
952
            element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
953
                (: variant :)
Mathias Goebel's avatar
Mathias Goebel committed
954
                ixp:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
955
                (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
956
                for $l in $labelAlt
Mathias Goebel's avatar
Mathias Goebel committed
957
                return
958
959
                    element xhtml:li {
                    attribute class {"label-" || string($l/@type)},
Mathias Goebel's avatar
Mathias Goebel committed
960
961
962
963
964
                    $l/text(),
                    if($l/@type = "variant")
                    then ()
                    else (
                        "&#160;",
965
966
                        element xhtml:a {
                            attribute href { string($l/@xml:base) || string($l) },
Mathias Goebel's avatar
Mathias Goebel committed
967
968
969
970
971
                            <xhtml:i title="Link zu externer Ressource" class="fa fa-external-link"></xhtml:i>
                        }
                    )
                },
                (: idno :)
Mathias Goebel's avatar
Mathias Goebel committed
972
                ixp:idno($idnos),
Mathias Goebel's avatar
Mathias Goebel committed
973
974
                (: birth, death :)
                if( not($birth or $death) ) then () else
975
                    element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
976
977
978
979
980
981
982
                        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
983
984
                    element xhtml:li {
                        attribute class { "occupation" },
Mathias Goebel's avatar
Mathias Goebel committed
985
986
987
988
                        $o/text()
                    },
                for $s in $state
                return
989
990
                    element xhtml:li {
                        attribute class { "state" },
Mathias Goebel's avatar
Mathias Goebel committed
991
992
                        $s/text()
                    },
993
994
995
996
997
998
999
1000
                (: 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("#")
For faster browsing, not all history is shown. View entire blame