tei2teisimple.xqm 31.8 KB
Newer Older
MRodz's avatar
MRodz committed
1
2
xquery version "3.1";

3
(:~
Michelle Rodzis's avatar
Michelle Rodzis committed
4
5
 : This modules handles the conversion of the Fontante-TEI/XML into TEI simplePrint
 : for the edited text. The resulting TEI simplePrint is the basis for the "Editerter
6
 : Text" (edited text) view on the website and the book. It represents the latest
Michelle Rodzis's avatar
Michelle Rodzis committed
7
 : layer of text.
8
 :
MRodz's avatar
MRodz committed
9
10
 : @author Michelle Rodzis
 : @version 0.1
Michelle Rodzis's avatar
Michelle Rodzis committed
11
 : @since TODO
MRodz's avatar
MRodz committed
12
13
 :)

14
module namespace fontaneSimple="http://fontane-nb.dariah.eu/teisimple";
MRodz's avatar
MRodz committed
15
16

declare namespace tei="http://www.tei-c.org/ns/1.0";
MRodz's avatar
MRodz committed
17
declare namespace test="http://exist-db.org/xquery/xqsuite";
MRodz's avatar
MRodz committed
18
19

import module namespace console="http://exist-db.org/xquery/console";
20
import module namespace simpleHelpers="http://fontane-nb.dariah.eu/teisimplehelpers" at "teisimplehelpers.xqm";
MRodz's avatar
MRodz committed
21

22
(:~
MRodz's avatar
MRodz committed
23
 : The main function initiates the transformation of a given notebook.
24
 :
MRodz's avatar
MRodz committed
25
 : TODO: adapt to several input files?
26
 :
MRodz's avatar
MRodz committed
27
 : :)
MRodz's avatar
MRodz committed
28
declare function fontaneSimple:main($file as xs:string) as node()? {
29
  let $doc :=
MRodz's avatar
MRodz committed
30
    try {
31
      (doc("/db/sade-projects/textgrid/data/xml/data/" || $file))
MRodz's avatar
MRodz committed
32
33
34
    } catch * {
      (console:log("It was not possible to open the requested file " || $file))
    }
35

MRodz's avatar
Fix #23    
MRodz committed
36
37
    let $front-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "front_cover")]
    let $back-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "back_cover")]
38
    let $content := $doc//tei:sourceDoc/tei:surface[not(contains(@n, "cover")
MRodz's avatar
MRodz committed
39
        or matches(@n, "spine"))]
40

41
    let $tei := <TEI xmlns="http://www.tei-c.org/ns/1.0">
MRodz's avatar
MRodz committed
42
        {$doc//tei:teiHeader}
MRodz's avatar
MRodz committed
43
        <text>
44
45
46
            <front>{fontaneSimple:transform($front-covers)}</front>
            <body>{fontaneSimple:transform($content)}</body>
            <back>{fontaneSimple:transform($back-covers)}</back>
MRodz's avatar
MRodz committed
47
        </text>
MRodz's avatar
MRodz committed
48
      </TEI>
49
     let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-pre.xml", $tei)
MRodz's avatar
MRodz committed
50
    return $tei
MRodz's avatar
MRodz committed
51
52
};

