transform.xqm 105 KB
Newer Older
Mathias Goebel's avatar
Mathias Goebel committed
1
xquery version "3.1";
Mathias Goebel's avatar
Mathias Goebel committed
2
3
4
5
6
7
8
9
10
11
module namespace fontaneTransfo="http://fontane-nb.dariah.eu/Transfo";

declare boundary-space preserve;
declare default element namespace "http://www.tei-c.org/ns/1.0";

declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare namespace digilib="digilib:digilib";
declare namespace svg="http://www.w3.org/2000/svg";
declare namespace xlink="http://www.w3.org/1999/xlink";
12
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
Mathias Goebel's avatar
Mathias Goebel committed
13
14
15
16

import module namespace console="http://exist-db.org/xquery/console";

declare variable $fontaneTransfo:tooltipReplacementPattern := '\s$|,$|\.|\($|\)$|;| ';
Mathias Goebel's avatar
Mathias Goebel committed
17
declare variable $fontaneTransfo:bracket_left.svg := <svg
Mathias Goebel's avatar
Mathias Goebel committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   version="1.1"
   id="svg3383"
   viewBox="20 20 40 250"
   style="transform: scaleX(0.5);"
   height="100%"
   width="1cm">
  <metadata
     id="metadata3390">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <defs
     id="defs3388" />
  <path
     stroke-width="1"
     d="M 30.87,261.00 C 30.87,261.00 30.00,220.00 30.00,220.00 30.00,220.00 30.00,179.00 30.00,179.00 29.99,173.57 29.22,165.11 27.53,160.00 25.78,154.70 23.34,153.50 23.18,149.91 22.98,145.60 26.14,143.08 27.78,138.00 29.18,133.65 29.99,123.73 30.00,119.00 30.00,119.00 30.00,72.00 30.00,72.00 30.00,60.01 29.29,47.86 31.28,36.00 32.35,29.70 33.52,24.34 40.00,22.00 40.00,22.00 35.93,36.00 35.93,36.00 35.93,36.00 34.00,53.00 34.00,53.00 34.00,53.00 34.00,125.00 34.00,125.00 34.00,125.00 31.45,141.00 31.45,141.00 31.45,141.00 28.13,150.00 28.13,150.00 28.13,150.00 31.09,159.00 31.09,159.00 31.09,159.00 34.00,179.00 34.00,179.00 34.00,179.00 34.00,244.00 34.00,244.00 34.00,244.00 36.16,263.00 36.16,263.00 36.16,263.00 40.00,276.00 40.00,276.00 32.45,274.30 31.81,267.69 30.87,261.00"
     id="bracket" />
Mathias Goebel's avatar
Mathias Goebel committed
47
48
49
</svg>;

declare function fontaneTransfo:magic($nodes as node()*) {
Mathias Goebel's avatar
Mathias Goebel committed
50
51
52
53
    fontaneTransfo:magic(($nodes), "undefined")
};

