index-processor.xqm 52.8 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
: @author Mathias Göbel
mrodzis's avatar
mrodzis committed
8
: @version 1.1.2
Mathias Goebel's avatar
Mathias Goebel committed
9
10
: @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
declare namespace foaf="http://xmlns.com/foaf/0.1/";
18
declare namespace gndo="http://d-nb.info/standards/elementset/gnd#";
Mathias Goebel's avatar
Mathias Goebel committed
19
20
declare namespace ore="http://www.openarchives.org/ore/terms/";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
Mathias Goebel's avatar
Mathias Goebel committed
21
declare namespace tei="http://www.tei-c.org/ns/1.0";
Mathias Goebel's avatar
Mathias Goebel committed
22
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
Mathias Goebel's avatar
Mathias Goebel committed
23
declare namespace xhtml="http://www.w3.org/1999/xhtml";
Mathias Goebel's avatar
Mathias Goebel committed
24

Mathias Goebel's avatar
Mathias Goebel committed
25
26
declare variable $ixp:metaCollection := '/db/sade-projects/textgrid/data/xml/meta/';
declare variable $ixp:targetStart := "http://textgridrep.org/textgrid:";
Mathias Goebel's avatar
Mathias Goebel committed
27
(: try/catch here, to pass the tests where no request object is available :)
Mathias Goebel's avatar
Mathias Goebel committed
28
29
30
31
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
32

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

Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
36
37
38
(:~
 : Helper function to collect all main nodes from the index files.
:)
Mathias Goebel's avatar
Mathias Goebel committed
39
declare function ixp:getNodes()
Mathias Goebel's avatar
   
Mathias Goebel committed
40
as array(*) {
Mathias Goebel's avatar
Mathias Goebel committed
41
42
43
44
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
45
let $docs := $uris ! doc($ixp:dataPath || . || '.xml')
Mathias Goebel's avatar
Mathias Goebel committed
46

Mathias Goebel's avatar
   
Mathias Goebel committed
47
return
Mathias Goebel's avatar
Mathias Goebel committed
48
    [
Mathias Goebel's avatar
Mathias Goebel committed
49
    $docs//tei:body/tei:listEvent,
Mathias Goebel's avatar
Mathias Goebel committed
50
    $docs//tei:body/tei:listOrg,
Mathias Goebel's avatar
Mathias Goebel committed
51
52
53
54
    $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
55
    $docs//tei:body//tei:list[@type="Fontane"]
Mathias Goebel's avatar
Mathias Goebel committed
56
    ]
Mathias Goebel's avatar
Mathias Goebel committed
57
58
59
};

