tei2teisimple.xqm 39.1 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
 : @author Michelle Weidling
MRodz's avatar
MRodz committed
10
 : @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

MRodz's avatar
MRodz committed
16
declare namespace svg="http://www.w3.org/2000/svg";
MRodz's avatar
MRodz committed
17
declare namespace tei="http://www.tei-c.org/ns/1.0";
MRodz's avatar
MRodz committed
18
declare namespace test="http://exist-db.org/xquery/xqsuite";
MRodz's avatar
MRodz committed
19
declare namespace xlink="http://www.w3.org/1999/xlink";
MRodz's avatar
MRodz committed
20
21

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

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

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

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

57
(:~
58
59
60
61
62
63
64
65
66
 : 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
67
 : @author Michelle Weidling
68
 : @param $nodes the elements of the book covers and the book content
Michelle Rodzis's avatar
Michelle Rodzis committed
69
 : @return $node()* a TEI simplePrint element
MRodz's avatar
MRodz committed
70
 :)
71
declare function fontaneSimple:transform($nodes as node()*) as node()* {
MRodz's avatar
MRodz committed
72
73
74
    for $node in $nodes
      return
        typeswitch ($node)
MRodz's avatar
MRodz committed
75
        case text() return
MRodz's avatar
MRodz committed
76
77
78
79
            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
80
81
82
83
84
                if($node/parent::tei:rs and starts-with($node, " ")
                and not($node/preceding-sibling::*[1][self::tei:handShift])) then
                    simpleHelpers:prepare-text(text{substring-after($node, " ")})
                else
                    simpleHelpers:prepare-text($node)
MRodz's avatar
MRodz committed
85
86
            else
                ()
87

MRodz's avatar
MRodz committed
88
89
90
        case element(tei:lb) return
            if($node[@break = "keepHyphen"]) then
                ()
91
92
            else if($node[@break = "no"]) then
                fontaneSimple:mark-intervention($node)
MRodz's avatar
MRodz committed
93
            else
94
                fontaneSimple:copy-element($node)
95

MRodz's avatar
MRodz committed
96
97
98
99
        case element(tei:g) return
            if($node[@ref = "#vds"]) then
                ()
            else if($node/@ref ="#rth" or $node/@ref ="#hb") then
100
                fontaneSimple:copy-element($node)
MRodz's avatar
MRodz committed
101
            else
102
                fontaneSimple:transform($node/node())
103

MRodz's avatar
MRodz committed
104
105
        case element(tei:del) return
            if($node/parent::tei:restore) then
106
                fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
107
            else if($node/descendant::tei:restore) then
108
                fontaneSimple:transform($node/descendant::tei:restore)
MRodz's avatar
MRodz committed
109
            else
MRodz's avatar
MRodz committed
110
                ()
111

MRodz's avatar
MRodz committed
112
113
114
115
116
        case element(tei:restore) return
            if(count($node/child::*) = 1 and $node/child::tei:del
            and $node/ancestor::tei:del) then
                ()
            else
117
                fontaneSimple:transform($node/node())
118

MRodz's avatar
MRodz committed
119
120
        case element(tei:retrace) return
            if($node/@rend) then
MRodz's avatar
MRodz committed
121
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
122
                    attribute rendition {$node/@rend},
123
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
124
125
                }
            else
126
                fontaneSimple:transform($node/node())
127

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

163
164
        case element(tei:addSpan) return
            if($node/@type = "edited_text") then
165
                fontaneSimple:copy-element($node)
166
            else
167
168
                ()

169
170
        case element(tei:fw) return
            ()
171

172
        case element(tei:line) return
Michelle Rodzis's avatar
Michelle Rodzis committed
173
            if($node/@type = "heading") then
174
                fontaneSimple:make-head($node)
175

176
            else if(simpleHelpers:has-valid-style($node)
177
            or matches($node/@rendition, "black_letter")
178
            or matches($node/@rendition, "roman")) then
179
                fontaneSimple:make-seg-with-rendition($node)
180
181
                
            else if($node/following::*[1][self::tei:lb[@break = "no"]]) then