declare function fontaneTransfo:magic($nodes as node()*, $inital as xs:string?) {
Mathias Goebel's avatar
Mathias Goebel committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
for $node in $nodes return
typeswitch($node)
    case element(tei:TEI)
            return
                element xhtml:div {
                    attribute class {'TEI', 'clearfix' (: damn bootstrap in this code? damn it! :) },
                    fontaneTransfo:magic($node/node())
                }

    case element(tei:teiHeader) return ()

    case element(tei:sourceDoc)
        return
            element xhtml:div {
                attribute id {substring-after($node/@n, 'er_')},
                attribute class {'sourceDoc'},
                fontaneTransfo:magic($node/node())
            }

    case element(tei:surface)
Mathias Goebel's avatar
Mathias Goebel committed
74
        return fontaneTransfo:surfaceDiv($node, $inital)
Mathias Goebel's avatar
Mathias Goebel committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
    case element(tei:zone)
        return
            try {(
            element xhtml:div {
(:                if ($node/parent::tei:line) :)
(:                    then:)
(:                        fontaneTransfo:zone-inline($node):)
(:                    else:)
                fontaneTransfo:zone($node),
                if( $node/contains(@style, "border-left-style:double") and $node/contains(@rend,"border-left-style:wavy") )
                then
                    element xhtml:div {
                        attribute class {"border-left border-left-style wavy"},
                        fontaneTransfo:magic($node/node())
                    }
                else
91
                    fontaneTransfo:magic($node/node())
Mathias Goebel's avatar
Mathias Goebel committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
            }
            )}
            catch * { ("zone: ", $err:code , $err:description, $err:value)  }
    case element(tei:figure)
        return
            if( $node/parent::zone/@points ) then
                    let $coordinates := tokenize( $node/ancestor::zone[1]/@points, ' ' )
                    return
                        (<svg class="{tokenize($node//tei:figDesc/tei:ref/text(), ' ')[2]}"
                        width="{$node/ancestor::tei:TEI/tei:teiHeader//tei:dimensions[@type="leaf"]/tei:width/string(@quantity)}mm"
                        height="{$node/ancestor::tei:TEI/tei:teiHeader//tei:dimensions[@type="leaf"]/tei:height/string(@quantity)}mm"
                        style="position:absolute; top:0;">
                            {for $pair in 1 to (count($coordinates) - 1)
                            let $x1 := tokenize($coordinates[$pair], ',')[1]
                            let $y1 := tokenize($coordinates[$pair], ',')[2]
                            let $x2 := tokenize($coordinates[$pair + 1], ',')[1]
                            let $y2 := tokenize($coordinates[$pair + 1], ',')[2]
                                return
                                    <line style="stroke-width:1" x1="{$x1}cm" y1="{$y1}cm" x2="{$x2}cm" y2="{$y2}cm" />
                            }
                        </svg>,
                        element xhtml:div {
                            attribute class {'hrHover'},
                            '<'||tokenize($node//tei:figDesc/tei:ref/text(), ' ')[2]||'>'
                            }
                        )
            else
                if(contains($node//tei:figDesc/tei:ref/text(), 'Absatzlinie') and contains($node//tei:figDesc/tei:ref/text(), 'nachgezogen')) then
                    (<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="auto" viewBox="0 0 300 20">
                        <path d="M130 4 C 130 4, 110 2, 90 6" fill="transparent"/>
                        <path d="M90 6 C 90 4, 100 10, 295 3" fill="transparent"/>
                        <path d="M295 3 C 300 -2, 300 8, 5 20" fill="transparent"/>
                        <path d="M5 20 C 4 17, 8 22, 295 14" fill="transparent"/>
                    </svg>,
                element xhtml:div {
                    attribute class {'hrHover'},
                    'Absatzlinie'
                })
            else
                if(contains($node//tei:figDesc/tei:ref/text(), "einfache Absatzlinie (hin und her)"))
                then
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 451 46">
134
                        {element svg:path {
Mathias Goebel's avatar
Mathias Goebel committed
135
136
137
138
                           attribute id {"ahihe"},
                           attribute fill {"none"},
                           attribute stroke {"darkslategrey"},
                           attribute stroke-width {"1"},
139
                           attribute d {"M 440.67,14.67 " ||
Mathias Goebel's avatar
Mathias Goebel committed
140
141
                            "C 440.67,14.67 25.33,2.00 7.33,21.33 " ||
                             "11.33,28.00 422.00,11.33 414.67,20.00 " ||
142
                             "392.67,8.67 32.00,36.67 32.00,36.67" }}}
Mathias Goebel's avatar
Mathias Goebel committed
143
144
145
146
147
148
149
150
151
152
153
                    </svg>
            else
                if(contains($node//tei:figDesc/tei:ref/text(), "horizontale Halbschleife von links nach rechts unten"))
                then
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 114 24">
                    <path id="Unnamed" fill="none" stroke="darkslategrey" stroke-width="1"
                            d="M 2.75,20.00 C 12.88,23.38 91.88,-1.50 106.75,4.12  113.62,6.88 112.00,12.12 110.50,13.25  107.25,15.00 105.00,11.12 105.00,11.12" />
                    </svg>
            else
                if(contains($node//tei:figDesc/tei:ref/text(), "horizontale Halbschleife von links oben nach rechts"))
                then
154
155
                    (<svg xmlns="http://www.w3.org/2000/svg" style="bottom:0; position:absolute;" viewBox="0 0 743 76" height="100%" width="100%" preserveAspectRatio="none">
                        <path fill="none" stroke="darkslategrey" stroke-width="3"
Mathias Goebel's avatar
Mathias Goebel committed
156
                            d="M 181.33,35.33 C 181.33,35.33 257.33,20.67 232.67,10.67  222.67,-3.33 4.67,27.33 6.67,42.00  4.67,73.33 380.00,68.00 730.00,52.67" />
157
158
159
160
161
                    </svg>,
                    element xhtml:div {
                      attribute class {'hrHover'},
                      'Absatzlinie'
                    })
Mathias Goebel's avatar
Mathias Goebel committed
162
163
164
            else
                if(contains($node//tei:figDesc/tei:ref/text(),"horizontale Schleife von links oben nach rechts unten"))
                then
165
166
                  <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="auto" viewBox="0 0 220 29">
                      {element svg:path {
Mathias Goebel's avatar
Mathias Goebel committed
167
168
169
170
                          attribute id {"sl2r1"},
                          attribute fill {"none"},
                          attribute stroke {"darkslategrey"},
                          attribute stroke-width {"1.5"},
171
172
173
174
175
                          attribute d {"M 14.00,18.18 " ||
                             " C 4.55,19.82 -2.73,27.09 5.27,26.55 " ||
                               " 65.64,20.91 197.64,-20.00 218.18,16.36 " ||
                               " 213.64,19.82 203.45,13.64 203.45,13.64" }}}
                  </svg>
Mathias Goebel's avatar
Mathias Goebel committed
176
177
178
            else
                if(contains($node//tei:figDesc/tei:ref/text(),"horizontale Halbschleife von links unten nach rechts"))
                then
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
                  <svg xmlns:dc="http://purl.org/dc/elements/1.1/"
                    xmlns:cc="http://creativecommons.org/ns#"
                    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                    xmlns="http://www.w3.org/2000/svg"
                    version="1.1"
                    viewBox="0 0 59 16"
                    height="100%"
                    width="100%"
                    preserveAspectRatio="none">
                    <metadata>
                      <rdf:rdf>
                        <cc:work rdf:about="">
                          <dc:format>image/svg+xml</dc:format>
                          <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"></dc:type>
                          <dc:title></dc:title>
                        </cc:work>
                      </rdf:rdf>
                    </metadata>
                    <path d="M 20.55,10.82 C 20.55,10.82 -8.18,5.55 6.91,5.09  35.18,4.00 57.00,3.91 57.00,3.91" stroke-width="1" stroke="black" fill="none" id="hsl2r"></path>
                  </svg>
Mathias Goebel's avatar
Mathias Goebel committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
            else
                if(contains($node//tei:figDesc/tei:ref/text(), 'Absatzlinie')) then
                    (element xhtml:hr {attribute class {'Absatzlinie'}
                },
                element xhtml:div {
                    attribute class {'hrHover'},
                    'Absatzlinie'
                })
            else
                if(contains($node//tei:figDesc/tei:ref/text(), 'Abgrenzungslinie')) then
                (element xhtml:hr {
                    attribute class {
                        'Abgrenzungslinie',
                        (let $medium := fontaneTransfo:getMedium($node)
Mathias Goebel's avatar
Mathias Goebel committed
213
214
215
216
                        return if($medium != ("pencil", "")) then $medium else ()),
                        if(contains($node//tei:figDesc/tei:ref/text(), 'Halbkreis'))
                        then "Halbkreis"
                        else ()
Mathias Goebel's avatar
Mathias Goebel committed
217
218
219
220
221
222
223
224
225
226
227
                    }
                },
                element xhtml:div {
                    attribute class {'hrHover'},
                    'Abgrenzungslinie'
                })
            else
                if(contains($node//tei:figDesc/tei:ref/text(), 'Schlusslinie')) then
                    (
                    if(contains($node//tei:figDesc/tei:ref/text(), "horizontale Halbschliefe von links oben nach rechts"))
                    then
228
229
                          <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="auto" viewBox="0 0 418 40">
                            {element svg:path {
Mathias Goebel's avatar
Mathias Goebel committed
230
231
232
                              attribute fill {"none"},
                              attribute stroke {"darkslategrey"},
                              attribute stroke-width {"1"},
233
234
235
236
237
238
                              attribute d {"M 408.00,13.50" ||
                                 " C -6.50,51.50 -4.50,22.50 17.00,16.00" ||
                                   " 17.00,16.00 35.50,12.50 35.50,12.50"}
                              }
                            }
                          </svg>
Mathias Goebel's avatar
Mathias Goebel committed
239
240
241
242
243
244
                    else
                        element xhtml:hr {
                            attribute class {'Schlusslinie'}
                        },
                element xhtml:div {
                    attribute class {'hrHover'},
245
                    if(contains($node//tei:figDesc/tei:ref/text(), 'ehemalige')) then 'ehemalige' else (),
Mathias Goebel's avatar
Mathias Goebel committed
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
                    'Schlusslinie'
                })
            else ()
    case element(tei:line)
        return
            try {
            element xhtml:div  {
                attribute class {'line', fontaneTransfo:segStyle($node), if($node/@type) then string($node/@type) else ()},
                attribute style {
                    string-join((
                        ($node/@style),
                        (if($node//text()[not(parent::tei:fw)]) then () else ('height:0.6cm;')),
                        ( (: line-height given in div.zone[style] has no effect wheren large rendering is needed :)
                        if($node//*[contains(string(@style), 'large')] or $node//ancestor::tei:zone[contains(string(@style), 'large')]) then replace( fontaneTransfo:lineHeight($node/parent::tei:zone), 'line-height', 'max-height') else ())
                ), ';')
                },
                try {fontaneTransfo:magic($node/node())} catch * { ($err:code , $err:description, $err:value) }
            }}
            catch * { ($err:code , $err:description, $err:value)  }

    case element(tei:seg)
        return
            if ($node/tei:g[@ref="#hb"]) then fontaneTransfo:fraction($node)
            else
            element xhtml:span {
                attribute class {
                    'seg',
                    if ($node/@style or $node/@rend or $node/@type) then fontaneTransfo:segStyle($node) else ()
                },
                if(contains($node/@style, 'letter-spacing')) then
                    attribute style { 'letter-spacing:'||substring-before(substring-after($node/@style, 'letter-spacing:'), 'cm')||'cm;'}
                    else (),
                fontaneTransfo:magic($node/node()),
                if($node/@type = "abort")
                then
                    element xhtml:div {
                        attribute class {'segHover italic'},
                        'Schreibabbruch'}
                else (),
                if($node/@type = "multiphrase")
                then
                    element xhtml:div {
                        attribute class {'segHover italic'},
                        'Mehrfachformulierung'}
                else ()
            }
    case element(tei:fw)
        return
294
          if (($node/preceding::tei:handShift[@new][1]/@new != '#Fontane') or not( exists( $node/preceding::tei:handShift[@new] ) ))
Mathias Goebel's avatar
Mathias Goebel committed
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
            then
                (element xhtml:div { attribute class {'fwWrapper'},
                element xhtml:span {
                    attribute class {'fw', (if ($node = ($node/ancestor::tei:surface//tei:fw[preceding::tei:handShift/@new != '#Fontane'])[position() gt 1] ) then (
                        (:'fw2':) ()
                        ) else () )
                    }, fontaneTransfo:magic($node/node())}
                })
            else
                element xhtml:span {
                    attribute class {'fw-fontane'},
                    fontaneTransfo:magic($node/node())
                }
    case element(tei:mod)
        return
            element xhtml:span {
                attribute class {
                    'mod',
                    $node/@type,
                    if($node/@rend) then "mod"||replace($node/@rend, ":", "_") else ()
                },
                if($node/@style) then attribute style {
                    if($node/@seq = "1")
                    then string($node/@style)
                    else
                        if($node/@seq = "2" and $node/@style = "text-decoration:underline" )
                        then "border-bottom: 1px solid darkslategrey;"
                        else ()
                } else (),
                if($node//del[@rend='overwritten']) then
                    element xhtml:div {
                        attribute class {'modHover italic', if($node/ancestor::tei:*/@rotate or $node/ancestor::tei:zone/preceding-sibling::tei:addSpan) then () else 'hoverTop'},
                        if($node/ancestor::tei:*/@rotate) then attribute style {'top:30px; transform:rotate(-'|| sum($node/ancestor::tei:*/@rotate) ||'deg);', '-webkit-transform:rotate(-'|| sum($node/ancestor::tei:*/@rotate) ||'deg);'} else (),
                        if(ends-with($node/preceding::text()[1][parent::tei:line = $node/parent::tei:line], ' ') or ends-with($node/preceding::text()[1][parent::tei:line = $node/parent::tei:line], ' '))
                            then ()
                            else
                               element xhtml:span { local:preText($node)},
                        '<',
                        element xhtml:span {
                            if( $node//tei:g[@ref="#hb"] )
                                then fontaneTransfo:magic($node/tei:del/node())
                                else fontaneTransfo:magic($node/tei:del/node())//text(),
                            (if ($node/tei:del/tei:gap) then fontaneTransfo:magic($node/tei:del/tei:gap) else ())
                        },
                        ' überschrieben ',
                        element xhtml:span {
                            string-join($node/tei:add//text())
                        },
343
                        '>', if(matches(string-join($node//tei:add/text()), '^\.$|^,$|^:$|^;$')) then () else element xhtml:span { fontaneTransfo:postText($node) }
Mathias Goebel's avatar
Mathias Goebel committed
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
                    }
                else if($node//del[not(@rend='overwritten')]) then
                    element xhtml:div {
                        attribute class {'modHover italic', if($node/ancestor::tei:*/@rotate or $node/ancestor::tei:zone/preceding-sibling::tei:addSpan) then () else 'hoverTop'},
                        if($node/ancestor::tei:*/@rotate) then attribute style {'top:30px; transform:rotate(-'|| sum($node/ancestor::tei:*/@rotate) ||'deg);', '-webkit-transform:rotate(-'|| sum($node/ancestor::tei:*/@rotate) ||'deg);'} else (),
                        ('Ersetzung', if( contains(string-join($node//@rend), 'caret') ) then 'mit Einweisungszeichen' else ())
                    }
                else (),
                fontaneTransfo:magic($node/node())
            }
    case element(tei:del)
        return
            element xhtml:span {
                attribute class {'del', replace($node/@rend, '#', 'hash'), if($node/@instant)then'instant'else()},
                (
                    if(local:modTest($node/parent::tei:mod))
                    then
                        attribute style {'text-align: center;display: inline-block;position: absolute;width:100%;'}
                    else ()),
                fontaneTransfo:magic($node/node()),
                if($node/@instant) then
                    element xhtml:div {
                        attribute class {'instantHover italic'},
                        'Sofortkorrektur'}
                else()
            }
    case element(tei:hi)
        return
            element xhtml:span {
                attribute class {'hi'},
                fontaneTransfo:magic($node/node())
            }
    case element(tei:add)
        return
            if( $node/@corresp and not($node/@type="multiphrase") ) then () else
            fontaneTransfo:addPreselection($node)
    case element(tei:retrace)
        return
            (
            fontaneTransfo:retrace($node),
            fontaneTransfo:magic($node/node())
            )
    case element(tei:restore)
        return
            element xhtml:span {
                attribute class {'restore'},
                element xhtml:div {attribute class {'restoreHover italic'},"Durchstreichung zurückgenommen"},
                fontaneTransfo:magic($node/node())
            }
    case element(tei:choice)
        return
            element xhtml:span {
                attribute class {'choice'},
                if ($node/tei:expan) then
                    element xhtml:div {
                        attribute class {'expan italic'},
                        let $count := count($node//tei:expan)
                        return
                            if($count = 1) then $node//tei:expan/text()
                            else for $expan at $pos in $node//tei:expan
                                    return
                                        if($pos = ($count - 1)) then $expan || '&#x2003;oder&#x2003;'
                                        else if($pos = $count)then $expan
                                        else $expan || ',&#x2003;'
                    }
                else (),
                fontaneTransfo:magic($node/node())
            }
    case element(tei:abbr)
        return
            element xhtml:span {
                attribute class {'abbr'},
                fontaneTransfo:magic($node/node())
            }
    case element(tei:rs)
        return
            element xhtml:span {
                attribute class {'rs', if($node/@type) then $node/@type else (), if($node/@ref) then substring-before($node/@ref, ':') else ()},
                attribute data-ref { string($node/@ref) },
                fontaneTransfo:magic($node/node())
            }
    case element(tei:date)
        return
            element xhtml:span {
                attribute class {'date'},
                fontaneTransfo:magic($node/node())
            }
    case element(tei:stamp)
        return
            element xhtml:div {
                attribute class {'stamp'},
                fontaneTransfo:stamp($node)
            }
    case element(tei:metamark)
        return fontaneTransfo:metamark($node)
    case element(tei:g)
        return
            if ($node/@ref='#mgem') then
                element xhtml:span {
                    attribute class {'g mgem'},
                    fontaneTransfo:magic($node/node())
                }
            else if ($node/@ref='#ngem') then
                element xhtml:span {
                    attribute class {'g ngem'},
                    fontaneTransfo:magic($node/node())
                }
            else if ($node/@ref="#rth") then
                element xhtml:span {
                    attribute class {'g rth'},
                    <xhtml:div class="hover">Reichstaler</xhtml:div>,
                    <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="auto" viewBox="0 0 82 107">
                        {element path {
                            attribute fill {"none"},
                            attribute stroke {"darkslategrey"},
                            attribute stroke-width {"5"},
                            attribute d {"M 24.73,35.82" ||
                               " C 24.73,35.82 30.36,30.73 32.00,26.55" ||
                                " 46.73,45.27 80.55,37.45 70.00,38.18" ||
                                " 16.73,50.73 -2.55,99.09 19.09,101.82" ||
                                " 52.00,103.45 57.09,80.00 42.91,80.91" ||
                                " 11.82,83.64 35.45,105.45 52.00,99.64" }}}
                    </svg>
                    }
            else ()
    case element(tei:unclear)
    return
        element xhtml:span {
            attribute class {'unclear'},
            fontaneTransfo:magic($node/node())
        }
    case element(tei:gap)
        return
            fontaneTransfo:gap($node)
    case element(tei:milestone) return
        element xhtml:span {
480
            attribute class {'milestone', string($node/@type), string($node/@unit)},
Mathias Goebel's avatar
Mathias Goebel committed
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
            attribute style {'display:none;'}
        }
    case element(tei:ref)
        return
            if($node/parent::tei:figDesc) then () else
            element xhtml:span {
                attribute class {'ref'},
                attribute id {'ref'||substring-after($node/@target, '#')},
                (: mouseover :)
                if(not(contains($node/@target, 'refxpath')) and substring-before(substring-after($node/@target, 'surface[@n'), "']")
                    = $node/ancestor::tei:surface[last()]/string(@n))
(: productive = $node/ancestor::tei:surface/tei:surface/string(@n)) :)
                then attribute onmouseover {
                    '$("[id=ref'|| substring-after($node/@target, '#') ||'], #'||substring-after($node/@target, '#')||'").toggleClass("highlight")'
                } else (),
                fontaneTransfo:magic($node/node()),
                (: link :)
                if(starts-with($node/@target, '#xpath(//surface') or not(contains($node/@target, $node/ancestor::tei:surface[last()]/@n)))
                then
                    element xhtml:span {
                        attribute class {'href'},
                        element xhtml:a {
                            if(not( contains($node/@target, 'xpath') ))
                            then (  attribute href {'edition.html?id=/xml/data/'|| $node/ancestor::tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:ab/tei:idno/substring-after(., ':') ||'.xml&amp;page='|| substring-before(substring-after($node/@target, "_"), "_") ||'&amp;target='||substring-after($node/@target, "#")},
                                    <i class="fa fa-link"/>
                                )
                            else
                                (   attribute href {'edition.html?id=/xml/data/'|| $node/ancestor::tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:ab/tei:idno/substring-after(., ':') ||'.xml&amp;page='||substring-before(substring-after($node/@target, "[@n='"), "']")},
                                    <i class="fa fa-link"/>
                                )
                        }
                    }
                else()
            }
Mathias Goebel's avatar
Mathias Goebel committed
515
516
517
    case element(tei:space)
        return
            element xhtml:span {
518
                attribute class {"space", string($node/@type), string($node/@unit) || string($node/@quantity)}
Mathias Goebel's avatar
Mathias Goebel committed
519
            }
Mathias Goebel's avatar
Mathias Goebel committed
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
    case element(tei:expan) return ()
    case element(tei:addSpan) return ()
    case element(tei:handShift) return ()
    case element(tei:lb) return ()
    case element(tei:anchor) return
        if( $node/ancestor::tei:sourceDoc//tei:add[@corresp = '#'||$node/@xml:id] )
        then
            element xhtml:span {
                attribute class { 'anchored' },
                fontaneTransfo:addPreselection( $node/ancestor::tei:sourceDoc//tei:add[@corresp = '#'||$node/@xml:id] )
            }
        else ()
    case text()
        return
            fontaneTransfo:text($node)
    default return fontaneTransfo:magic($node/node())
};
Mathias Goebel's avatar
Mathias Goebel committed
537
declare function fontaneTransfo:surfaceDiv($node as node(), $inital as xs:string) {(
538
539
540
541
    if($node/parent::tei:sourceDoc or string($node/@n) = $inital)
    then
            element xhtml:div {
            attribute class {'rowWrapper', 'clearfix', 'butthead'},
Mathias Goebel's avatar
Mathias Goebel committed
542
(:                    attribute id { $node/string(@n) },:)
543
            fontaneTransfo:facs($node),
Mathias Goebel's avatar
Mathias Goebel committed
544
(:                    if($node/string(@type) = ("clipping", "additional")):)
545
546
            element xhtml:div {
                if($node/@subtype="Kalenderblatt")
Mathias Goebel's avatar
Mathias Goebel committed
547
548
                (: cause of rotation handling, an additional div is needed for
                mostly rotated Kalenderblätter:)
549
                then
Mathias Goebel's avatar
Mathias Goebel committed
550
                    element xhtml:div {
551
                        fontaneTransfo:surface($node, $inital),
Mathias Goebel's avatar
Mathias Goebel committed
552
                        fontaneTransfo:magic($node/node())
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
                    }
                else(
                fontaneTransfo:surface($node, $inital),
                fontaneTransfo:magic($node/node()))
            },
            element xhtml:div {
                attribute class {'teixml'},
                element xhtml:pre {
                    element xhtml:b {
                        <xhtml:h3 class="xmlTitle">Auszug aus dem TEI/XML-Dokument</xhtml:h3>,
                        <xhtml:div>
                            <xhtml:a href="xml.html?id=/xml/data/{$node/preceding::tei:teiHeader//tei:idno[@type="TextGrid"]/substring-after(., 'textgrid:')}.xml">Gesamtes TEI/XML-Dokument</xhtml:a>
                            |
                            <xhtml:a target="_blank" href="rest/data/{$node/preceding::tei:teiHeader//tei:idno[@type="TextGrid"]/substring-after(., 'textgrid:')}.xml">(via REST)</xhtml:a>
                        </xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
568
                    },
569
570
571
                    element xhtml:code {
                        attribute class {'html'},
                        serialize($node)
Mathias Goebel's avatar
Mathias Goebel committed
572
                    }
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
                }
                }
            }
    else
    (
    element xhtml:div {
        fontaneTransfo:surface($node, $inital),
        if($node/@type = ('clipping', 'additional'))
        then
            fontaneTransfo:magic($node/node())
        else fontaneTransfo:magic($node/node())
    }),
    let $ids := $node//@xml:id,
        $notes := $node/ancestor::tei:TEI//tei:note[@type="editorial"]/tokenize(replace(@target, "#", ""), " "),
        $test := (($ids = $notes) and string($node/@n) = $inital)
    return
        if($test) then
Mathias Goebel's avatar
Mathias Goebel committed
590
            element xhtml:div {
591
592
593
594
595
596
                attribute class {"notes"},
                element xhtml:ul {
                    for $i in $node/ancestor::tei:TEI//tei:note[@type="editorial"][tokenize(replace(@target, "#", ""), " ") = $ids]
                    return
                        element xhtml:li {
                            fontaneTransfo:noteParser($i)
Mathias Goebel's avatar
Mathias Goebel committed
597
                        }
598
                }
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
599

600
601
            }
        else ()
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
602

Mathias Goebel's avatar
Mathias Goebel committed
603
)};
604
declare function fontaneTransfo:surface($n, $inital) {
Mathias Goebel's avatar
Mathias Goebel committed
605
attribute class {
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
606
    'surface',
607
    (if($n/@type) then (' tei'||$n/@type) else ()),
Mathias Goebel's avatar
Mathias Goebel committed
608
    (if($n/@subtype) then string($n/@subtype) else ()),
Mathias Goebel's avatar
Mathias Goebel committed
609
610
611
    if( string($n/@subtype)="Kalenderblatt") then if(ends-with($n/@n, 'v')) then 'verso' else 'recto' else (),
    if( $n/parent::tei:surface ) then "nested" else ()
},
Mathias Goebel's avatar
Mathias Goebel committed
612
(: dont call it a label (bootstrap) :)
Mathias Goebel's avatar
Mathias Goebel committed
613
(if($n/@n) then attribute id {"s"||$n/@n} else()),
Mathias Goebel's avatar
Mathias Goebel committed
614
attribute style {
615
  let $values := distinct-values((
Mathias Goebel's avatar
Mathias Goebel committed
616
617
618
    if ($n/(@ulx or @uly)) then ('position:absolute;', 'top:'|| $n/@uly ||'cm;', 'left:'|| $n/@ulx ||'cm;') else (),
    if ($n/(@ulx and @lrx)) then ('position:absolute;' ,'left:'|| $n/@ulx ||'cm;' , 'width:'||$n/@lrx - $n/@ulx||'cm;') else (),
    if ($n/(@uly and @lry)) then ('position:absolute;', 'top:'|| $n/@uly ||'cm;' , 'height:'||$n/@lry - $n/@uly||'cm;') else (),
619
620
621
622
623
624
625
626
627
    if ($n/@subtype = 'Kalenderblatt')
    then (
            'top:'|| $n/@uly ||'cm;',
            'left:'|| $n/@ulx ||'cm;',
            'width:'||$n/@lrx - $n/@ulx||'cm;',
            'height:'||$n/@lry - $n/@uly||'cm;',
            "position:relative;"
        )
    else ()
Mathias Goebel's avatar
Mathias Goebel committed
628
    )) (: distinct values :)
629
630
631
632
633
  return
    (: omit top, left and position in case of a nested surface :)
      if( string($n/@n) = $inital )
      then $values[not( contains(., "absolute") ) and not( starts-with(., "top:") ) and not( starts-with(., "left:") )]
      else $values
Mathias Goebel's avatar
Mathias Goebel committed
634
635
636
637
638
639
640
641
642
}
};

declare function fontaneTransfo:zone($n) {
attribute class {
            'zone',
            string($n/@type),
            string($n/@subtype),
            if (exists($n/preceding-sibling::tei:addSpan) and $n/preceding-sibling::tei:addSpan/substring-after(@spanTo, '#') = $n/following-sibling::tei:anchor/@xml:id ) then 'addSpan' else(),
643
            if (exists($n/child::tei:mod[@seq])
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
644
              and
645
                  $n/child::tei:mod[@seq]/substring-after(@spanTo, '#') = $n/following-sibling::tei:anchor/@xml:id
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
646
                  )
647
              then 'mod-seq-'|| string($n/child::tei:mod[@seq][substring-after(@spanTo, '#') = $n/following-sibling::tei:anchor/@xml:id]/@seq) else(),
Mathias Goebel's avatar
Mathias Goebel committed
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
            if ($n/tei:figure) then 'figure' else(),
            fontaneTransfo:segStyle($n),
            if( $n/@type="illustration" and $n/parent::tei:line) then "verticalMiddel" else (),
            if(not( $n//tei:line ) and $n/tei:figure[string(.//tei:ref) = "Diagonale Streichung"]) then "deletion-diagonal" else (),
            let $id := string($n/@xml:id)
            let $metamark := $n/ancestor::tei:surface[1]//tei:metamark[contains(string(@corresp), $id)]
            return
                if( ($id != "") and ( $metamark//tei:ref/ends-with(., 'gestrichen; erledigt') = true()) ) then 'hover' else ()
    },
attribute style {
(: place it! :)
    if (($n/@ulx or $n/@uly or $n/@lrx or $n/@lry) and not($n/ancestor::tei:zone/@rotate))
        then
            if ($n/ancestor::tei:zone[last()]//tei:figure)
                then
                ('position:absolute;',
                'top:'|| $n/@uly - sum($n/ancestor::tei:zone/@uly)||'cm;',
                'left:'||$n/@ulx -sum($n/ancestor::tei:zone/@ulx)||'cm;',
(:  'width:'|| (if($n/@lry) then $n/@lrx - (if($n/@ulx) then $n/@ulx else 0) - sum($n/ancestor::tei:zone/@lrx) ||'cm;'  else '' )||:)
                    'width:'||(if($n/@lry) then $n/@lrx - (if($n/@ulx) then $n/@ulx else 0) - (if ($n/parent::tei:line) then 0 else sum($n/ancestor::tei:zone/@lrx)) ||'cm;'  else '' ),
(:  'height:'|| $n/@lry - (if($n/@uly) then $n/@uly else 0)  - sum($n/ancestor::tei:zone/@lry)||'cm;':)
                   'height:'|| $n/@lry - (if($n/@uly) then $n/@uly else 0)  - (if ($n/parent::tei:line) then 0 else sum($n/ancestor::tei:zone/@lry)) ||'cm;'
                ) else
            if (not($n/@ulx|$n/@uly|$n/@lrx) and $n//tei:fw)
                    then 'width:100%;'
(:                then if( $n//text()[matches(., '\w')][not(./ancestor::tei:fw)]) then 'width:100%;' else 'width:100%;height:0;':)
            else
                'position:absolute;'||
                'top:'|| $n/@uly ||'cm;'||
                'left:'||$n/@ulx ||'cm;'||
                'width:'||$n/@lrx - (if($n/@ulx) then $n/@ulx else 0) ||'cm;'||
                'height:'|| $n/@lry - (if($n/@uly) then $n/@uly else 0)  ||'cm;'
    else(),
    if( $n/not(@ulx|@lrx|@rotate) and $n//tei:fw)
(:        then 'width:100%;':)
        then if( $n//text()[matches(., '\w')][not(./ancestor::tei:fw)]) then 'width:100%;' else 'width:100%;'
(: edited: 2016-12-07
 : cause: email  "Probleme mit Seitenzahlen; dringend"
 : was: then if( $n//text()[matches(., '\w')][not(./ancestor::tei:fw)]) then 'width:100%;' else 'width:100%;height:0;'
 :)
    else (),
    if($n/ancestor::tei:zone/@rotate) then
        let $rotation := sum( $n/ancestor::tei:zone/@rotate )
        let $value:=
            if($rotation gt 89 and $rotation lt 180) then 'position:absolute;'|| 'top:-'|| $n/@ulx ||'cm;left:'|| $n/@uly ||'cm;'
            else ()
        return if(contains($value, '-cm') or contains($value, ':cm')) then () else $value
    else(),
(:    if( preceding-sibling::tei:*[1]/local-name="line" ) then 'position:absolute;' else(),:)
(: rotate it! :)
(:    if ($n/@rotate and not( $n/parent::tei:surface/count(tei:zone) = 1)) :)
    if ($n/@rotate)
        then
            'transform:rotate('|| $n/@rotate ||'deg);'||'-webkit-transform:rotate('|| $n/@rotate ||'deg);'
    else (),
    fontaneTransfo:lineHeight($n),
(: look 4 TILE objects :)
    if ($n/tei:figure[@xml:id]) then
        let $id := string($n/tei:figure/@xml:id)
        let $uri := string($n/ancestor::tei:TEI//tei:idno[@type="TextGrid"])

        let $link := fontaneTransfo:newestTBLELink($uri, $id)
        let $shape := $link/substring-before(substring-after(@targets, '#'), ' ')
(:        let $image := $tei//svg:g[@id = $link/parent::tei:linkGrp/substring-after(@facs, '#')]/svg:image/@xlink:href:)
Mathias Goebel's avatar
Mathias Goebel committed
712
(:        let $image := ($n/ancestor::tei:surface)[1]/substring-after(@facs, "textgridrep.org/") || ".1":)
Mathias Goebel's avatar
Mathias Goebel committed
713
714

        let $svgg := $link/ancestor::tei:TEI//svg:g[@id = $link/parent::tei:linkGrp/substring-after(@facs, '#')]
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
715
        let $image := substring-before($svgg//svg:image/@xlink:href, ".") || ".1"
Mathias Goebel's avatar
Mathias Goebel committed
716
717
718
719
        let $x := number($svgg//svg:rect[@id = $shape]/substring-before(@x, '%'))
        let $y := number($svgg//svg:rect[@id = $shape]/substring-before(@y, '%'))
        let $w := number($svgg//svg:rect[@id = $shape]/substring-before(@width, '%'))
        let $h := number($svgg//svg:rect[@id = $shape]/substring-before(@height, '%'))
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
720

721

Mathias Goebel's avatar
Mathias Goebel committed
722
723
        let $rotation := sum( ($n/ancestor-or-self::tei:*/@rotate) )
        let $rotation := if($rotation != 0) then 360 - $rotation else 0
724
725
726
727
728
        let $furtherAttributes :=
                if($n/ancestor::tei:line)
                then "width:"|| $n/@lrx - $n/@ulx ||"cm; height:"||$n/@lry - $n/@uly ||"cm;"
                else ""
        return ("background-image: url('https://textgridlab.org/1.0/digilib/rest/IIIF/"|| $image || '/pct:'||$x||','||$y||','||$w||','||$h||"/,1000/"|| $rotation ||"/default.jpg'); background-repeat: no-repeat; background-size: 100% 100%;"||$furtherAttributes)
Mathias Goebel's avatar
Mathias Goebel committed
729
(:        digilib/"|| $image || '?dh=500&amp;dw=500&amp;wx='||$x||'&amp;wy='||$y||'&amp;ww='||$w||'&amp;wh='||$h||"&amp;mo=png&amp;rot="||$rotation||"'); background-repeat: no-repeat; background-size: 100% auto;"):)
Mathias Goebel's avatar
Mathias Goebel committed
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
    else (),

    (: like on C07 15r, a zone can contain a single (nonword) character that belongs to nearby lines. in this cases, we increase the font size by rule.
    this stays against our practise to encode a font-size if semantic matters. we should discuss this.
    :)
    if (sum($n/tei:line//text()/string-length(.)) = 1 and $n/tei:line//text()/matches(., '\W' ) ) then 'font-size:'||$n/@lry - $n/@uly||'cm' else (),
    if (sum($n/tei:line//text()/string-length(.)) = 1 and $n/tei:line//text()/matches(., '\W' ) and ($n/@lry - $n/@uly gt 1)) then 'transform:scaleX(0.5)' else (),

    (: override height statements before, if we want to prepare an inline zone :)
    if($n/parent::tei:line)
        then
            (
                'display:inline-block; position:relative; left:0; top:0;'
            )
        else ()
},
if($n/@xml:id)
then
    attribute id {$n/@xml:id}
else (),
if($n/@xml:id and $n/ancestor::tei:TEI//tei:ref[substring-after(@target, '#')=$n/@xml:id])
then
    (: edit same line in ref too! :)
    attribute onmouseover {'$("[id=ref'|| $n/@xml:id ||'], #'||$n/@xml:id||'").toggleClass("highlight")'}
else (),
if (exists($n/preceding-sibling::tei:addSpan) and $n/preceding-sibling::tei:addSpan/substring-after(@spanTo, '#') = $n/following-sibling::tei:anchor/@xml:id ) then
    element xhtml:div {attribute class {'addSpanHover italic'}, 'Hinzufügung'}
    else(),
if($n/@rend="border-left-style:brace") then $fontaneTransfo:bracket_left.svg else (),
    let $id := string($n/@xml:id)
    let $metamark := $n/ancestor::tei:surface[1]//tei:metamark[contains(string(@corresp), $id)]
    return
if( ($id != "") and ( $metamark//tei:ref/ends-with(., 'gestrichen; erledigt') = true()) )
    then
        element xhtml:div {attribute class {'zoneHover'}, 'Erledigungsstreichung'}
    else ()
};
767
(:~ returns a sequence of class names according to the given styles
Mathias Goebel's avatar
Mathias Goebel committed
768
 : not only for tei:seg, also used in tei:zone
769
770
 : @param $node – a single tei:seg or tei:zone or whatever you have with @style
 : or @rend or to calculate line-height.
Mathias Goebel's avatar
Mathias Goebel committed
771
:)
772
declare function fontaneTransfo:segStyle($node) {
Mathias Goebel's avatar
Mathias Goebel committed
773
774
775
776
let
$style := $node/@style,
$rend :=  $node/@rend,

Mathias Goebel's avatar
minor    
Mathias Goebel committed
777
778
779
780
781
782
783
784
$type:= if(($node/local-name() = ("seg", "zone")) and ($node/@type = "cancel"))
        then
            if(not($node/@prev|$node/@next))
              then "cancelLeft cancelRight"
            else if($node/@next)
              then "cancelLeft"
            else if($node/@prev)
              then
Mathias Goebel's avatar
Mathias Goebel committed
785
                if($node/ancestor::tei:sourceDoc//tei:metamark[@function="deletion"][contains(@corresp, $node/@xml:id)]//tei:ref != "Diagonale Streichung begrenzt durch eine senkrechte Abgrenzung am Anfang")
Mathias Goebel's avatar
minor    
Mathias Goebel committed
786
787
788
                then "cancelRight"
                else ()
            else ()
Mathias Goebel's avatar
Mathias Goebel committed
789
790
791
792
793
794
795
796
797
798
799
800
        else (),

$noLineThroughInCaseOfDeletionViaMetamark :=  if(
    contains($node/@style, 'text-decoration:line-through') and
    ($node/ancestor-or-self::tei:*/concat('#', @xml:id) = tokenize( $node/ancestor::tei:TEI//tei:metamark/@corresp, ' ')) )
    then " noLineThrough"
    else ()

let $rend := replace($rend, '\s', '')

let $seq :=
    for $s in tokenize(replace(replace($style, 'radius:', 'radius'), '\s|\.|%|-style', ''), ';')
801
    where not(matches($s, "^margin\-left:\d{1,2}\.{0,1}\d{0,1}cm$"))
Mathias Goebel's avatar
Mathias Goebel committed
802
803
804
805
806
807
808
809
810
    return
        tokenize($s, ':')
(: -stlye now in pattern to be replaced
 :         for $t at $pos in tokenize($s, ':'):)
(:            return if (contains($t, '-style')) then substring-before($t, '-style') else $t:)

let $rendSeq :=
    for $r in tokenize(replace($rend, '\s', ''), ';')
    return
811
        replace(replace(replace($r, "medium:", "medium_"), ':', ' '), '[\(\)]', '')
Mathias Goebel's avatar
Mathias Goebel committed
812

813
let $preMedium := string($node/preceding::handShift[@medium][1]/@medium)
Mathias Goebel's avatar
Mathias Goebel committed
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
let $medium := if ($preMedium = ('blue_pencil', 'violet_pencil', 'black_ink', 'blue_ink', 'brown_ink')) then $preMedium[. = ('blue_pencil', 'violet_pencil', 'black_ink', 'blue_ink', 'brown_ink')] else ()
let $test:= if($seq = ()) then ('TODO', $medium) else ($seq, $rendSeq, $medium, $type, $noLineThroughInCaseOfDeletionViaMetamark)

return
    $test ! replace(replace(., '/', '_'), '3_4', 'd3_4')
};

declare function fontaneTransfo:retrace($node){

element xhtml:span {
    attribute class {'retrace'},
    element xhtml:span {
        attribute class {'retraced'},
        fontaneTransfo:magic($node/text()),
        element xhtml:div {
            attribute class {'retraceHover', if($node/ancestor::tei:*/@rotate and $node/ancestor::tei:zone/preceding-sibling::tei:addSpan) then () else 'hoverTop'},
            (if ($node/ancestor::tei:zone/@rotate) then attribute style {'transform: rotate('|| 360 - sum($node/ancestor::tei:zone/@rotate) ||'deg);'}
            else ()),

            local:preText($node),

            element xhtml:span {
                attribute class {'italic'},
                '<'},
            $node//text(),
            element xhtml:span {
                attribute class {'italic'},
                ' nachgezogen '},
                $node//text(),
                element xhtml:span {
                attribute class {'italic'},
                '>'},
846
            fontaneTransfo:postText($node)
Mathias Goebel's avatar
Mathias Goebel committed
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
        }
    }
}
};

declare function local:preText($n) {
let $directText := $n/preceding::text()
                [ancestor::tei:line = $n/ancestor::tei:line]
                [not(parent::tei:add[@place = ('below', 'above')])]
let $prvLineText := if($n/preceding::text()[ancestor::tei:line = $n/ancestor::tei:line][last()]/parent::*/@prev)
                    then ($n/ancestor::tei:TEI//*[@xml:id = substring-after($n/preceding::text()[ancestor::tei:line = $n/ancestor::tei:line][last()]/parent::*/@prev, '#')]//text())
                    else ()
let $prvLineText := if(
                        (string-join($prvLineText)="")
                        and ( not(matches(string-join($n/preceding::text()[ancestor::tei:line = $n/ancestor::tei:line]), '\s')))
                        and (
                               ends-with($n/ancestor::tei:line/preceding::tei:line[1], '-')
                            or ends-with($n/ancestor::tei:line/preceding::tei:line[1], '⸗')
                            )
                        )
                    then tokenize( string($n/ancestor::tei:line/preceding::tei:line[1]), ' ' )[last()]
                    else $prvLineText
return
    replace(tokenize(string-join( ($prvLineText, $directText) ), '\s|\.|,|;|&#x2003;' )[last()], $fontaneTransfo:tooltipReplacementPattern, '' )
};

873
declare function fontaneTransfo:postText($n) {
Mathias Goebel's avatar
Mathias Goebel committed
874
(:  former mod hover::)
875
let $text := if(matches($n/following::text()[1][ancestor::tei:line = $n/ancestor::tei:line], '\s'))
Mathias Goebel's avatar
Mathias Goebel committed
876
877
878
879
880
881
882
                            then ()
                            else
                                if( matches(string-join($n/following::text()[ancestor::tei:line = $n/ancestor::tei:line]), '\s' ))
                                then tokenize(string-join($n/following::text()[ancestor::tei:line = $n/ancestor::tei:line]), '\s' )[1]
                                else if(not($n/@next) and matches($n/ancestor::tei:line, '-$|⸗$' ))
                                then
                                    tokenize(string-join(
883
884
                                        ($n/following::text()[ancestor::tei:line = $n/ancestor::tei:line],
                                        $n/following::text()[ancestor::tei:line = $n/ancestor::tei:line/following::tei:line[1]])), ' ')[1]
885
886
                                else tokenize(string-join($n/following::text()[ancestor::tei:line = $n/ancestor::tei:line]), ' ')[1]

Mathias Goebel's avatar
Mathias Goebel committed
887
888
let $text :=    if( $n/@next )
                then
889
                    let $completeTEI := $n/ancestor::tei:TEI
Mathias Goebel's avatar
Mathias Goebel committed
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
                    return
                        $text || string($completeTEI//*[@xml:id= substring-after($n/@next, '#')])
                else $text

return if($text = "(") then $text else replace( $text , $fontaneTransfo:tooltipReplacementPattern, '' )
};

declare function fontaneTransfo:stamp($node) {
switch ($node/string(.))
case 'FONTANE.' return
                    <svg xmlns="http://www.w3.org/2000/svg" width="23mm" height="4mm" data-info="Stempel: FONTANE.">
                        <g alignment-baseline="baseline">
                            <text x="0mm" y="3.5mm" style="fill: purple;stroke: none;font-size:4mm; font-family:Ubuntu-Light, Verdana, sans-serif;">FONTANE.</text>
                        </g>
                    </svg>

case 'STAATSBIBLIOTHEK •BERLIN•' return
                    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="24.2mm" height="15.2mm" data-info="Stempel: STAATS- BIBLIOTHEK BERLIN">
                        <defs>
                            <filter id="unschaerfe" color-interpolation-filters="sRGB">
                                <feGaussianBlur stdDeviation="0.0"/>
                            </filter>
                        </defs>
                        <g alignment-baseline="baseline">
                            <g filter="url(#unschaerfe)">
                                <rect x="0.5mm" y="0.5mm" width="23mm" height="14mm" rx="1mm" fill="none" stroke="black" stroke-width="1mm"/>
                                <text
                                    style="stroke:none; font-family:FreeSerif, serif; font-size: 3.4mm; font-weight: bold;">
                                    <tspan id="zeile1" x="5mm" y="4mm">STAATS-</tspan>
                                    <tspan id="zeile2" x="1mm" y="8.5mm">BIBLIOTHEK</tspan>
                                    <tspan id="zeile3" x="3mm" y="13mm">∙ BERLIN ∙</tspan>
                                </text>
                            </g>
                        </g>
                    </svg>

case 'DSB Font.-Arch. Potsdam' return
                    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="15.2mm" height="15.2mm" data-info="Stempel: DSB Font.-Arch. Potsdam">
                        <defs>
                            <filter id="unschaerfe" color-interpolation-filters="sRGB">
                                <feGaussianBlur stdDeviation="0.3"/>
                            </filter>
                        </defs>
                        <g alignment-baseline="baseline">
                            <circle cx="7.5mm" cy="7.5mm" r="7.25mm" fill="none" stroke="darkblue" stroke-width="0.5mm"/>
                            <text style="font-size:65%; font-family:FreeSans;" fill="darkblue">
                                <tspan id="zeile1" x="4.5mm" y="4mm">DSB</tspan>
                                <tspan id="zeile2" x="0.9mm" y="7.5mm">Font.-Arch.</tspan>
                                <tspan id="zeile3" x="2mm" y="11mm">Potsdam</tspan>
                            </text>
                        </g>
                    </svg>
case "BERLIN W.West" return
                    <img src="/public/img/stempel-berlin-w.png" width="100%" height="100%"/>
default return
                    <svg xmlns="http://www.w3.org/2000/svg" width="23mm" height="3.5mm">
                        <g alignment-baseline="baseline">
                            <text x="0mm" y="3.5mm" style="font-size:4mm; font-family:Ubuntu-Light, Verdana, sans-serif;" fill="purple">Stempel nicht unterstützt oder Fehler im Code.</text>
                        </g>
                    </svg>
};
declare function fontaneTransfo:text($n) {
let $followingAnchorWithModBeforeThisNode :=  $n/following::tei:anchor[@xml:id = $n/preceding::tei:mod[@seq]/substring-after(@spanTo, '#')]/('#'||@xml:id)
let $allModBefore := $n/preceding::tei:mod[@spanTo = $followingAnchorWithModBeforeThisNode]
let $modClasses := for $mod in $allModBefore return ("modSeq" || string($mod/@seq), fontaneTransfo:segStyle($mod))
Mathias Goebel's avatar
Mathias Goebel committed
955
let $handShiftNewRef := $n/preceding::handShift[@new][1]/substring-after(@new, '#')
Mathias Goebel's avatar
Mathias Goebel committed
956
957
958
959
960
961
return
if ($n/ancestor::tei:line) then
element xhtml:span {
    attribute class {
        $modClasses,
        if(not(
Mathias Goebel's avatar
Mathias Goebel committed
962
963
964
            matches($handShiftNewRef, 'Archivar|Druck')
            ))
        then (
Mathias Goebel's avatar
Mathias Goebel committed
965
          (: medium :)
Mathias Goebel's avatar
Mathias Goebel committed
966
            $n/preceding::handShift[@medium][1]/@medium,
Mathias Goebel's avatar
Mathias Goebel committed
967
          (: hand :)
Mathias Goebel's avatar
Mathias Goebel committed
968
            $handShiftNewRef,
Mathias Goebel's avatar
Mathias Goebel committed
969
970
            if ($handShiftNewRef = '') then 'Fontane' else
          (: rendition :)
Mathias Goebel's avatar
Mathias Goebel committed
971
            $n/preceding::handShift[@rendition][1]/@rendition,
Mathias Goebel's avatar
Mathias Goebel committed
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
          (: script :)
            let $script :=
              (if (contains($n/preceding::handShift[@script][1]/@script, ' '))
              then string($n/preceding::handShift[@script][1]/@script)
              else
                  if($n/preceding::handShift[@script][1]/@script = ('standard', 'clean', 'hasty', 'angular'))
                  then $n/preceding::handShift[contains(@script, 'Latn') or contains(@script, 'Latf')][1]/tokenize(@script, ' ')[. = ('Latn', 'Latf')] || ' ' || $n/preceding::handShift[@script][1]/@script
                  (: ^^^ no test for an additional whitespace together with Latn or Latf, characteristics will be overwritten by the current @script :)
              else
                  if ($n/preceding::handShift[@script][1]/@script = ('Latn', 'Latf'))
                  then $n/preceding::handShift[@script][1]/@script || ' ' || $n/preceding::handShift[contains(@script, 'standard') or contains(@script, 'clean') or contains(@script, 'hasty') or contains(@script, 'angular')][1]/tokenize(@script, ' ')[. = ('standard', 'clean', 'hasty', 'angular')]
              else ''
              )
            return
              if($n/ancestor::tei:seg[@xml:lang] and matches($script, "standard|clean|hasty|angular")) then
                substring-after($n/ancestor::tei:seg[@xml:lang]/@xml:lang, '-') || ' ' || substring-after($script, ' ')
              else $script
          )
Mathias Goebel's avatar
Mathias Goebel committed
990
        else (
Mathias Goebel's avatar
Mathias Goebel committed
991
            $handShiftNewRef
Mathias Goebel's avatar
Mathias Goebel committed
992
993
994
            )
    },
    attribute data-info {
Mathias Goebel's avatar
Mathias Goebel committed
995
        let $hand := $handShiftNewRef
Mathias Goebel's avatar
Mathias Goebel committed
996
997
998
999
1000
        let $hand := switch($hand)
                        case '' return 'Theodor Fontane'
                        case 'Fontane' return 'Theodor Fontane'
                        case 'Friedrich_Fontane' return 'Friedrich Fontane'
                        default return $hand
For faster browsing, not all history is shown. View entire blame