(:~
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
60
61
 : the list type an entity is listed in.
 : This is used when preparing the html resource name.
Mathias Goebel's avatar
Mathias Goebel committed
62
 : @param $entity On of tei:item, tei:place, tei:person, tei:gersonGrp,
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
63
64
65
66
 : 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
67
declare function ixp:get-list-by-entity($entity as node()?)
Mathias Goebel's avatar
Mathias Goebel committed
68
69
70
71
as xs:string {
switch ( $entity/local-name() )
    case "event" return "listEvent"
    case "org" return "listOrg"
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
72
    case "person" return
Mathias Goebel's avatar
Mathias Goebel committed
73
        if($entity/ancestor::tei:item)
Mathias Goebel's avatar
Mathias Goebel committed
74
        then ixp:get-list-by-entity( $entity/ancestor::tei:item[last()] )
Mathias Goebel's avatar
Mathias Goebel committed
75
        else "listPerson"
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
76
    case "personGrp" return
Mathias Goebel's avatar
Mathias Goebel committed
77
        if($entity/ancestor::tei:item)
Mathias Goebel's avatar
Mathias Goebel committed
78
        then ixp:get-list-by-entity( $entity/ancestor::tei:item[last()] )
Mathias Goebel's avatar
Mathias Goebel committed
79
80
81
82
83
84
85
86
        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
87
88
89
90
91
(:~
 : Returns the prefix used in the TEI documents to refere to a index file.
 : @param $entity an element from the index (e.g. tei:person)
 :)
declare function ixp:get-prefix-by-entity($entity as element(*))
Mathias Goebel's avatar
Mathias Goebel committed
92
as xs:string {
Mathias Goebel's avatar
Mathias Goebel committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  switch($entity/base-uri())
  case "/db/sade-projects/textgrid/data/xml/data/253t0.xml"
    return "eve"
  case "/db/sade-projects/textgrid/data/xml/data/253t2.xml"
    return "plc"
  case "/db/sade-projects/textgrid/data/xml/data/253t1.xml"
    return "org"
  case "/db/sade-projects/textgrid/data/xml/data/253sx.xml"
    return "psn"
  case "/db/sade-projects/textgrid/data/xml/data/253t3.xml"
    return "wrk"
  default
    return error(QName("FONTANE", "INDEX2"), "entity resource is not considered to belong to the index: " || $entity/base-uri())
};

declare function ixp:get-icon-by-entity($entity as element(*))
Mathias Goebel's avatar
Mathias Goebel committed
109
110
111
112
113
114
115
116
117
118
119
120
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
121
122
123
(:~
 : Helper function to use an efficient map data type to store the model.
 :)
Mathias Goebel's avatar
Mathias Goebel committed
124
declare function ixp:main-map($index as xs:string+)
Mathias Goebel's avatar
Mathias Goebel committed
125
as map() {
Mathias Goebel's avatar
Mathias Goebel committed
126
let $nodes := ixp:getNodes()
Mathias Goebel's avatar
Mathias Goebel committed
127
return
Mathias Goebel's avatar
Mathias Goebel committed
128
map:merge(
Mathias Goebel's avatar
Mathias Goebel committed
129
130
    for $n in 1 to array:size($nodes)
    let $node := $nodes?($n)
Mathias Goebel's avatar
Mathias Goebel committed
131
132
    let $localId := string-join(($node/local-name(), $node/@type), "-")
    let $content :=
Mathias Goebel's avatar
Mathias Goebel committed
133
        for $node in $node return
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
134
        switch ($node/local-name())
Mathias Goebel's avatar
   
Mathias Goebel committed
135
            case "listEvent" return
Mathias Goebel's avatar
Mathias Goebel committed
136
                if($index = "listEvent") then ixp:events($node) else ()
Mathias Goebel's avatar
   
Mathias Goebel committed
137
            case "listOrg" return
Mathias Goebel's avatar
Mathias Goebel committed
138
                if($index = "listOrg") then ixp:orgs($node) else ()
Mathias Goebel's avatar
   
Mathias Goebel committed
139
            case "listPerson" return
Mathias Goebel's avatar
Mathias Goebel committed
140
                if($index = "listPerson") then ixp:persons($node) else ()
Mathias Goebel's avatar
   
Mathias Goebel committed
141
            case "listPlace" return
Mathias Goebel's avatar
Mathias Goebel committed
142
                if($index = "listPlace") then ixp:places($node) else ()
Mathias Goebel's avatar
   
Mathias Goebel committed
143
            case "list" return
Mathias Goebel's avatar
Mathias Goebel committed
144
                ixp:works($node)
Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
145
            default return error(QName("FONTANE", "INDEX1"), "unknown node-name: " || $node/local-name())
Mathias Goebel's avatar
Mathias Goebel committed
146
147
148
    return
        map:entry(
            $localId,
Mathias Goebel's avatar
Mathias Goebel committed
149
            map:merge(
Mathias Goebel's avatar
Mathias Goebel committed
150
                map:entry("content", $content)
Mathias Goebel's avatar
Mathias Goebel committed
151
            )
Mathias Goebel's avatar
Mathias Goebel committed
152
        )
Mathias Goebel's avatar
Mathias Goebel committed
153
)
Mathias Goebel's avatar
Mathias Goebel committed
154
155
};

Mathias Goebel's avatar
Mathias Goebel committed
156
declare function ixp:main-map()
Mathias Goebel's avatar
   
Mathias Goebel committed
157
as map() {
Mathias Goebel's avatar
Mathias Goebel committed
158
    ixp:main-map(("listEvent", "listOrg", "listPerson", "listPlace", "list-"))
Mathias Goebel's avatar
   
Mathias Goebel committed
159
160
};

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

Mathias Goebel's avatar
   
Mathias Goebel committed
172
173
174
175
(:~
 : Main function to create a complete index, contains some template specific
 : code.
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
176
declare function ixp:register($index as xs:string?)
Mathias Goebel's avatar
   
Mathias Goebel committed
177
as element(xhtml:div)+ {
Mathias Goebel's avatar
Mathias Goebel committed
178
let $map := ixp:main-map($index)
Mathias Goebel's avatar
   
Mathias Goebel committed
179
180
181
return
    $map?*?("content")
};
182

Mathias Goebel's avatar
Mathias Goebel committed
183
184
(:~
 : helper function to get the tgmd:title by URI
Mathias Goebel's avatar
Mathias Goebel committed
185
186
 : @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
187
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
188
declare function ixp:resolve-name($uri as xs:string)
Mathias Goebel's avatar
Mathias Goebel committed
189
as xs:string {
Mathias Goebel's avatar
Mathias Goebel committed
190
    let $title := string(doc($ixp:metaCollection || $uri || '.xml')//tgmd:title)
Mathias Goebel's avatar
Mathias Goebel committed
191
    return
Mathias Goebel's avatar
   
Mathias Goebel committed
192
193
194
        if($title = "")
        then $uri
        else $title
Mathias Goebel's avatar
Mathias Goebel committed
195
196
197
};

(:~
Mathias Goebel's avatar
Mathias Goebel committed
198
 : tests for a given ID to appear in all @xml:id in a given node
Mathias Goebel's avatar
Mathias Goebel committed
199
200
 : @param $id The id to search for
 : @param $node The document or xml fragment
Mathias Goebel's avatar
Mathias Goebel committed
201
 : :)
Mathias Goebel's avatar
Mathias Goebel committed
202
declare function ixp:check-active($id as xs:string, $node as element(*)+)
203
as xs:boolean {
204
    exists($node/id($id))
Mathias Goebel's avatar
Mathias Goebel committed
205
206
};

Mathias Goebel's avatar
Mathias Goebel committed
207
208
(:~
 : checks if a target entity is in the current node set
Mathias Goebel's avatar
Mathias Goebel committed
209
 : @param $node Any node set
Mathias Goebel's avatar
Mathias Goebel committed
210
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
211
declare function ixp:check-entity($node as node()+)
Mathias Goebel's avatar
Mathias Goebel committed
212
as xs:string? {
Mathias Goebel's avatar
Mathias Goebel committed
213
    if(ixp:check-active($ixp:getEntity, $node))
Mathias Goebel's avatar
Mathias Goebel committed
214
215
216
217
    then "active"
    else ()
};

218
219
(:~
 : creates a generic xhtml:class attribute mandatory for every entry
Mathias Goebel's avatar
Mathias Goebel committed
220
 : @param $id ID to check for
221
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
222
declare function ixp:entry-class($id as attribute(xml:id))
Mathias Goebel's avatar
Mathias Goebel committed
223
as attribute(class)? {
224
225
    attribute class {
        "registerEintrag",
Mathias Goebel's avatar
Mathias Goebel committed
226
        $id/parent::*/local-name()
227
228
229
230
    }
};

(:~
Mathias Goebel's avatar
Mathias Goebel committed
231
 : creates a list for label or name
Mathias Goebel's avatar
Mathias Goebel committed
232
 : @param $variant A tei element containing any secondary label or name variant
Mathias Goebel's avatar
Mathias Goebel committed
233
 :)
Mathias Goebel's avatar
Mathias Goebel committed
234
declare function ixp:variant($variant as element()*)
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
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 ",")
                }
        }
    }
};

(:~
251
 : transforms tei:idno to xhtml:li
Mathias Goebel's avatar
Mathias Goebel committed
252
253
 : @param $idnos TEI element (idno and label) with reference to authority file
 : @TODO Declare element(tei:idno), currently wrong encoding with tei:label
254
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
255
declare function ixp:idno($idnos as element()*)
Mathias Goebel's avatar
Mathias Goebel committed
256
as element(xhtml:li)* {
257
258
for $idno in $idnos
let $str := string($idno)
Mathias Goebel's avatar
Mathias Goebel committed
259
let $wikipedia :=
Mathias Goebel's avatar
Mathias Goebel committed
260
261
  if($idno/@type = "GND") then ixp:gnd-wikipedia($str) else
  if($idno/@type = "Wikidata") then ixp:wikidata-wikipedia($str) else ()
262
let $deutscheBiographie := collection($config:data-root)/id( "gnd"||$str )
263
264
265
266
267
268
269
270
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>
271
        },
Mathias Goebel's avatar
Mathias Goebel committed
272
        (: Deutsche Biografie :)
273
        if($idno/parent::tei:person and $deutscheBiographie)
274
275
        then
          (",&#160;",
276
            let $url := string($deutscheBiographie/@db-url)
277
278
279
280
281
            return
              element xhtml:a {
                attribute title {
                    if(ends-with($url, "adbcontent"))
                    then "ADB-Eintrag basierend auf GND"
Mathias Goebel's avatar
Mathias Goebel committed
282
283
284
                    else if (ends-with($url, "ndbcontent"))
                    then "NDB-Eintrag basierend auf GND"
                    else "Eintrag in Deutscher Biografie basierend auf GND"
285
286
287
288
                },
                attribute href {$url},
                if(ends-with($url, "adbcontent"))
                then "ADB"
Mathias Goebel's avatar
Mathias Goebel committed
289
290
291
                else if (ends-with($url, "ndbcontent"))
                then "NDB"
                else "DB"
292
            })
293
        else (),
294
        if(string($wikipedia) = "") then ()
295
296
297
298
299
300
        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>
            })
301
302
303
    }
};