53
(:~
54
55
56
57
58
59
60
61
62
 : Recursivly iterates the passed nodes and converts them according to the
 : requirements for the "Edierter Text". While it convers almost all of the
 : requirements stated in the encoding documentation (c.f.
 : https://fontane-nb.dariah.eu/doku.html), some parts of it are handled in a
 : second step (c.f. TODO) - especially the removal of tei:handShift duplicates
 : and the tei:milestone expansion to tei:div[@type = "section"] resp. tei:p -
 : because it is easier to perform these steps after the XML hierarchy has been
 : flattened a bit.
 :
MRodz's avatar
MRodz committed
63
 : @author Michelle Rodzis
64
 : @param $nodes the elements of the book covers and the book content
Michelle Rodzis's avatar
Michelle Rodzis committed
65
 : @return $node()* a TEI simplePrint element
MRodz's avatar
MRodz committed
66
 :)
67
declare function fontaneSimple:transform($nodes as node()*) as node()* {
MRodz's avatar
MRodz committed
68
69
70
    for $node in $nodes
      return
        typeswitch ($node)
MRodz's avatar
MRodz committed
71
        case text() return
MRodz's avatar
MRodz committed
72
73
74
75
76
77
78
            if($node/ancestor::tei:line
            or $node/ancestor::tei:figDesc
            or $node/ancestor::tei:desc[@type = "edited_text"]
            or $node/ancestor::tei:note[@type = "editorial"]) then
                simpleHelpers:prepare-text($node)
            else
                ()
79

MRodz's avatar
MRodz committed
80
81
82
        case element(tei:lb) return
            if($node[@break = "keepHyphen"]) then
                ()
83
84
            else if($node[@break = "no"]) then
                fontaneSimple:mark-intervention($node)
MRodz's avatar
MRodz committed
85
            else
86
                fontaneSimple:copy-element($node)
87

MRodz's avatar
MRodz committed
88
89
90
91
        case element(tei:g) return
            if($node[@ref = "#vds"]) then
                ()
            else if($node/@ref ="#rth" or $node/@ref ="#hb") then
92
                fontaneSimple:copy-element($node)
MRodz's avatar
MRodz committed
93
            else
94
                fontaneSimple:transform($node/node())
95

MRodz's avatar
MRodz committed
96
97
        case element(tei:del) return
            if($node/parent::tei:restore) then
98
                fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
99
            else if($node/descendant::tei:restore) then
100
                fontaneSimple:transform($node/descendant::tei:restore)
MRodz's avatar
MRodz committed
101
            else
MRodz's avatar
MRodz committed
102
                ()
103

MRodz's avatar
MRodz committed
104
105
106
107
108
        case element(tei:restore) return
            if(count($node/child::*) = 1 and $node/child::tei:del
            and $node/ancestor::tei:del) then
                ()
            else
109
                fontaneSimple:transform($node/node())
110

MRodz's avatar
MRodz committed
111
112
113
        case element(tei:retrace) return
            if($node/@rend) then
                element tei:seg {
Michelle Rodzis's avatar
Michelle Rodzis committed
114
                    attribute rendition {$node/@rend},
115
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
116
117
                }
            else
118
                fontaneSimple:transform($node/node())
119

120
        case element(tei:add) return
121
            if($node/@type = "edited_text"
122
            or $node/child::tei:seg[@type = "multiphrase"]) then
123
                fontaneSimple:copy-element($node)
124
125
126
127
(:                :)
(:            else if($node[matches(@copyOf, $node/preceding::tei:seg/@xml:id):)
(:                and not(@cause = "unclear")]) then:)
(:                fontaneSimple:mark-intervention($node):)
128
                
129
130
131
132
133
            
            else if($node/@cause = "unclear") then
                ()
                
            else if($node[matches(@copyOf, $node/preceding::tei:seg/@xml:id)]) then
134
                fontaneSimple:mark-intervention($node)
135
                
136
            else if($node/@cause ="catchword") then
MRodz's avatar
MRodz committed
137
                ()
138
                
MRodz's avatar
MRodz committed
139
            else if($node/@rend ="|") then
140
                fontaneSimple:transform($node/node())
141
                
142
            else if(not($node/@xml:id)) then
143
                fontaneSimple:transform($node/node())
144
                
145
            else if(simpleHelpers:is-transposed($node)) then
146
147
                let $corresp := //tei:metamark[matches(@target, $node/@xml:id)]
                return
148
149
                    (fontaneSimple:transform($corresp/node()),
                    fontaneSimple:transform($node/node()))
150
                    
151
            else
152
                fontaneSimple:transform($node/node())
153

154
155
        case element(tei:addSpan) return
            if($node/@type = "edited_text") then
156
                fontaneSimple:copy-element($node)
157
            else
158
159
                ()

160
161
        case element(tei:fw) return
            ()
162

163
        case element(tei:line) return
Michelle Rodzis's avatar
Michelle Rodzis committed
164
            if($node/@type = "heading") then
165
                fontaneSimple:make-head($node)
166

167
            else if(simpleHelpers:has-valid-style($node)
168
            or matches($node/@rendition, "black_letter")
169
            or matches($node/@rendition, "roman")) then
170
                fontaneSimple:make-seg-with-rendition($node)
171
172
                
            else if($node/following::*[1][self::tei:lb[@break = "no"]]) then
173
                (simpleHelpers:start-line($node),
174
                simpleHelpers:trim-last-char($node))
175
176
                
            else if ($node/preceding::*[1][self::tei:lb[@break = "no"]]) then
177
                (simpleHelpers:start-line($node),
178
                simpleHelpers:trim-first-char($node))
179
180
                
            else if($node/@type = "verse") then
MRodz's avatar
MRodz committed
181
182
183
184
185
186
187
188
189
190
191
192
193
                if(not($node/@next)) then
                    (if(not($node/preceding-sibling::tei:line[@type = "verse"])) then
                        fontaneSimple:mark-linegroup-beginning()
                    else
                        (),
                    element tei:l {
                            fontaneSimple:transform($node/node())
                        },
                    if(not($node/following-sibling::tei:line[@type = "verse"])) then
                        fontaneSimple:mark-linegroup-end()
                    else
                        ())  
                (: 3.8.2.2.1.3 Vers mit anderer Beschriftung in einer Zeile :)
194
                else
MRodz's avatar
MRodz committed
195
196
197
198
199
200
201
202
203
204
205
206
207
                    let $corresp := $node/following::tei:seg[@type = "verse" 
                        and matches($node/@next, @xml:id)]
                    return
                        (fontaneSimple:mark-linegroup-beginning(),
                        element tei:l {
                            fontaneSimple:transform($node/node()),
                            simpleHelpers:start-line($node),
                            fontaneSimple:transform($corresp/node())
                        },
                        fontaneSimple:mark-linegroup-end())
                    
            else if($node/parent::tei:zone[@type = "verse"]/child::*[1] = $node) then
                fontaneSimple:transform($node/node())             
208
                
209
210
211
            (: with opting for a tei:milestone we try to meet the project's
            requirements on the one hand while avoiding to run into hierarchical
            problems in the further processing on the other hand:)
212
            else if(not($node/@type = "item")) then
213
                (simpleHelpers:start-line($node),
214
                fontaneSimple:transform($node/node()))
215
                
MRodz's avatar
MRodz committed
216
            else if($node/@type = "item") then
217
                element tei:item {
MRodz's avatar
MRodz committed
218
                    $node/(@* except (@rend, @type, @style)),
Michelle Rodzis's avatar
Michelle Rodzis committed
219
220
221
222
                    if($node/@rend) then
                        attribute rendition {$node/@rend}
                    else
                        (),
223
                    fontaneSimple:transform($node/node())
224
                }
225
                
226
            else
227
                (simpleHelpers:start-line($node),
228
                fontaneSimple:transform($node/node()))
229

230
        case element(tei:handShift) return
231
            fontaneSimple:enhance-handshift($node)
232

233
        case element(tei:stamp) return
Michelle Rodzis's avatar
Michelle Rodzis committed
234
235
236
237
            if($node/ancestor::tei:surface[matches(@n, "Beilage")]) then
                fontaneSimple:copy-element($node)
            else
                ()
238

239
        case element(tei:seg) return
240
            if(count($node/*) = 1 and
Michelle Rodzis's avatar
Michelle Rodzis committed
241
242
243
            (($node/tei:stamp 
                and not($node/ancestor::tei:surface[matches(@n, "Beilage")]))
            or $node/tei:metamark[@function = "caret"]))
244
245
                then
                    ()
246

MRodz's avatar
MRodz committed
247
            else if($node/@type = "heading") then
MRodz's avatar
MRodz committed
248
                fontaneSimple:make-head($node)
249
250

            else if(matches($node/@style, "underline")
251
            and not(matches($node/@style, "vertical-align"))) then
252
                fontaneSimple:transform($node/node())
253

254
            else if(simpleHelpers:has-valid-style($node)
255
            or matches($node/@rendition, "black_letter")
256
            or matches($node/@rendition, "roman")) then
257
                fontaneSimple:make-seg-with-rendition($node)
258
259
260

            else if($node/@type = "initials"
            or $node/@type = "monogram"
MRodz's avatar
MRodz committed
261
262
            or $node/@type = "multiphrase"
            or $node/@xml:lang)
263
                then
264
                    fontaneSimple:copy-element($node)
265
266

            else if($node/@type = "auction_number"
267
            or $node/@type = "cancel"
MRodz's avatar
MRodz committed
268
269
            or $node/@type = "abort"
            or $node/@function ="unknown")
270
271
                then
                    ()
272
273
274
                    
            else if($node/parent::tei:add and $node/@copyOf) then
                fontaneSimple:mark-intervention($node)
MRodz's avatar
MRodz committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
                
            else if($node/@type = "verse" and $node/@prev) then
                ()
                
            else if($node/@type = "said") then
                if($node/@next) then
                    let $next := replace($node/@next, "#", "")
                    let $corresp := $node/following::*[@xml:id = $next]
                    return
                        (element tei:seg {
                            $node/@type,
                            fontaneSimple:transform($node/node()),
                            fontaneSimple:transform($corresp/node())
                        },
                        element tei:lb {
                            attribute type {"edited_text"}
                        })
                else
                    element tei:seg {
                        $node/@type,
                        fontaneSimple:transform($node/node())
                    }
297

298
            else
299
                fontaneSimple:transform($node/node())
300

MRodz's avatar
MRodz committed
301
        case element(tei:hi) return
302
            fontaneSimple:copy-element($node)
303
304

        (: TODO if $node/@type = "highlighted" then make
305
        a hi[@type = "vertical-mark"] in the second stage of creating the
306
        simple format. use simpleHelpers:get-xml-chunk($node) for this.:)
307
308
        case element(tei:mod) return
            if($node/@type = "highlighted"
309
            and simpleHelpers:is-hand-contemporary($node/@hand)) then
310
                $node
311
312
            else
                fontaneSimple:transform($node/node())
313

314
        case element(tei:anchor) return
315
            fontaneSimple:copy-element($node)
316
317

        case element(tei:surface) return
MRodz's avatar
MRodz committed
318
            if(matches($node/@n, "cover")) then
Michelle Rodzis's avatar
Michelle Rodzis committed
319
320
                (fontaneSimple:make-pb-with-type($node/@n),
                fontaneSimple:transform($node/node()))
Michelle Rodzis's avatar
Michelle Rodzis committed
321
322
323
324
325
326
327
328
329
330
331
332
333
                
            else if(matches($node/@n, "Beilage")) then
                element tei:div {
                    $node/@*,
                    fontaneSimple:transform($node/node())
                }
                
            else if($node/@type = "pocket") then
                (fontaneSimple:make-pb($node),
                element tei:div {
                    $node/(@* except (@n, @ulx, @uly, @lry, @lrx)),
                    fontaneSimple:transform($node/node())
                })
Michelle Rodzis's avatar
Michelle Rodzis committed
334
            
335
            else if(simpleHelpers:is-page($node)
MRodz's avatar
MRodz committed
336
            and $node/@type = "clipping") then
337
                (fontaneSimple:make-pb($node),
MRodz's avatar
MRodz committed
338
339
                (if(not($node/@subtype = "Kalenderblatt"
                or $node/@subtype = "Zeitungsausschnitt_Fragment")) then
Michelle Rodzis's avatar
Michelle Rodzis committed
340
341
342
343
                    element tei:div {
                        $node/(@* except (@n, @ulx, @uly, @lry, @lrx)),
                        fontaneSimple:transform($node/node())
                    }
MRodz's avatar
MRodz committed
344
345
                else
                    ()))
Michelle Rodzis's avatar
Michelle Rodzis committed
346
            
347
            else if(simpleHelpers:is-page($node)) then
348
                (fontaneSimple:make-pb($node),
349
                fontaneSimple:transform($node/node()))
Michelle Rodzis's avatar
Michelle Rodzis committed
350
            
351
            else if($node/@type = "label" and
352
            (contains($node/@subtype, "Fontane")
353
            or contains($node/@subtype, "Hersteller"))
354
            ) then
355
                fontaneSimple:make-div($node)
Michelle Rodzis's avatar
Michelle Rodzis committed
356
            
MRodz's avatar
MRodz committed
357
358
            else
                ()
359

MRodz's avatar
MRodz committed
360
361
362
363
        case element(tei:milestone) return
            if($node/@unit = "illustration") then
                ()
            else
364
                fontaneSimple:copy-element($node)
365

366
        case element(tei:gap) return
367
            fontaneSimple:copy-element($node)
368

369
        case element(tei:metamark) return
370
            if($node/@function = "integrate"
371
372
373
374
            or $node/@function = "authorial_note") then
                element tei:ab {
                    $node/@*
                }
375
            else if($node/@function = "placeholder"
376
377
            or $node/@function ="etc."
            or $node/@function ="caret"
MRodz's avatar
MRodz committed
378
            or $node/@function = "footnote-mark"
379
380
381
            or $node/@function ="footnotes"
            or $node/@function ="ellipsis"
            or $node/@function = "paragraph") then
MRodz's avatar
MRodz committed
382
383
                element tei:ab {
                    attribute type {$node/@function},
384
                    fontaneSimple:transform($node/node())
385
                }
386
387
            else
                ()
388

389
        case element(tei:surplus) return
390
            fontaneSimple:mark-intervention($node)
391

MRodz's avatar
MRodz committed
392
        case element(tei:zone) return
393
            if(matches($node/@style, "border-style:solid")
MRodz's avatar
MRodz committed
394
395
396
397
            and not(matches($node/@style, "border-radius"))
            and not($node/@rend = "border-style:house")) then
                element tei:div {
                    attribute type {"frame"},
398
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
399
                }
400

MRodz's avatar
MRodz committed
401
            else if(matches($node/@rend, "border-bottom-style:brace")) then
402
                (fontaneSimple:transform($node/node()),
MRodz's avatar
MRodz committed
403
404
                element tei:ab {
                    attribute type {"bottom-brace"}
405
406
                })

MRodz's avatar
MRodz committed
407
408
            else if($node/@type = "cancel") then
                ()
409

MRodz's avatar
MRodz committed
410
411
412
413
            else if($node/@type = "marked_off") then
                element tei:seg {
                    $node/@type,
                    $node/@xml:id,
414
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
415
                }
416

MRodz's avatar
MRodz committed
417
418
            else if($node/@type = "highlighted") then
                if($node/child::tei:zone[@type = "highlighted"]) then
419
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
420
421
422
                else
                    element tei:hi {
                        attribute type {"vertical-mark"},
423
                        fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
424
                    }
425

426
427
            else if($node/@type = "illustration"
            or $node/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
428
429
430
431
432
433
434
                if(not($node//tei:figure/parent::tei:del)) then
                    element {QName("http://www.tei-c.org/ns/1.0", "ab")}{
                        (if($node/child::tei:zone[@type = "illustration"]) then
                            attribute type {"composed-sketch"}
                        else
                            (attribute type {"sketch"},
                            if($node/parent::tei:zone[@type = "illustration"]) then
435
                                attribute rendition {"margin-left:" || $node/@ulx
MRodz's avatar
MRodz committed
436
437
438
439
440
                                || "cm; " || "margin-top:" || $node/@uly || "cm"}
                            else
                                ()
                            )
                        ),
441
                        fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
442
                    }
443
                else
MRodz's avatar
MRodz committed
444
                    ()
445

446
447
            else if($node/parent::tei:zone/@type = "illustration"
            or $node/parent::tei:zone/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
448
449
                element {QName("http://www.tei-c.org/ns/1.0", "seg")}{
                    attribute type {"caption"},
450
                    attribute rendition {"margin-left:" || $node/@ulx || "cm; "
MRodz's avatar
MRodz committed
451
                        || "margin-top:" || $node/@uly || "cm"},
452
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
453
                }
454

MRodz's avatar
MRodz committed
455
            else if($node/@type = "heading") then
456
                fontaneSimple:make-head($node)
457

MRodz's avatar
MRodz committed
458
            else if($node/@type = "list" or $node/@type = "item") then
459
                element {QName("http://www.tei-c.org/ns/1.0", $node/@type)} {
Michelle Rodzis's avatar
Michelle Rodzis committed
460
461
462
463
464
                    $node/(@xml:id, @subtype, @rendition, @prev, @next),
                    if($node/@rend) then
                        attribute rendition {$node/@rend}
                    else
                        (),                    
465
                    fontaneSimple:transform($node/node())
466
                }
Michelle Rodzis's avatar
Michelle Rodzis committed
467
                
MRodz's avatar
MRodz committed
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
            else if($node/@type = "dialogue") then
                element tei:div {
                    $node/@type,
                    fontaneSimple:transform($node/node())
                }
                
            else if($node/@type = "verse") then
                (fontaneSimple:mark-linegroup-beginning(),
                element tei:l {
                    fontaneSimple:transform($node/node())
                },
                fontaneSimple:mark-linegroup-end())
                
            else if($node/@type = "said" and $node/@prev) then
                ()
                
            else if($node/@type = "said") then
                element tei:seg {
                    $node/@type,
                    fontaneSimple:transform($node/node())
                }
                
MRodz's avatar
MRodz committed
490
491
492
493
            else if($node/@type = "toc" 
            and matches($node/@subtype, "ungültig")) then
                ()
                
Michelle Rodzis's avatar
Michelle Rodzis committed
494
495
            else if($node/@type = "toc") then
                element tei:list {
496
                    $node/(@type, @subtype),
Michelle Rodzis's avatar
Michelle Rodzis committed
497
498
                    fontaneSimple:transform($node/node())
                }
499

MRodz's avatar
MRodz committed
500
501
            else if($node/@type = "legend") then
                element {QName("http://www.tei-c.org/ns/1.0", "div")}{
502
                    (if($node/@style
503
504
505
506
507
                    or $node/@rendition) then
                        attribute rendition {simpleHelpers:filter-rendition($node)}
                    else
                        ()),
                    $node/(@* except (@rendition, @style)),
508
                    fontaneSimple:transform($node/node())
509
                }
Michelle Rodzis's avatar
Michelle Rodzis committed
510
511
512
513
514
515
                
            else if($node/@type = "additional") then
                element tei:ab {
                    $node/(@* except (@ulx, @uly, @lry, @lrx)),
                    fontaneSimple:transform($node/node())
                }
516

517
            else if(simpleHelpers:has-valid-style($node)
518
            or matches($node/@rendition, "black_letter")
519
            or matches($node/@rendition, "script")
520
            or matches($node/@rendition, "roman")) then
521
                fontaneSimple:make-seg-with-rendition($node)
522

523
            else if(not($node/@xml:id)) then
524
                fontaneSimple:transform($node/node())
525

526
527
528
529
530
531
532
533
            else if($node/@xml:id) then
                element tei:seg {
                    $node/@xml:id,
                    $node/@prev,
                    $node/@next,
                    $node/@corresp,
                    fontaneSimple:transform($node/node())
                }
534

MRodz's avatar
MRodz committed
535
            else
536
                fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
537
538
539
540
541
542
543
544
545
546
547
548
                
        case element(tei:said) return
            (element tei:seg {
                attribute type {"said"},
                fontaneSimple:transform($node/node())
            },
            if($node/ancestor::tei:zone[@type = "dialogue"]/descendant::tei:said[position() != last()] = $node) then
                element tei:lb {
                        attribute type {"edited_text"}
                }
            else
                ())
549

MRodz's avatar
MRodz committed
550
        case element(tei:figure) return
551
            if(count($node/child::*) = 1 and $node/child::tei:figDesc) then
552
                (: genealogy lines probably shouldn't be displayed, but I still have to
553
554
555
556
                check that. in case they should be serialized, I leave the code :)
(:                if(matches($node/descendant::tei:ref, "Stammbaumverbindungslinie")) then:)
(:                    element tei:seg {:)
(:                        $node/@*,:)
557
(:                        fontaneSimple:transform($node/node()):)
558
559
560
561
562
563
(:                    }:)
(:                else if(matches($node/descendant::tei:ref, "Schlusslinie")):)
                if(matches($node/descendant::tei:ref, "Schlusslinie"))
                    then
                        element tei:ab {
                            switch ($node/descendant::tei:ref)
564
565
566
                                case "horizontale einfache Schlusslinie" return
                                    attribute type {"long-end-line"}
                                case "Schlusslinie; horizontale Halbschleife von links oben nach rechts" return
567
                                    attribute type {"long-end-line"}
568
                                case "horizontale einfache Schlusslinie (gewellt)" return
569
                                    attribute type {"long-end-line-wavy"}
570
                                case "Schlusslinien; horizontale Schleife von links oben nach rechts unten" return
571
                                    attribute type {"bottom-brace-short"}
572
573
                                default return
                                    attribute type {"end-line"}
574
575
                        }
                else if(matches($node/descendant::tei:ref, "Absatzlinie")
576
577
                (: in case of double paragraph lines the single lines are
                encoded with "oberer" resp. "unterer Teil", but we only
578
579
580
581
582
583
584
585
586
587
                serialize the encoding for the upper line :)
                and not(matches($node/descendant::tei:ref, "unterer Teil"))
                and not(matches($node/descendant::tei:figDesc, "unsicher"))) then
                    element tei:ab {
                        if(matches($node/descendant::tei:ref, "doppelt"))
                            then
                                attribute type {"short-paragraph-line-double"}
                            else
                                attribute type {"short-paragraph-line"}
                    }
MRodz's avatar
MRodz committed
588
                else if($node/ancestor::tei:zone[@type = "illustration"]) then
MRodz's avatar
MRodz committed
589
                    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
Michelle Rodzis's avatar
Michelle Rodzis committed
590
591
                        $node/@*,
                        fontaneSimple:transform($nodes/node())
MRodz's avatar
MRodz committed
592
                    }
593
                else
MRodz's avatar
MRodz committed
594
595
                    ()
            else
596
                fontaneSimple:copy-element($node)
597

MRodz's avatar
MRodz committed
598
        case element(tei:note) return
599
            if($node/@type = "authorial"
600
            and not($node/@subtype = "footnote")) then
MRodz's avatar
MRodz committed
601
                ()
602
            else
603
                fontaneSimple:copy-element($node)
604

MRodz's avatar
MRodz committed
605
606
607
608
609
610
        case element(tei:certainty) return
            element {QName("http://www.tei-c.org/ns/1.0", "note")}{
                attribute type {"editorial"},
                attribute subtype {"certainty"},
                $node/@cert,
                $node/@target,
611
                fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
612
            }
613

MRodz's avatar
MRodz committed
614
        case element(tei:figDesc) return
615
            fontaneSimple:copy-element($node)
616

MRodz's avatar
MRodz committed
617
        case element(tei:ref) return
618
            fontaneSimple:copy-element($node)
619

MRodz's avatar
MRodz committed
620
        case element(tei:space) return
621
            fontaneSimple:copy-element($node)
622

MRodz's avatar
MRodz committed
623
        case element(tei:choice) return
624
            fontaneSimple:copy-element($node)
625

MRodz's avatar
MRodz committed
626
        case element(tei:abbr) return
627
            fontaneSimple:copy-element($node)
628

MRodz's avatar
MRodz committed
629
        case element(tei:expan) return
630
            fontaneSimple:copy-element($node)
631
632
633
634
635
636
            
        case element(tei:sic) return
            fontaneSimple:copy-element($node)     
            
        case element(tei:corr) return
            fontaneSimple:copy-element($node)
637

MRodz's avatar
MRodz committed
638
        case element(tei:rs) return
639
            fontaneSimple:copy-element($node)
640

MRodz's avatar
MRodz committed
641
        case element(tei:date) return
642
            element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
643
644
                (if($node/@when-iso) then
                    attribute when {$node/@when-iso}
645
646
                else
                    ()),
647
648
                (if($node/@from-iso) then
                    attribute from {$node/@from-iso}
649
650
                else
                    ()),
651
652
                (if($node/@to-iso) then
                    attribute to {$node/@to-iso}
Michelle Rodzis's avatar
Michelle Rodzis committed
653
                else
654
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
655
656
                (if($node/@notAfter-iso) then
                    attribute notAfter {$node/@notAfter-iso}
657
                else
658
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
659
                $node/(@* except (@when-iso, @to-iso, @from-iso, @notAfter-iso)),
660
                fontaneSimple:transform($node/node())
661
            }
662

663
        case element(tei:ptr) return
664
            ()
665

MRodz's avatar
MRodz committed
666
        default return
667
            fontaneSimple:transform($node/node())
668
};
669
670
671
672
673
674
675
676
677
678

(:~
 : Takes a given element over as is since it is compliant to TEI simplePrint.
 :
 : @author Michelle Rodzis
 : @param $node the current text node
 : @return node() a copy of the current node
 :)
declare function fontaneSimple:copy-element($node as node()) as node() {
    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
Michelle Rodzis's avatar
Michelle Rodzis committed
679
680
681
682
683
        $node/(@* except @rend),
        if($node/@rend) then
            attribute rendition {$node/@rend}
        else
            (),
684
685
686
687
688
689
690
691
692
693
694
695
696
697
        fontaneSimple:transform($node/node())
    }
};

(:~
 : Creates a tei:head with an @rendition and a font-size, if available.
 :
 : @author Michelle Rodzis
 : @param $node the current tei:line, tei:zone or tei:seg node
 : @return element(tei:head)
 : :)
declare function fontaneSimple:make-head($node as node()) as element(tei:head) {
    element tei:head {
        (if($node/descendant::tei:seg[matches(@style, "font-size")]) then
MRodz's avatar
MRodz committed
698
            attribute style {simpleHelpers:get-font-size($node)}
699
        else
MRodz's avatar
MRodz committed
700
            attribute style {"default"}
701
        ),
MRodz's avatar
MRodz committed
702
        attribute type {"former-" || $node/name()},
703
704
705
706
        $node/@subtype,
        (if($node/@rendition) then
            $node/@rendition
        else
MRodz's avatar
MRodz committed
707
708
709
710
711
            ()),         
        (if($node/@rend) then
            $node/@rend
        else
            ()),        
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
        fontaneSimple:transform($node/node())
    }
};

(:~
 : Creates a tei:div.
 :
 : @author Michelle Rodzis
 : @param $node the current tei:surface node
 : @return element(tei:div)
 : :)
declare function fontaneSimple:make-div($node as element(tei:surface))
as element(tei:div) {
    element tei:div{
        $node/(@* except (@facs, @n, @attachment, @subtype, @ulx, @uly, @lrx, @lry, @points)),
        fontaneSimple:transform($node/node())
    }
};

(:~
 : Creates a new tei:seg with all relevant rendition information.
 :
 : @author Michelle Rodzis
 : @param $node the current tei:zone, tei:line, or tei:seg element
 : @return element(tei:seg)
 :)
declare function fontaneSimple:make-seg-with-rendition($node as element(*))
as element(tei:seg) {
    element tei:seg {
        attribute rendition {simpleHelpers:filter-rendition($node)},
        $node/(@* except (@style, @rendition)),
743
744
745
746
        (if($node[self::tei:line or self::tei:zone]) then
            attribute unit {$node/name()}
        else
            ()),
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
        fontaneSimple:transform($node/node())
    }
};


(:~
 : Creates a tei:pb.
 :
 : @author Michelle Rodzis
 : @param $node the current tei:surface node
 : @return element(tei:pb)
 :)
declare function fontaneSimple:make-pb($node as element(tei:surface))
as element(tei:pb) {
    element {QName("http://www.tei-c.org/ns/1.0", "pb")}{
        $node/@n
    }
};


(:~
 : Creates a tei:pb with a type instead of a @n representing the pagination.
 : This function is mainly used to separate the inner and outer book covers from
 : each other.
 :
 : @author Michelle Rodzis
 : @param $node the current tei:surface node
 : @return element(tei:pb)
 :)
declare function fontaneSimple:make-pb-with-type($type as xs:string)
as element(tei:pb) {
    element {QName("http://www.tei-c.org/ns/1.0", "pb")}{
        attribute type {$type}
    }
};

declare function fontaneSimple:enhance-handshift($node as element(tei:handShift))
as element(tei:handShift) {
    let $prev-hand := $node/preceding::tei:handShift[@new][1]
    return
        element tei:handShift {
            $node/@*,
            if(not($node/@new)) then
                attribute new {$prev-hand/@new}
            else
                (),
            if(not($node/@script)) then
                attribute script {""}
            else
                (),
            if(not($node/@medium)) then
                attribute medium {""}
            else
                ()
        }
};
803
804


805
declare function fontaneSimple:mark-intervention($node as element(*)) 
806
807
as element(tei:seg) {
    element tei:seg {
808
809
810
811
812
813
        if($node[self::tei:lb]) then
            attribute type {"missing-hyphen"}
        else if($node[self::tei:surplus]) then
            attribute type {"surplus"}
        else
            attribute type {"reduplication"},
814
            
815
        <tei:hi xmlns="http://www.tei-c.org/ns/1.0">‹</tei:hi>,
816
        
817
818
819
820
        if($node[self::tei:lb]) then
            simpleHelpers:find-chars($node)
        else
            fontaneSimple:transform($node/node()),
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
846
847
848
849
850
851
        <tei:hi xmlns="http://www.tei-c.org/ns/1.0">›</tei:hi>
    }
};


declare function fontaneSimple:mark-missing-hyphen($node as element(tei:lb)) as
element(tei:seg) {
    element tei:seg {
        attribute type {"missing-hyphen"},
        <tei:hi xmlns="http://www.tei-c.org/ns/1.0">‹</tei:hi>,
        simpleHelpers:find-chars($node),
        <tei:hi xmlns="http://www.tei-c.org/ns/1.0">›</tei:hi>
    }
};


(:~ In this first serialization step the beginning and end of line groups are 
 : simply marked with milestones, which are expanded to a full tei:lg in the 
 : second serialization step. :)
declare function fontaneSimple:mark-linegroup-beginning() as
element(tei:milestone) {
    element tei:milestone {
        attribute unit {"start-lg"}
    }
};

declare function fontaneSimple:mark-linegroup-end() as
element(tei:milestone) {
    element tei:milestone {
        attribute unit {"end-lg"}
852
    }
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
};

declare function fontaneSimple:has-pb-inbetween($node as node(), 
$corresp as node()*) as xs:boolean {
    if($node/following::tei:surface[. << $corresp]) then
        true()
    else
        false()
};

declare function fontaneSimple:separates-corresp-nodes($node as element(tei:surface)) 
as xs:boolean {
    some $prev in $node/preceding::*[@next]
    satisfies contains($prev/@next, $node/descendant::*/@xml:id)
        or contains($prev/@next, $node/following::*/@xml:id)
868
};