tei2teisimple.xqm 35.9 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
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";
21
import module namespace index-info="http://fontane-nb.dariah.eu/index-info" at "index-info.xqm";
MRodz's avatar
MRodz committed
22

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

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

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

54
(:~
55
56
57
58
59
60
61
62
63
 : 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
64
 : @author Michelle Weidling
65
 : @param $nodes the elements of the book covers and the book content
Michelle Rodzis's avatar
Michelle Rodzis committed
66
 : @return $node()* a TEI simplePrint element
MRodz's avatar
MRodz committed
67
 :)
68
declare function fontaneSimple:transform($nodes as node()*) as node()* {
MRodz's avatar
MRodz committed
69
70
71
    for $node in $nodes
      return
        typeswitch ($node)
MRodz's avatar
MRodz committed
72
        case text() return
MRodz's avatar
MRodz committed
73
74
75
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
                simpleHelpers:prepare-text($node)
            else
                ()
80

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

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

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

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

MRodz's avatar
MRodz committed
112
113
        case element(tei:retrace) return
            if($node/@rend) then
MRodz's avatar
MRodz committed
114
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
115
                    attribute rendition {$node/@rend},
116
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
117
118
                }
            else
119
                fontaneSimple:transform($node/node())
120

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

MRodz's avatar
MRodz committed
402
            else if(matches($node/@rend, "border-bottom-style:brace")) then
403
                (fontaneSimple:transform($node/node()),
MRodz's avatar
MRodz committed
404
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
MRodz's avatar
MRodz committed
405
                    attribute type {"bottom-brace"}
406
407
                })

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

MRodz's avatar
MRodz committed
411
            else if($node/@type = "marked_off") then
MRodz's avatar
MRodz committed
412
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
413
414
                    $node/@type,
                    $node/@xml:id,
415
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
416
                }
417

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

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

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

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

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

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

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

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

528
            else if($node/@xml:id) then
MRodz's avatar
MRodz committed
529
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
530
531
532
533
534
535
                    $node/@xml:id,
                    $node/@prev,
                    $node/@next,
                    $node/@corresp,
                    fontaneSimple:transform($node/node())
                }
536

MRodz's avatar
MRodz committed
537
            else
538
                fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
539
540
                
        case element(tei:said) return
MRodz's avatar
MRodz committed
541
            (element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
542
543
544
545
                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
546
                element {QName("http://www.tei-c.org/ns/1.0", "lb")} {
MRodz's avatar
MRodz committed
547
548
549
550
                        attribute type {"edited_text"}
                }
            else
                ())
551

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

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

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

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

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

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

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

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

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

MRodz's avatar
MRodz committed
640
        case element(tei:rs) return
MRodz's avatar
MRodz committed
641
642
            let $index-type := substring-before($node/@ref, ":")
            return
MRodz's avatar
MRodz committed
643
                element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
MRodz's avatar
MRodz committed
644
                    $node/@*,
MRodz's avatar
MRodz committed
645
                    fontaneSimple:make-index-infos($node, $index-type),
MRodz's avatar
MRodz committed
646
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
647
                }
648

MRodz's avatar
MRodz committed
649
        case element(tei:date) return
MRodz's avatar
MRodz committed
650
            element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
651
652
                (if($node/@when-iso) then
                    attribute when {$node/@when-iso}
653
654
                else
                    ()),
655
656
                (if($node/@from-iso) then
                    attribute from {$node/@from-iso}
657
658
                else
                    ()),
659
660
                (if($node/@to-iso) then
                    attribute to {$node/@to-iso}
Michelle Rodzis's avatar
Michelle Rodzis committed
661
                else
662
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
663
664
                (if($node/@notAfter-iso) then
                    attribute notAfter {$node/@notAfter-iso}
665
                else
666
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
667
                $node/(@* except (@when-iso, @to-iso, @from-iso, @notAfter-iso)),
668
                fontaneSimple:transform($node/node())
669
            }
670

671
        case element(tei:ptr) return
672
            ()
673

MRodz's avatar
MRodz committed
674
        default return
675
            fontaneSimple:transform($node/node())
676
};
677
678
679
680