Mathias Goebel's avatar
Mathias Goebel committed
304
declare function ixp:gnd-wikipedia($gndid-orig as xs:string)
305
306
307
308
309
310
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"
Mathias Goebel's avatar
Mathias Goebel committed
311
let $request := <hc:request method="get" href="{$url}" />
312
313
314
315
let $response :=
    if( doc-available( $docname ))
    then doc( $docname )
    else
Mathias Goebel's avatar
Mathias Goebel committed
316
        hc:send-request($request)[2]
Mathias Goebel's avatar
Mathias Goebel committed
317
318
let $store :=
    if(config:get("sade.develop") = "true")
Mathias Goebel's avatar
Mathias Goebel committed
319
320
321
322
    then
        if(doc-available($gndCollection || $filename))
        then $gndCollection || $filename
        else
Mathias Goebel's avatar
Mathias Goebel committed
323
324
325
326
327
            try {
                xmldb:store($gndCollection, $filename, $response)
            } catch * {
                ()
            }
Mathias Goebel's avatar
Mathias Goebel committed
328
    else ()
329
330
331
332
return
    string($response//foaf:page/@rdf:resource)
};

Mathias Goebel's avatar
Mathias Goebel committed
333
declare function ixp:wikidata-wikipedia($wikidata-id as xs:string)
Mathias Goebel's avatar
Mathias Goebel committed
334
335
336
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
Mathias Goebel's avatar
typo    
Mathias Goebel committed
337
  let $request := <hc:request method="get" href="{$url}" />
Mathias Goebel's avatar
Mathias Goebel committed
338
  let $uris := hc:send-request($request)[2]//*:uri/string()
Mathias Goebel's avatar
Mathias Goebel committed
339
340
341
342
343
344
345
346
  return (
    $uris[matches(., "de\.wikipedia")],
    $uris[matches(., "en\.wikipedia")],
    $uris[matches(., "fr\.wikipedia")],
    $uris[matches(., "it\.wikipedia")],
    $uris[1])[1]
};