182
                (simpleHelpers:start-line($node),
183
                simpleHelpers:trim-last-char($node))
184
185
                
            else if ($node/preceding::*[1][self::tei:lb[@break = "no"]]) then
186
                (simpleHelpers:start-line($node),
187
                simpleHelpers:trim-first-char($node))
188
189
                
            else if($node/@type = "verse") then
MRodz's avatar
MRodz committed
190
191
192
193
194
                if(not($node/@next)) then
                    (if(not($node/preceding-sibling::tei:line[@type = "verse"])) then
                        fontaneSimple:mark-linegroup-beginning()
                    else
                        (),
MRodz's avatar
MRodz committed
195
                    element {QName("http://www.tei-c.org/ns/1.0", "l")} {
MRodz's avatar
MRodz committed
196
197
198
199
200
201
202
                            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 :)
203
                else
MRodz's avatar
MRodz committed
204
205
206
207
                    let $corresp := $node/following::tei:seg[@type = "verse" 
                        and matches($node/@next, @xml:id)]
                    return
                        (fontaneSimple:mark-linegroup-beginning(),
MRodz's avatar
MRodz committed
208
                        element {QName("http://www.tei-c.org/ns/1.0", "l")} {
MRodz's avatar
MRodz committed
209
210
211
212
213
214
215
216
                            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())             
217
                
218
219
220
            (: 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:)
221
            else if(not($node/@type = "item")) then
222
                (simpleHelpers:start-line($node),
223
                fontaneSimple:transform($node/node()))
224
                
MRodz's avatar
MRodz committed
225
            else if($node/@type = "item") then
MRodz's avatar
MRodz committed
226
                element {QName("http://www.tei-c.org/ns/1.0", "item")} {
MRodz's avatar
MRodz committed
227
                    $node/(@* except (@rend, @type, @style)),
Michelle Rodzis's avatar
Michelle Rodzis committed
228
229
230
231
                    if($node/@rend) then
                        attribute rendition {$node/@rend}
                    else
                        (),
232
                    fontaneSimple:transform($node/node())
233
                }
234
                
235
            else
236
                (simpleHelpers:start-line($node),
237
                fontaneSimple:transform($node/node()))
238

239
        case element(tei:handShift) return
240
            fontaneSimple:enhance-handshift($node)
241

242
        case element(tei:stamp) return
Michelle Rodzis's avatar
Michelle Rodzis committed
243
244
245
246
            if($node/ancestor::tei:surface[matches(@n, "Beilage")]) then
                fontaneSimple:copy-element($node)
            else
                ()
247

248
        case element(tei:seg) return
249
            if(count($node/*) = 1 and
Michelle Rodzis's avatar
Michelle Rodzis committed
250
251
252
            (($node/tei:stamp 
                and not($node/ancestor::tei:surface[matches(@n, "Beilage")]))
            or $node/tei:metamark[@function = "caret"]))
253
254
                then
                    ()
255

MRodz's avatar
MRodz committed
256
            else if($node/@type = "heading") then
MRodz's avatar
MRodz committed
257
                fontaneSimple:make-head($node)
258
259

            else if(matches($node/@style, "underline")
260
            and not(matches($node/@style, "vertical-align"))) then
261
                fontaneSimple:transform($node/node())
262

263
            else if(simpleHelpers:has-valid-style($node)
264
            or matches($node/@rendition, "black_letter")
265
            or matches($node/@rendition, "roman")) then
266
                fontaneSimple:make-seg-with-rendition($node)
267
268
269

            else if($node/@type = "initials"
            or $node/@type = "monogram"
MRodz's avatar
MRodz committed
270
271
            or $node/@type = "multiphrase"
            or $node/@xml:lang)
272
                then
273
                    fontaneSimple:copy-element($node)
274
275

            else if($node/@type = "auction_number"
276
            or $node/@type = "cancel"
MRodz's avatar
MRodz committed
277
278
            or $node/@type = "abort"
            or $node/@function ="unknown")
279
280
                then
                    ()
281
282
283
                    
            else if($node/parent::tei:add and $node/@copyOf) then
                fontaneSimple:mark-intervention($node)
MRodz's avatar
MRodz committed
284
285
286
287
288
289
290
291
292
                
            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
MRodz's avatar
MRodz committed
293
                        (element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
294
295
296
297
                            $node/@type,
                            fontaneSimple:transform($node/node()),
                            fontaneSimple:transform($corresp/node())
                        },
MRodz's avatar
MRodz committed
298
                        element {QName("http://www.tei-c.org/ns/1.0", "lb")} {
MRodz's avatar
MRodz committed
299
300
301
                            attribute type {"edited_text"}
                        })
                else
MRodz's avatar
MRodz committed
302
                    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
303
304
305
                        $node/@type,
                        fontaneSimple:transform($node/node())
                    }
306

307
            else
308
                fontaneSimple:transform($node/node())
309

MRodz's avatar
MRodz committed
310
        case element(tei:hi) return
311
            fontaneSimple:copy-element($node)
312
313

        (: TODO if $node/@type = "highlighted" then make
314
        a hi[@type = "vertical-mark"] in the second stage of creating the
315
        simple format. use simpleHelpers:get-xml-chunk($node) for this.:)
316
317
        case element(tei:mod) return
            if($node/@type = "highlighted"
318
            and simpleHelpers:is-hand-contemporary($node/@hand)) then
319
                $node
320
321
            else
                fontaneSimple:transform($node/node())
322

323
        case element(tei:anchor) return
324
            fontaneSimple:copy-element($node)
325
326

        case element(tei:surface) return
MRodz's avatar
MRodz committed
327
            if(matches($node/@n, "cover")) then
Michelle Rodzis's avatar
Michelle Rodzis committed
328
329
                (fontaneSimple:make-pb-with-type($node/@n),
                fontaneSimple:transform($node/node()))
Michelle Rodzis's avatar
Michelle Rodzis committed
330
331
                
            else if(matches($node/@n, "Beilage")) then
MRodz's avatar
MRodz committed
332
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
333
334
335
336
337
338
                    $node/@*,
                    fontaneSimple:transform($node/node())
                }
                
            else if($node/@type = "pocket") then
                (fontaneSimple:make-pb($node),
MRodz's avatar
MRodz committed
339
                element {QName("http://www.tei-c.org/ns/1.0", "div")}{
Michelle Rodzis's avatar
Michelle Rodzis committed
340
341
342
                    $node/(@* except (@n, @ulx, @uly, @lry, @lrx)),
                    fontaneSimple:transform($node/node())
                })
Michelle Rodzis's avatar
Michelle Rodzis committed
343
            
344
            else if(simpleHelpers:is-page($node)
MRodz's avatar
MRodz committed
345
            and $node/@type = "clipping") then
346
                (fontaneSimple:make-pb($node),
MRodz's avatar
MRodz committed
347
348
                (if(not($node/@subtype = "Kalenderblatt"
                or $node/@subtype = "Zeitungsausschnitt_Fragment")) then
MRodz's avatar
MRodz committed
349
                    element {QName("http://www.tei-c.org/ns/1.0", "div")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
350
351
352
                        $node/(@* except (@n, @ulx, @uly, @lry, @lrx)),
                        fontaneSimple:transform($node/node())
                    }
MRodz's avatar
MRodz committed
353
354
                else
                    ()))
Michelle Rodzis's avatar
Michelle Rodzis committed
355
            
356
            else if(simpleHelpers:is-page($node)) then
357
                (fontaneSimple:make-pb($node),
358
                fontaneSimple:transform($node/node()))
Michelle Rodzis's avatar
Michelle Rodzis committed
359
            
360
            else if($node/@type = "label" and
361
            (contains($node/@subtype, "Fontane")
362
            or contains($node/@subtype, "Hersteller"))
363
            ) then
364
                fontaneSimple:make-div($node)
Michelle Rodzis's avatar
Michelle Rodzis committed
365
            
MRodz's avatar
MRodz committed
366
367
            else
                ()
368

MRodz's avatar
MRodz committed
369
370
371
372
        case element(tei:milestone) return
            if($node/@unit = "illustration") then
                ()
            else
373
                fontaneSimple:copy-element($node)
374

375
        case element(tei:gap) return
376
            fontaneSimple:copy-element($node)
377

378
        case element(tei:metamark) return
379
            if($node/@function = "integrate"
380
            or $node/@function = "authorial_note") then
MRodz's avatar
MRodz committed
381
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
382
383
                    $node/@*
                }
384
            else if($node/@function = "placeholder"
385
386
            or $node/@function ="etc."
            or $node/@function ="caret"
MRodz's avatar
MRodz committed
387
            or $node/@function = "footnote-mark"
388
389
390
            or $node/@function ="footnotes"
            or $node/@function ="ellipsis"
            or $node/@function = "paragraph") then
MRodz's avatar
MRodz committed
391
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
MRodz's avatar
MRodz committed
392
                    attribute type {$node/@function},
393
                    fontaneSimple:transform($node/node())
394
                }
395
396
            else
                ()
397

398
        case element(tei:surplus) return
399
            fontaneSimple:mark-intervention($node)
400

MRodz's avatar
MRodz committed
401
        case element(tei:zone) return
402
            if(matches($node/@style, "border-style:solid")
MRodz's avatar
MRodz committed
403
404
            and not(matches($node/@style, "border-radius"))
            and not($node/@rend = "border-style:house")) then
MRodz's avatar
MRodz committed
405
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
MRodz's avatar
MRodz committed
406
                    attribute type {"frame"},
407
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
408
                }
409

MRodz's avatar
MRodz committed
410
            else if(matches($node/@rend, "border-bottom-style:brace")) then
411
                (fontaneSimple:transform($node/node()),
MRodz's avatar
MRodz committed
412
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
MRodz's avatar
MRodz committed
413
                    attribute type {"bottom-brace"}
414
415
                })

MRodz's avatar
MRodz committed
416
417
            else if($node/@type = "cancel") then
                ()
418

MRodz's avatar
MRodz committed
419
            else if($node/@type = "marked_off") then
MRodz's avatar
MRodz committed
420
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
421
422
                    $node/@type,
                    $node/@xml:id,
423
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
424
                }
425

MRodz's avatar
MRodz committed
426
427
            else if($node/@type = "highlighted") then
                if($node/child::tei:zone[@type = "highlighted"]) then
428
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
429
                else
MRodz's avatar
MRodz committed
430
                    element {QName("http://www.tei-c.org/ns/1.0", "hi")} {
MRodz's avatar
MRodz committed
431
                        attribute type {"vertical-mark"},
432
                        fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
433
                    }
434

435
436
            else if($node/@type = "illustration"
            or $node/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
437
                if(not($node//tei:figure/parent::tei:del)) then
MRodz's avatar
MRodz committed
438
                    element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
MRodz's avatar
MRodz committed
439
440
441
442
443
                        (if($node/child::tei:zone[@type = "illustration"]) then
                            attribute type {"composed-sketch"}
                        else
                            (attribute type {"sketch"},
                            if($node/parent::tei:zone[@type = "illustration"]) then
444
                                attribute rendition {"margin-left:" || $node/@ulx
MRodz's avatar
MRodz committed
445
446
447
448
449
                                || "cm; " || "margin-top:" || $node/@uly || "cm"}
                            else
                                ()
                            )
                        ),
450
                        fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
451
                    }
452
                else
MRodz's avatar
MRodz committed
453
                    ()
454

455
456
            else if($node/parent::tei:zone/@type = "illustration"
            or $node/parent::tei:zone/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
457
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
458
                    attribute type {"caption"},
459
                    attribute rendition {"margin-left:" || $node/@ulx || "cm; "
MRodz's avatar
MRodz committed
460
                        || "margin-top:" || $node/@uly || "cm"},
461
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
462
                }
463

MRodz's avatar
MRodz committed
464
            else if($node/@type = "heading") then
465
                fontaneSimple:make-head($node)
466

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

MRodz's avatar
MRodz committed
510
            else if($node/@type = "legend") then
MRodz's avatar
MRodz committed
511
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
512
                    (if($node/@style
513
514
515
516
517
                    or $node/@rendition) then
                        attribute rendition {simpleHelpers:filter-rendition($node)}
                    else
                        ()),
                    $node/(@* except (@rendition, @style)),
518
                    fontaneSimple:transform($node/node())
519
                }
Michelle Rodzis's avatar
Michelle Rodzis committed
520
521
                
            else if($node/@type = "additional") then
MRodz's avatar
MRodz committed
522
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
523
524
525
                    $node/(@* except (@ulx, @uly, @lry, @lrx)),
                    fontaneSimple:transform($node/node())
                }
526

527
            else if(simpleHelpers:has-valid-style($node)
528
            or matches($node/@rendition, "black_letter")
529
            or matches($node/@rendition, "script")
530
            or matches($node/@rendition, "roman")) then
531
                fontaneSimple:make-seg-with-rendition($node)
532

533
            else if(not($node/@xml:id)) then
534
                fontaneSimple:transform($node/node())
535

536
            else if($node/@xml:id) then
MRodz's avatar
MRodz committed
537
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
538
539
540
541
542
543
                    $node/@xml:id,
                    $node/@prev,
                    $node/@next,
                    $node/@corresp,
                    fontaneSimple:transform($node/node())
                }
544

MRodz's avatar
MRodz committed
545
            else
546
                fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
547
548
                
        case element(tei:said) return
MRodz's avatar
MRodz committed
549
            (element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
550
551
552
553
                attribute type {"said"},
                fontaneSimple:transform($node/node())
            },
            if($node/ancestor::tei:zone[@type = "dialogue"]/descendant::tei:said[position() != last()] = $node) then
MRodz's avatar
MRodz committed
554
                element {QName("http://www.tei-c.org/ns/1.0", "lb")} {
MRodz's avatar
MRodz committed
555
556
557
558
                        attribute type {"edited_text"}
                }
            else
                ())
559

MRodz's avatar
MRodz committed
560
        case element(tei:figure) return
561
            if(count($node/child::*) = 1 and $node/child::tei:figDesc) then
562
                (: genealogy lines probably shouldn't be displayed, but I still have to
563
564
                check that. in case they should be serialized, I leave the code :)
(:                if(matches($node/descendant::tei:ref, "Stammbaumverbindungslinie")) then:)
MRodz's avatar
MRodz committed
565
(:                    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {:)
566
(:                        $node/@*,:)
567
(:                        fontaneSimple:transform($node/node()):)
568
569
570
571
(:                    }:)
(:                else if(matches($node/descendant::tei:ref, "Schlusslinie")):)
                if(matches($node/descendant::tei:ref, "Schlusslinie"))
                    then
MRodz's avatar
MRodz committed
572
                        element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
573
                            switch ($node/descendant::tei:ref)
574
575
576
                                case "horizontale einfache Schlusslinie" return
                                    attribute type {"long-end-line"}
                                case "Schlusslinie; horizontale Halbschleife von links oben nach rechts" return
577
                                    attribute type {"long-end-line"}
578
                                case "horizontale einfache Schlusslinie (gewellt)" return
579
                                    attribute type {"long-end-line-wavy"}
580
                                case "Schlusslinien; horizontale Schleife von links oben nach rechts unten" return
581
                                    attribute type {"bottom-brace-short"}
582
583
                                default return
                                    attribute type {"end-line"}
584
585
                        }
                else if(matches($node/descendant::tei:ref, "Absatzlinie")
586
587
                (: in case of double paragraph lines the single lines are
                encoded with "oberer" resp. "unterer Teil", but we only
588
589
590
                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
MRodz's avatar
MRodz committed
591
                    element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
592
593
594
595
596
597
                        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
598
                else if($node/ancestor::tei:zone[@type = "illustration"]) then
MRodz's avatar
MRodz committed
599
                    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
Michelle Rodzis's avatar
Michelle Rodzis committed
600
                        $node/@*,
MRodz's avatar
MRodz committed
601
602
                        (: TODO: generalize :)
                        attribute href {fontaneSimple:make-link-to-sketch("16b00", $node/@xml:id)},
603
                        attribute height-in-mm {fontaneSimple:get-height-in-mm("16b00", $node/@xml:id)},
Michelle Rodzis's avatar
Michelle Rodzis committed
604
                        fontaneSimple:transform($nodes/node())
MRodz's avatar
MRodz committed
605
                    }
606
                else
MRodz's avatar
MRodz committed
607
608
                    ()
            else
609
                fontaneSimple:copy-element($node)
610

MRodz's avatar
MRodz committed
611
        case element(tei:note) return
612
            if($node/@type = "authorial"
613
            and not($node/@subtype = "footnote")) then
MRodz's avatar
MRodz committed
614
                ()
615
            else
616
                fontaneSimple:copy-element($node)
617

MRodz's avatar
MRodz committed
618
        case element(tei:certainty) return
MRodz's avatar
MRodz committed
619
            element {QName("http://www.tei-c.org/ns/1.0", "note")} {
MRodz's avatar
MRodz committed
620
621
622
623
                attribute type {"editorial"},
                attribute subtype {"certainty"},
                $node/@cert,
                $node/@target,
624
                fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
625
            }
626

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

MRodz's avatar
MRodz committed
630
        case element(tei:ref) return
631
            fontaneSimple:copy-element($node)
632

MRodz's avatar
MRodz committed
633
        case element(tei:space) return
634
            fontaneSimple:copy-element($node)
635

MRodz's avatar
MRodz committed
636
        case element(tei:choice) return
637
            fontaneSimple:copy-element($node)
638

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

MRodz's avatar
MRodz committed
642
        case element(tei:expan) return
643
            fontaneSimple:copy-element($node)
644
645
646
647
648
649
            
        case element(tei:sic) return
            fontaneSimple:copy-element($node)     
            
        case element(tei:corr) return
            fontaneSimple:copy-element($node)
650

MRodz's avatar
MRodz committed
651
        case element(tei:rs) return
MRodz's avatar
MRodz committed
652
653
            let $index-type := substring-before($node/@ref, ":")
            return
654
                (element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
MRodz's avatar
MRodz committed
655
                    $node/@*,
MRodz's avatar
MRodz committed
656
                    fontaneSimple:make-index-infos($node, $index-type),
MRodz's avatar
MRodz committed
657
                    fontaneSimple:transform($node/node())
658
659
                },
                text{" "})
660

MRodz's avatar
MRodz committed
661
        case element(tei:date) return
MRodz's avatar
MRodz committed
662
            element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
663
664
                (if($node/@when-iso) then
                    attribute when {$node/@when-iso}
665
666
                else
                    ()),
667
668
                (if($node/@from-iso) then
                    attribute from {$node/@from-iso}
669
670
                else
                    ()),
671
672
                (if($node/@to-iso) then
                    attribute to {$node/@to-iso}
Michelle Rodzis's avatar
Michelle Rodzis committed
673
                else
674
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
675
676
                (if($node/@notAfter-iso) then
                    attribute notAfter {$node/@notAfter-iso}
677
                else
678
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
679
                $node/(@* except (@when-iso, @to-iso, @from-iso, @notAfter-iso)),
680
                fontaneSimple:transform($node/node())
681
            }
682

683
        case element(tei:ptr) return
684
            ()
685

MRodz's avatar
MRodz committed
686
        default return
687
            fontaneSimple:transform($node/node())
688
};
689
690
691
692

(:~
 : Takes a given element over as is since it is compliant to TEI simplePrint.
 :
MRodz's avatar
MRodz committed
693
 : @author Michelle Weidling
694
695
696
697
698
 : @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
699
700
701
702
703
        $node/(@* except @rend),
        if($node/@rend) then
            attribute rendition {$node/@rend}
        else
            (),
704
705
706
707
708
709
710
        fontaneSimple:transform($node/node())
    }
};

(:~
 : Creates a tei:head with an @rendition and a font-size, if available.
 :
MRodz's avatar
MRodz committed
711
 : @author Michelle Weidling
712
713
714
715
 : @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) {
MRodz's avatar
MRodz committed
716
    element {QName("http://www.tei-c.org/ns/1.0", "head")} {
717
        (if($node/descendant::tei:seg[matches(@style, "font-size")]) then
MRodz's avatar
MRodz committed
718
            attribute style {simpleHelpers:get-font-size($node)}
719
        else
MRodz's avatar
MRodz committed
720
            attribute style {"default"}
721
        ),
MRodz's avatar
MRodz committed
722
        attribute type {"former-" || $node/name()},
723
724
725
726
        $node/@subtype,
        (if($node/@rendition) then
            $node/@rendition
        else
MRodz's avatar
MRodz committed
727
728
729
730
731
            ()),         
        (if($node/@rend) then
            $node/@rend
        else
            ()),        
732
733
734
735
736
737
738
        fontaneSimple:transform($node/node())
    }
};

(:~
 : Creates a tei:div.
 :
MRodz's avatar
MRodz committed
739
 : @author Michelle Weidling
740
741
742
743
744
 : @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) {
MRodz's avatar
MRodz committed
745
    element {QName("http://www.tei-c.org/ns/1.0", "div")} {
746
747
748
749
750
751
752
753
        $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.
 :
MRodz's avatar
MRodz committed
754
 : @author Michelle Weidling
755
756
757
758
759
 : @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) {
MRodz's avatar
MRodz committed
760
    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
761
762
        attribute rendition {simpleHelpers:filter-rendition($node)},
        $node/(@* except (@style, @rendition)),
763
764
765
766
        (if($node[self::tei:line or self::tei:zone]) then
            attribute unit {$node/name()}
        else
            ()),
767
768
769
770
771
772
773
774
        fontaneSimple:transform($node/node())
    }
};


(:~
 : Creates a tei:pb.
 :
MRodz's avatar
MRodz committed
775
 : @author Michelle Weidling
776
777
778
779
780
 : @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) {
MRodz's avatar
MRodz committed
781
    element {QName("http://www.tei-c.org/ns/1.0", "pb")} {
782
783
784
785
786
787
788
789
790
791
        $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.
 :
MRodz's avatar
MRodz committed
792
 : @author Michelle Weidling
793
794
795
796
797
798
799
800
801
802
803
 : @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))
804
as element(tei:milestone) {
805
806
    let $prev-hand := $node/preceding::tei:handShift[@new][1]
    return
MRodz's avatar
MRodz committed
807
        element {QName("http://www.tei-c.org/ns/1.0", "milestone")} {
MRodz's avatar
MRodz committed
808
            attribute unit {"handshift"},
809
810
811
812
            attribute subtype {if($node/@new) then $node/@new else $prev-hand/@new},
            attribute rend {concat("script(", (if($node/@script) then $node/@script else ""), ") ",
                "medium(", (if($node/@medium) then $node/@medium else ""), ")")},
            $node/(@* except (@new, @medium, @script))
813
814
        }
};
815
816


817
declare function fontaneSimple:mark-intervention($node as element(*)) 
818
as element(tei:seg) {
MRodz's avatar
MRodz committed
819
    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
820
821
822
823
824
825
        if($node[self::tei:lb]) then
            attribute type {"missing-hyphen"}
        else if($node[self::tei:surplus]) then
            attribute type {"surplus"}
        else
            attribute type {"reduplication"},
826
            
827
        <tei:hi xmlns="http://www.tei-c.org/ns/1.0">‹</tei:hi>,
828
        
829
830
831
832
        if($node[self::tei:lb]) then
            simpleHelpers:find-chars($node)
        else
            fontaneSimple:transform($node/node()),
833
            
834
835
836
837
838
839
840
        <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) {
MRodz's avatar
MRodz committed
841
    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
842
843
844
845
846
847