(:~
 : Takes a given element over as is since it is compliant to TEI simplePrint.
 :
MRodz's avatar
MRodz committed
681
 : @author Michelle Weidling
682
683
684
685
686
 : @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
687
688
689
690
691
        $node/(@* except @rend),
        if($node/@rend) then
            attribute rendition {$node/@rend}
        else
            (),
692
693
694
695
696
697
698
        fontaneSimple:transform($node/node())
    }
};

(:~
 : Creates a tei:head with an @rendition and a font-size, if available.
 :
MRodz's avatar
MRodz committed
699
 : @author Michelle Weidling
700
701
702
703
 : @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
704
    element {QName("http://www.tei-c.org/ns/1.0", "head")} {
705
        (if($node/descendant::tei:seg[matches(@style, "font-size")]) then
MRodz's avatar
MRodz committed
706
            attribute style {simpleHelpers:get-font-size($node)}
707
        else
MRodz's avatar
MRodz committed
708
            attribute style {"default"}
709
        ),
MRodz's avatar
MRodz committed
710
        attribute type {"former-" || $node/name()},
711
712
713
714
        $node/@subtype,
        (if($node/@rendition) then
            $node/@rendition
        else
MRodz's avatar
MRodz committed
715
716
717
718
719
            ()),         
        (if($node/@rend) then
            $node/@rend
        else
            ()),        
720
721
722
723
724
725
726
        fontaneSimple:transform($node/node())
    }
};

(:~
 : Creates a tei:div.
 :
MRodz's avatar
MRodz committed
727
 : @author Michelle Weidling
728
729
730
731
732
 : @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
733
    element {QName("http://www.tei-c.org/ns/1.0", "div")} {
734
735
736
737
738
739
740
741
        $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
742
 : @author Michelle Weidling
743
744
745
746
747
 : @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
748
    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
749
750
        attribute rendition {simpleHelpers:filter-rendition($node)},
        $node/(@* except (@style, @rendition)),
751
752
753
754
        (if($node[self::tei:line or self::tei:zone]) then
            attribute unit {$node/name()}
        else
            ()),
755
756
757
758
759
760
761
762
        fontaneSimple:transform($node/node())
    }
};


(:~
 : Creates a tei:pb.
 :
MRodz's avatar
MRodz committed
763
 : @author Michelle Weidling
764
765
766
767
768
 : @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
769
    element {QName("http://www.tei-c.org/ns/1.0", "pb")} {
770
771
772
773
774
775
776
777
778
779
        $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
780
 : @author Michelle Weidling
781
782
783
784
785
786
787
788
789
790
791
 : @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))
792
as element(tei:milestone) {
793
794
    let $prev-hand := $node/preceding::tei:handShift[@new][1]
    return
MRodz's avatar
MRodz committed
795
        element {QName("http://www.tei-c.org/ns/1.0", "milestone")} {
MRodz's avatar
MRodz committed
796
            attribute unit {"handshift"},
797
798
799
800
            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))
801
802
        }
};
803
804


805
declare function fontaneSimple:mark-intervention($node as element(*)) 
806
as element(tei:seg) {
MRodz's avatar
MRodz committed
807
    element {QName("http://www.tei-c.org/ns/1.0", "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
        <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
829
    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
830
831
832
833
834
835
836
837
838
839
840
841
842
        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) {
MRodz's avatar
MRodz committed
843
    element {QName("http://www.tei-c.org/ns/1.0", "milestone")} {
844
845
846
847
848
849
        attribute unit {"start-lg"}
    }
};

declare function fontaneSimple:mark-linegroup-end() as
element(tei:milestone) {
MRodz's avatar
MRodz committed
850
    element {QName("http://www.tei-c.org/ns/1.0", "milestone")} {