347
348
349
(:~
 : transformation from tei:note to xhtml:li
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
350
declare function ixp:note($note as element(tei:note)*)
Mathias Goebel's avatar
Mathias Goebel committed
351
as element(xhtml:li)* {
352
353
354
355
for $n in $note
    return
        element xhtml:li {
            attribute class { "tei-note" },
Mathias Goebel's avatar
Mathias Goebel committed
356
357
358
359
360
            $n/text(),
            for $ptr in $n/tei:ptr[@type = "Figurenlexikon"]
            return
                element xhtml:a {
                    attribute href { string($ptr/@target) },
361
362
                    attribute class { "figurenlexikon" },
                    string($ptr/@type)
Mathias Goebel's avatar
Mathias Goebel committed
363
                }
364
365
366
        }
};

367
368
369
(:~
 : creates a list of all creations or points to the creator of a work
 : :)
Mathias Goebel's avatar
Mathias Goebel committed
370
declare function ixp:creator($creators as element(tei:link)+)
371
as element(xhtml:li) {
372
373
374
375
376
377

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
378
    "",
379
    element xhtml:ul {
380
        attribute class {"workList"},
381
382
383
        for $creator in $creators
        let $target := $creator/@target => substring-before(" ")
        let $targetId := $target => substring-after(":")
Mathias Goebel's avatar
Mathias Goebel committed
384
        let $targetNode := $ixp:dataCollection/id($targetId)
385
        let $title := string($targetNode/*[1])
386
387
388
389
390
391
        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
392
                else ixp:get-list-by-entity( $targetNode )
393
            else "target-not-available"
394
        order by $title
395
396
        return
            element xhtml:li {
397
                attribute class {"item"},
398
                element xhtml:a {
399
                    attribute href { "register.html?e=" || string-join($targetId) },
400
401
                    if($targetNode[2])
                    then "two entities with same ID: " || $targetId
402
                    else $title
403
                },
Mathias Goebel's avatar
fix    
Mathias Goebel committed
404
                text{ "&#8195;" },
405
406
407
408
409
410
411
                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"}
                    }
412
413
414
415
416
417
                }
            }
    }
}
else
    (: work item with creator :)
418
419
element xhtml:li {
    attribute class { "creator" },
Mathias Goebel's avatar
Mathias Goebel committed
420
    "",
421
    element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
422
        attribute class {"listPerson"},
423
424
        for $creator in $creators
        let $target := $creator/@target => substring-after(" ")
Mathias Goebel's avatar
Mathias Goebel committed
425
        let $targetId := $target => substring-after(":")
Mathias Goebel's avatar
Mathias Goebel committed
426
        let $targetNode := $ixp:dataCollection/id($targetId)
Mathias Goebel's avatar
   
Mathias Goebel committed
427
428
429
        let $htmlResource :=
(: TODO remove condition for final production release :)
            if($targetNode)
430
431
432
            then
                if($targetNode[2])
                then "two entities with same ID: " || $targetId
Mathias Goebel's avatar
Mathias Goebel committed
433
                else ixp:get-list-by-entity( $targetNode )
Mathias Goebel's avatar
   
Mathias Goebel committed
434
            else "target-not-available"
435
436
        return
            element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
437
                attribute class {"person"},
438
                element xhtml:a {
439
                    attribute href { "register.html?e=" || string-join($targetId) },
440
441
442
                    if($targetNode[2])
                    then "two entities with same ID: " || $targetId
                    else string($targetNode/*[1])
443
444
445
446
447
448
                }
            }
    }
}
};

Mathias Goebel's avatar
Mathias Goebel committed
449
declare function ixp:has-former-or-current-location($links as element(tei:link)*)
450
451
as element(xhtml:li)* {
for $link in $links
Mathias Goebel's avatar
Mathias Goebel committed
452
453
454
455
456
457
458
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
459
let $targetNode := $ixp:dataCollection/id($id)
Mathias Goebel's avatar
Mathias Goebel committed
460
461
462
463
464
465
466
467
468
469
470
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
471
let $list := ixp:get-list-by-entity($targetNode)
472
473
474
475
return
    element xhtml:li {
        attribute class { "former-or-current-location" },
        element xhtml:a {
476
        attribute href { "register.html?e=" || $id },
477
478
        <xhtml:i class="fa fa-map-marker" aria-hidden="true"></xhtml:i>,
        "&#160;",
479
480
481
482
483
484
485
486
        $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 ()))
487
488
489
490
        }
    }
};

491
492
493
(:~ 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.
494
 : @version 2.0
495
 :)
Mathias Goebel's avatar
Mathias Goebel committed
496
declare function ixp:links($entity as element()) {
497
498
499
let $id := string($entity/@xml:id)
let $prefix := ixp:get-prefix-by-entity($entity)
let $reference := $prefix || ":" || $id
Mathias Goebel's avatar
Mathias Goebel committed
500
501
502
503
let $hits := $ixp:dataCollection//tei:rs
                [contains(@ref, $reference)]
                [not(@prev)]
                [@ref eq $reference]
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520

let $array :=
    array{
        for $hit in $hits
        let $base := $hit/base-uri()
        let $tguri := (substring-before($base, ".xml") => tokenize("/|\."))[last()]
        let $resolve := ixp:resolve-name($tguri)
        return
            map{
                "base": $base,
                "tguri" : $tguri,
                "title" : $resolve,
                "surface": $hit/ancestor::tei:surface[parent::tei:sourceDoc]/string(@n)
            }
    }
let $titles := $array?*?title => distinct-values()
let $countNotebooks := count($titles)
521
return
522
523
element xhtml:li {
    attribute class { "links" },
524
    if($countNotebooks lt 2) then 'In Notizbuch' else ('In den Notizbüchern ',
525
526
    <span style="color:gray">({$countNotebooks} Notizbücher, insgesamt {array:size($array)} Vorkommnisse)</span>),
    element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
527
        (: main list :)
528
529
530
531
532
533
534
535
536
537
538
539
540
541
        for $title in $titles
        let $titleArray := $array?*[?title = $title]
        let $titleReadable := $title => replace("([A-E])0(\d)", "$1$2")
        let $tguri := $titleArray?tguri[1]
        order by $title
        return
        element xhtml:li {
            $titleReadable || ": ",
            element xhtml:ul {
                attribute class {"link-list-horizontal"},
                for $surface in distinct-values($titleArray?surface)
                let $count := $titleArray[?surface = $surface] => count()
                return
                    element xhtml:li {
542
543
                    element xhtml:a {
                        attribute href {
Mathias Goebel's avatar
Mathias Goebel committed
544
                            "edition.html?id=%2Fxml%2Fdata%2F" || $tguri || ".xml"
545
                            || "&amp;page=" || $surface
546
547
                            || "&amp;target=" || $id
                        },
mrodzis's avatar
mrodzis committed
548
                        f-misc:n-translate($surface),
549
550
551
552
                        if($count eq 1) then ()
                        else (" ", <xhtml:span title="Anzahl an Vorkommnissen auf dieser Seite">({$count})</xhtml:span>)
                    }
                }
553
            }
554
555
556
557
558
        }
    }
}
};

Mathias Goebel's avatar
Mathias Goebel committed
559
560
(:~
 : prepares a link to the current entry
Mathias Goebel's avatar
Mathias Goebel committed
561
 : @param $id The xml:id of the currently processed element
Mathias Goebel's avatar
Mathias Goebel committed
562
:)
Mathias Goebel's avatar
Mathias Goebel committed
563
declare function ixp:entry-link($id as attribute(xml:id))
Mathias Goebel's avatar
Mathias Goebel committed
564
565
566
567
568
as element(xhtml:span) {
    element xhtml:span {
        attribute class {"registerLink"},
        element xhtml:a {
            attribute href {
569
                "register.html?e=" || $id
Mathias Goebel's avatar
Mathias Goebel committed
570
571
572
573
574
575
                },
            <xhtml:i title="Link zu diesem Eintrag" class="fa fa-link"></xhtml:i>
        }
    }
};

Mathias Goebel's avatar
Mathias Goebel committed
576
577
(:~
 : creates a xhtml list item containing serialized code.
Mathias Goebel's avatar
Mathias Goebel committed
578
 : @param $node A single element
Mathias Goebel's avatar
Mathias Goebel committed
579
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
580
declare function ixp:li-code($node as element(*))
Mathias Goebel's avatar
Mathias Goebel committed
581
as element(xhtml:li) {
582
583
584
585
element xhtml:li {
    attribute class {"register-code"},
    element xhtml:span {
        attribute class {"registerCode"},
Mathias Goebel's avatar
Mathias Goebel committed
586
587
            <xhtml:i title="Zeige XML" class="fa fa-code"></xhtml:i>
    },
Mathias Goebel's avatar
minor    
Mathias Goebel committed
588
    if(config:get("sade.develop") = "true")
Mathias Goebel's avatar
Mathias Goebel committed
589
590
591
592
593
    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
594
}
Mathias Goebel's avatar
Mathias Goebel committed
595
596
};

597
598
(:~
 : generic function for entries with tei:note/tei:ptr.
Mathias Goebel's avatar
Mathias Goebel committed
599
 : @return Link to the corresponding index entry
600
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
601
declare function ixp:pointer($entry as element())
Mathias Goebel's avatar
Mathias Goebel committed
602
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
603
604
    let $labelMain := $entry/*[1]
    let $target := substring-after(($entry/tei:note/tei:ptr/@target), '#')
Mathias Goebel's avatar
Mathias Goebel committed
605
    let $targetNode := $ixp:dataCollection/id($target)
606
    return
Mathias Goebel's avatar
Mathias Goebel committed
607
        if(not($targetNode)) then <div>target not found</div> else
608
609
610
        element xhtml:li {
            attribute class {
                "registerEintrag",
Mathias Goebel's avatar
Mathias Goebel committed
611
                if( $entry >> $targetNode )
612
613
614
615
616
                then "up"
                else "down"
            },
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
617
                    $labelMain/text()
618
619
620
621
622
623
624
            },
            element xhtml:ul {
                element xhtml:li {
                attribute class { "pointer" },
                "siehe: ",
                    element xhtml:a {
                        attribute href { "?e=" || $target },
625
626
627
                        try {
                             string($targetNode/*[1])
                         } catch * {
Mathias Goebel's avatar
Mathias Goebel committed
628
                             (: TODO remove try catch when the data is better :)
629
630
                             "multiple entities found: " || string-join(($targetNode ! serialize(.)), " AND ")
                         }
631
632
633
634
635
                    }
                }
            }
        }
};
636

Mathias Goebel's avatar
cleanup    
Mathias Goebel committed
637
638
639
(:
 : parses a tei:bibl and mainly prepares a list item with a link to the entity
 :)
Mathias Goebel's avatar
Mathias Goebel committed
640
declare function ixp:bibl($bibls as element(tei:bibl)*)
641
642
643
as element(xhtml:li)* {
for $bibl in $bibls
    let $biblId := $bibl/tei:ptr/@target => substring-after(":")
Mathias Goebel's avatar
Mathias Goebel committed
644
    let $targetNode := $ixp:dataCollection/id($biblId)[. instance of element(tei:bibl)]
645
646
647
648
649
650
651
    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
652
            $targetNode/tei:choice/tei:abbr/string() ||
653
654
655
656
657
658
659
            (if($bibl/tei:citedRange)
            then ":&#160;" || $bibl/tei:citedRange
            else ())
            }
        }
};

Mathias Goebel's avatar
Mathias Goebel committed
660
declare function ixp:get-gnd-data($url as xs:string)
661
as element(rdf:RDF){
Mathias Goebel's avatar
Mathias Goebel committed
662
663
664
    let $request := <hc:request method="get"/>
    return
    hc:send-request($request, $url || "/about/rdf")[2]//rdf:RDF
665
666
667
668
669
670
};

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

Mathias Goebel's avatar
Mathias Goebel committed
671
672
(:~
 : parser for listEvents/event entities
Mathias Goebel's avatar
Mathias Goebel committed
673
 : @param $eventDoc The tei:listEvent containing all entries
Mathias Goebel's avatar
Mathias Goebel committed
674
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
675
declare function ixp:events($eventDoc as element(tei:listEvent))
676
as element(xhtml:div) {
Mathias Goebel's avatar
   
Mathias Goebel committed
677
<xhtml:div id="{ string-join(($eventDoc/local-name(), $eventDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
678
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
679
680
    {for $eventList in $eventDoc/tei:listEvent
    return
Mathias Goebel's avatar
Mathias Goebel committed
681
682
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
683
                <h4 class="panel-title">{$eventList/tei:head/text()}</h4>
Mathias Goebel's avatar
Mathias Goebel committed
684
685
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
686
                <ul class="listEvent">
687
{
Mathias Goebel's avatar
Mathias Goebel committed
688
if($ixp:getNotebook = $ixp:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
689
690
691
692
693
694
695
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
696
  return ixp:prepare-event($event)
Mathias Goebel's avatar
Mathias Goebel committed
697
698
else
  for $event in $eventList/tei:event[tei:linkGrp/tei:link
Mathias Goebel's avatar
Mathias Goebel committed
699
  [starts-with(@target, $ixp:getNotebook)]]
Mathias Goebel's avatar
Mathias Goebel committed
700
701
702
703
704
  let $sort := string($event/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
Mathias Goebel's avatar
Mathias Goebel committed
705
  return ixp:prepare-event($event)
706
}
Mathias Goebel's avatar
Mathias Goebel committed
707
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
708
709
            </xhtml:div>
        </xhtml:div>
710
    }
Mathias Goebel's avatar
Mathias Goebel committed
711
712
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
713
714
};

Mathias Goebel's avatar
Mathias Goebel committed
715
716
(:~
 : parser for listEvents/event entities
Mathias Goebel's avatar
Mathias Goebel committed
717
 : @param $eventDoc The tei:listEvent containing all entries
Mathias Goebel's avatar
Mathias Goebel committed
718
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
719
declare function ixp:events($eventDoc as element(tei:listEvent), $filter as xs:string*)
Mathias Goebel's avatar
Mathias Goebel committed
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
as element(xhtml:div) {
<xhtml:div id="{ string-join(($eventDoc/local-name(), $eventDoc/@type), "-") }" class="tab-pane">
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
    {for $eventList in $eventDoc/tei:listEvent
    return
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
                <h4 class="panel-title">{$eventList/tei:head/text()}</h4>
            </xhtml:div>
            <xhtml:div class="panel-body">
                <ul class="listEvent">
{
  for $event in $eventList/tei:event[@xml:id = $filter]
  let $sort := string($event/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
  return ixp:prepare-event($event)
}
                </ul>
            </xhtml:div>
        </xhtml:div>
    }
    </xhtml:div>
</xhtml:div>
};

Mathias Goebel's avatar
Mathias Goebel committed
748
declare function ixp:prepare-event($event as element(tei:event))
749
as element(xhtml:li) {
750
751
752
753
(: check if the item points to another entity :)
if( not(exists($event/@xml:id)) )
then
    (: pointer :)
Mathias Goebel's avatar
Mathias Goebel committed
754
    ixp:pointer($event)
755
756
else
    let $id := $event/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
757
    let $wheres := tokenize($event/@where, " ") ! substring-after(., ":")
758
759
760
761
762
763
    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
764
return
765
766
    element xhtml:li {
        attribute id { string($id) },
Mathias Goebel's avatar
Mathias Goebel committed
767
        ixp:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
768
        (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
769
        ixp:entry-link($id),
770
771
        element xhtml:span {
                attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
772
                $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
773
            },
774
        element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
775
            (: variant :)
Mathias Goebel's avatar
Mathias Goebel committed
776
            ixp:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
777
            (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
778
            ixp:idno($labelAlt),
Mathias Goebel's avatar
Mathias Goebel committed
779
            (: note :)
Mathias Goebel's avatar
Mathias Goebel committed
780
            ixp:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
781
            (: where :)
782
783
784
            for $where in $wheres
            return
                ixp:data-loader($ixp:dataCollection/id($where)),
Mathias Goebel's avatar
Mathias Goebel committed
785
            (: bibl :)
Mathias Goebel's avatar
Mathias Goebel committed
786
            ixp:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
787
            (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
788
            ixp:links($event),
Mathias Goebel's avatar
Mathias Goebel committed
789
            ixp:li-code($event)
Mathias Goebel's avatar
Mathias Goebel committed
790
791
        }
    }
Mathias Goebel's avatar
Mathias Goebel committed
792
793
};

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

Mathias Goebel's avatar
Mathias Goebel committed
838
(:~
Mathias Goebel's avatar
Mathias Goebel committed
839
 : parser for tei:listOrg, returns the index of organisations.
Mathias Goebel's avatar
Mathias Goebel committed
840
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
841
declare function ixp:orgs($orgDoc as element(tei:listOrg)+, $filter as xs:string*) {
Mathias Goebel's avatar
Mathias Goebel committed
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
<xhtml:div id="{ string-join(($orgDoc/local-name(), $orgDoc/@type), "-") }" class="tab-pane">
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
    {for $orgList in $orgDoc
    return
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
                <h4 class="panel-title">{ $orgList/tei:head/text() }</h4>
            </xhtml:div>
            <xhtml:div class="panel-body">
                <ul class="listOrg">
{
  for $org in $orgList/tei:org[@xml:id = $filter]
  let $sort := string($org/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
  return ixp:prepare-org($org)
}
                </ul>
            </xhtml:div>
        </xhtml:div>
    }
    </xhtml:div>
</xhtml:div>

};

Mathias Goebel's avatar
Mathias Goebel committed
870
871
872
873
(:~
 : transforms a single tei:org element to a xhtml:li
 : @since 1.0
 :  :)
Mathias Goebel's avatar
Mathias Goebel committed
874
declare function ixp:prepare-org($org as element(tei:org))
Mathias Goebel's avatar
Mathias Goebel committed
875
as element(xhtml:li) {
876
877
878
879
(: check if the item points to another entity :)
if( not(exists($org/@xml:id)) )
then
    (: pointer :)
Mathias Goebel's avatar
Mathias Goebel committed
880
    ixp:pointer($org)
881
else
Mathias Goebel's avatar
Mathias Goebel committed
882
    let $id := $org/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
883
    let $labelMain := ($org/tei:orgName)[1]
Mathias Goebel's avatar
Mathias Goebel committed
884
    let $idnos := $org/tei:idno
Mathias Goebel's avatar
Mathias Goebel committed
885
    let $variant := $org/tei:orgName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
886
887
888
889
    let $note := $org/tei:note
    let $bibl := $org/tei:bibl
    let $links := $org/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
return
890
891
    element xhtml:li {
        attribute id { string($id) },
Mathias Goebel's avatar
Mathias Goebel committed
892
        ixp:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
893
        (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
894
        ixp:entry-link($id),
895
896
        element xhtml:span {
                attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
897
                $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
898
            },
899
        element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
900
            (: variant :)
Mathias Goebel's avatar
Mathias Goebel committed
901
            ixp:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
902
            (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
903
            ixp:idno($idnos),
Mathias Goebel's avatar
Mathias Goebel committed
904
            (: note :)
Mathias Goebel's avatar
Mathias Goebel committed
905
            ixp:note($note),
Mathias Goebel's avatar
Mathias Goebel committed
906
            (: bibl :)
Mathias Goebel's avatar
Mathias Goebel committed
907
            ixp:bibl($bibl),
Mathias Goebel's avatar
Mathias Goebel committed
908
            (: links :)
Mathias Goebel's avatar
Mathias Goebel committed
909
            ixp:links($org),
Mathias Goebel's avatar
Mathias Goebel committed
910
            ixp:li-code($org)
Mathias Goebel's avatar
Mathias Goebel committed
911
912
        }
    }
Mathias Goebel's avatar
Mathias Goebel committed
913
914
};

Mathias Goebel's avatar
Mathias Goebel committed
915
(:~
Mathias Goebel's avatar
Mathias Goebel committed
916
 : parser for tei:listPerson, returns the index of persons
Mathias Goebel's avatar
Mathias Goebel committed
917
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
918
declare function ixp:persons($persDoc as element(tei:listPerson))
Mathias Goebel's avatar
Mathias Goebel committed
919
as element(xhtml:div) {
Mathias Goebel's avatar
Mathias Goebel committed
920
(: main tab :)
Mathias Goebel's avatar
   
Mathias Goebel committed
921
<xhtml:div id="{ string-join(($persDoc/local-name(), $persDoc/@type), "-") }" class="tab-pane">
Mathias Goebel's avatar
Mathias Goebel committed
922
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
923
924
    {for $persList in $persDoc
    return
Mathias Goebel's avatar
Mathias Goebel committed
925
926
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
927
928
                <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
929
930
            </xhtml:div>
            <xhtml:div class="panel-body">
Mathias Goebel's avatar
Mathias Goebel committed
931
                <ul class="listPerson">
932
{
Mathias Goebel's avatar
Mathias Goebel committed
933
if($ixp:getNotebook = $ixp:targetStart)
Mathias Goebel's avatar
Mathias Goebel committed
934
935
936
937
938
939
940
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
941
  return ixp:prepare-person($pers)
Mathias Goebel's avatar
Mathias Goebel committed
942
else
Mathias Goebel's avatar
Mathias Goebel committed
943
  for $pers in $persList/tei:*[tei:linkGrp/tei:link[starts-with(@target, $ixp:getNotebook)]]
Mathias Goebel's avatar
Mathias Goebel committed
944
945
946
947
948
  let $sort := string($pers/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
Mathias Goebel's avatar
Mathias Goebel committed
949
  return ixp:prepare-person($pers)
950
}
Mathias Goebel's avatar
Mathias Goebel committed
951
                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
952
953
            </xhtml:div>
        </xhtml:div>
954
    }
Mathias Goebel's avatar
Mathias Goebel committed
955
956
    </xhtml:div>
</xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
957
958
};

Mathias Goebel's avatar
Mathias Goebel committed
959
960
961
962

(:~
 : parser for tei:listPerson, returns the index of persons
 :   :)
Mathias Goebel's avatar
Mathias Goebel committed
963
declare function ixp:persons($persDoc as element(tei:listPerson), $filter as xs:string*)
Mathias Goebel's avatar
Mathias Goebel committed
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
as element(xhtml:div) {
(: main tab :)
<xhtml:div id="{ string-join(($persDoc/local-name(), $persDoc/@type), "-") }" class="tab-pane">
    <xhtml:div class="panel-group" aria-multiselectable="true" role="tablist">
    {for $persList in $persDoc
    return
        <xhtml:div class="panel panel-default">
            <xhtml:div class="panel-heading">
                <h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">Personen und Werke</a>
                </h4>
            </xhtml:div>
            <xhtml:div class="panel-body">
                <ul class="listPerson">
{

  for $pers in $persList/tei:*[@xml:id = $filter]
  let $sort := string($pers/*[1])
                => replace("ä", "ae")
                => replace("ö", "oe")
                => replace("ü", "ue")
  order by $sort
  return ixp:prepare-person($pers)

}
                </ul>
            </xhtml:div>
        </xhtml:div>
    }
    </xhtml:div>
</xhtml:div>
};

Mathias Goebel's avatar
Mathias Goebel committed
996
declare function ixp:prepare-person($pers as element(*)+)
Mathias Goebel's avatar
Mathias Goebel committed
997
as element(xhtml:li) {
Mathias Goebel's avatar
Mathias Goebel committed
998
999
1000
1001
(: check if the item points to another entity :)
if( not(exists($pers/@xml:id)) )
then
    (: pointer :)
Mathias Goebel's avatar
Mathias Goebel committed
1002
    ixp:pointer($pers)
Mathias Goebel's avatar
Mathias Goebel committed
1003
1004
1005
else
    (: entity :)
    let $id := $pers/@xml:id
Mathias Goebel's avatar
Mathias Goebel committed
1006
1007
    let $labelMain := $pers/tei:persName[1]
    let $labelAlt := $pers/tei:persName[not(@type="variant")][position() gt 1]
Mathias Goebel's avatar
Mathias Goebel committed
1008
    let $variant := $pers/tei:persName[@type="variant"]
Mathias Goebel's avatar
Mathias Goebel committed
1009
1010
1011
1012
1013
1014
1015
    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
1016
1017
    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
1018
1019
    let $links := $pers/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"]
    return
1020
1021
        element xhtml:li {
            attribute id { string($id) },
Mathias Goebel's avatar
Mathias Goebel committed
1022
            ixp:entry-class($id),
Mathias Goebel's avatar
Mathias Goebel committed
1023
            (: link to this entry :)
Mathias Goebel's avatar
Mathias Goebel committed
1024
            ixp:entry-link($id),
1025
1026
            element xhtml:span {
                    attribute class { "label-main" },
Mathias Goebel's avatar
Mathias Goebel committed
1027
                    $labelMain/text()
Mathias Goebel's avatar
Mathias Goebel committed
1028
                },
1029
1030
1031
1032
1033
1034
1035
1036
1037
                if(not($pers/parent::tei:listPerson/parent::tei:item)) then () else
                element xhtml:span {
                        attribute class { "hiera-ref" },
                        " in: ",
                        element xhtml:a {
                            attribute href { "?e=" || string($pers/parent::tei:listPerson/parent::tei:item/@xml:id) },
                            string($pers/parent::tei:listPerson/parent::tei:item/*[1])
                        }
                    },
1038
            element xhtml:ul {
Mathias Goebel's avatar
Mathias Goebel committed
1039
                (: variant :)
Mathias Goebel's avatar
Mathias Goebel committed
1040
                ixp:variant($variant),
Mathias Goebel's avatar
Mathias Goebel committed
1041
                (: secondary label :)
Mathias Goebel's avatar
Mathias Goebel committed
1042
                for $l in $labelAlt
Mathias Goebel's avatar
Mathias Goebel committed
1043
                return
1044
1045
                    element xhtml:li {
                    attribute class {"label-" || string($l/@type)},
Mathias Goebel's avatar
Mathias Goebel committed
1046
1047
1048
1049
1050
                    $l/text(),
                    if($l/@type = "variant")
                    then ()
                    else (
                        "&#160;",
1051
1052
                        element xhtml:a {
                            attribute href { string($l/@xml:base) || string($l) },
Mathias Goebel's avatar
Mathias Goebel committed
1053
1054
1055
1056
1057
                            <xhtml:i title="Link zu externer Ressource" class="fa fa-external-link"></xhtml:i>
                        }
                    )
                },
                (: idno :)
Mathias Goebel's avatar
Mathias Goebel committed
1058
                ixp:idno($idnos),
Mathias Goebel's avatar
Mathias Goebel committed
1059
1060
                (: birth, death :)
                if( not($birth or $death) ) then () else
1061
                    element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
1062
1063
1064
1065
1066
1067
1068
                        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
1069
1070
                    element xhtml:li {
                        attribute class { "occupation" },
Mathias Goebel's avatar
Mathias Goebel committed
1071
1072
1073
1074
                        $o/text()
                    },
                for $s in $state
                return
1075
1076
                    element xhtml:li {
                        attribute class { "state" },
Mathias Goebel's avatar
Mathias Goebel committed
1077
1078
                        $s/text()
                    },
1079
1080
1081
1082
1083
1084
1085
1086
1087
                (: 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
1088
                            ixp:data-loader($ixp:dataCollection/id($memberId))