tei2teisimple.xqm 26.6 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
32
33
34
        (: TODO:An error with the index occured while building so we 
        temporarily put the file somewhere else :)
(:      (doc("/db/sade-projects/textgrid/data/xml/data/" || $file)):)
      (doc("/db/apps/SADE/resources/xml/" || $file))
MRodz's avatar
MRodz committed
35
36
37
    } catch * {
      (console:log("It was not possible to open the requested file " || $file))
    }
38

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

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

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

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

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

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

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

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

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

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

163
164
        case element(tei:fw) return
            ()
165

166
167
168
        case element(tei:line) return
            if(count($node/*) = 1 and $node/child::tei:fw) then
                ()
MRodz's avatar
MRodz committed
169
            else if($node/@type = "heading") then
170
                fontaneSimple:make-head($node)
171

172
            else if(simpleHelpers:has-valid-style($node)
173
            or matches($node/@rendition, "black_letter")
174
            or matches($node/@rendition, "roman")) then
175
                fontaneSimple:make-seg-with-rendition($node)
176
177
                
            else if($node/following::*[1][self::tei:lb[@break = "no"]]) then
178
179
                (simpleHelpers:start-line(),
                simpleHelpers:trim-last-char($node))
180
181
                
            else if ($node/preceding::*[1][self::tei:lb[@break = "no"]]) then
182
183
                (simpleHelpers:start-line(),
                simpleHelpers:trim-first-char($node))
184
185
186
187
188
189
190
191
192
193
194
195
196
197
                
            else if($node/@type = "verse") 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
                    ())    
                
198
199
200
            (: 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:)
201
            else if(not($node/@type = "item")) then
202
203
                (simpleHelpers:start-line(),
                fontaneSimple:transform($node/node()))
204
                
205
206
            else if($node/@type = "item" and not($node/@xml:id)) then
                element tei:item {
207
                    fontaneSimple:transform($node/node())
208
                }
209
                
210
            else if($node/@type = "item"
211
            and simpleHelpers:is-transposed($node)) then
212
                ()
213
                
214
            else
215
216
                (simpleHelpers:start-line(),
                fontaneSimple:transform($node/node()))
217

218
        case element(tei:handShift) return
219
            fontaneSimple:enhance-handshift($node)
220

221
222
        case element(tei:stamp) return
            ()
223

224
        case element(tei:seg) return
225
            if(count($node/*) = 1 and
226
            ($node/tei:stamp or $node/tei:metamark[@function = "caret"]))
227
228
                then
                    ()
229

MRodz's avatar
MRodz committed
230
            else if($node/@type = "heading") then
231
                fontaneSimple:make-head($node)
232
233

            else if(matches($node/@style, "underline")
234
            and not(matches($node/@style, "vertical-align"))) then
235
                fontaneSimple:transform($node/node())
236

237
            else if(simpleHelpers:has-valid-style($node)
238
            or matches($node/@rendition, "black_letter")
239
            or matches($node/@rendition, "roman")) then
240
                fontaneSimple:make-seg-with-rendition($node)
241
242
243

            else if($node/@type = "initials"
            or $node/@type = "monogram"
MRodz's avatar
MRodz committed
244
245
            or $node/@type = "multiphrase"
            or $node/@xml:lang)
246
                then
247
                    fontaneSimple:copy-element($node)
248
249

            else if($node/@type = "auction_number"
250
            or $node/@type = "cancel"
MRodz's avatar
MRodz committed
251
252
            or $node/@type = "abort"
            or $node/@function ="unknown")
253
254
                then
                    ()
255
256
257
                    
            else if($node/parent::tei:add and $node/@copyOf) then
                fontaneSimple:mark-intervention($node)
258

259
            else
260
                fontaneSimple:transform($node/node())
261

MRodz's avatar
MRodz committed
262
        case element(tei:hi) return
263
            fontaneSimple:copy-element($node)
264
265

        (: TODO if $node/@type = "highlighted" then make
266
        a hi[@type = "vertical-mark"] in the second stage of creating the
267
        simple format. use simpleHelpers:get-xml-chunk($node) for this.:)
268
269
        case element(tei:mod) return
            if($node/@type = "highlighted"
270
            and simpleHelpers:is-hand-contemporary($node/@hand)) then
271
                $node
272
273
            else
                fontaneSimple:transform($node/node())
274

275
        case element(tei:anchor) return
276
            fontaneSimple:copy-element($node)
277
278

        case element(tei:surface) return
MRodz's avatar
MRodz committed
279
            if(matches($node/@n, "cover")) then
Michelle Rodzis's avatar
Michelle Rodzis committed
280
281
282
                (fontaneSimple:make-pb-with-type($node/@n),
                fontaneSimple:transform($node/node()))
            
283
            else if(simpleHelpers:is-page($node)
MRodz's avatar
MRodz committed
284
            and $node/@type = "clipping") then
285
                (fontaneSimple:make-pb($node),
MRodz's avatar
MRodz committed
286
287
                (if(not($node/@subtype = "Kalenderblatt"
                or $node/@subtype = "Zeitungsausschnitt_Fragment")) then
288
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
289
290
                else
                    ()))
Michelle Rodzis's avatar
Michelle Rodzis committed
291
            
292
            else if(simpleHelpers:is-page($node)) then
293
                (fontaneSimple:make-pb($node),
294
                fontaneSimple:transform($node/node()))
Michelle Rodzis's avatar
Michelle Rodzis committed
295
            
296
            else if($node/@type = "label" and
297
            (contains($node/@subtype, "Fontane")
298
            or contains($node/@subtype, "Hersteller"))
299
            ) then
300
                fontaneSimple:make-div($node)
Michelle Rodzis's avatar
Michelle Rodzis committed
301
            
MRodz's avatar
MRodz committed
302
303
            else
                ()
304

MRodz's avatar
MRodz committed
305
306
307
        case element(tei:milestone) return
            if($node/@unit = "illustration") then
                ()
308
(:            else if($node/@unit = "section") then:)
309
(:                simpleHelpers:make-section($node):)
310
311
(:            else if($node/@unit = "pararaph") then:)
(:                fontaneSimple:make-paragraph($node):)
MRodz's avatar
MRodz committed
312
            else
313
                fontaneSimple:copy-element($node)
314

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

318
        case element(tei:metamark) return
319
            if($node/@function = "integrate"
320
321
322
323
            or $node/@function = "authorial_note") then
                element tei:ab {
                    $node/@*
                }
324
            else if($node/@function = "placeholder"
325
326
327
328
329
            or $node/@function ="etc."
            or $node/@function ="caret"
            or $node/@function ="footnotes"
            or $node/@function ="ellipsis"
            or $node/@function = "paragraph") then
MRodz's avatar
MRodz committed
330
331
                element tei:ab {
                    attribute type {$node/@function},
332
                    fontaneSimple:transform($node/node())
333
                }
334
335
            else
                ()
336

337
        case element(tei:surplus) return
338
            fontaneSimple:mark-intervention($node)
339

MRodz's avatar
MRodz committed
340
        case element(tei:zone) return
341
            if(matches($node/@style, "border-style:solid")
MRodz's avatar
MRodz committed
342
343
344
345
            and not(matches($node/@style, "border-radius"))
            and not($node/@rend = "border-style:house")) then
                element tei:div {
                    attribute type {"frame"},
346
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
347
                }
348

MRodz's avatar
MRodz committed
349
            else if(matches($node/@rend, "border-bottom-style:brace")) then
350
                (fontaneSimple:transform($node/node()),
MRodz's avatar
MRodz committed
351
352
                element tei:ab {
                    attribute type {"bottom-brace"}
353
354
                })

MRodz's avatar
MRodz committed
355
356
            else if($node/@type = "cancel") then
                ()
357

MRodz's avatar
MRodz committed
358
359
360
361
            else if($node/@type = "marked_off") then
                element tei:seg {
                    $node/@type,
                    $node/@xml:id,
362
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
363
                }
364

MRodz's avatar
MRodz committed
365
366
            else if($node/@type = "highlighted") then
                if($node/child::tei:zone[@type = "highlighted"]) then
367
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
368
369
370
                else
                    element tei:hi {
                        attribute type {"vertical-mark"},
371
                        fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
372
                    }
373

374
375
            else if($node/@type = "illustration"
            or $node/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
376
377
378
379
380
381
382
                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
383
                                attribute rendition {"margin-left:" || $node/@ulx
MRodz's avatar
MRodz committed
384
385
386
387
388
                                || "cm; " || "margin-top:" || $node/@uly || "cm"}
                            else
                                ()
                            )
                        ),
389
                        fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
390
                    }
391
                else
MRodz's avatar
MRodz committed
392
                    ()
393

394
395
            else if($node/parent::tei:zone/@type = "illustration"
            or $node/parent::tei:zone/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
396
397
                element {QName("http://www.tei-c.org/ns/1.0", "seg")}{
                    attribute type {"caption"},
398
                    attribute rendition {"margin-left:" || $node/@ulx || "cm; "
MRodz's avatar
MRodz committed
399
                        || "margin-top:" || $node/@uly || "cm"},
400
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
401
                }
402

MRodz's avatar
MRodz committed
403
            else if($node/@type = "heading") then
404
                fontaneSimple:make-head($node)
405

MRodz's avatar
MRodz committed
406
407
            else if($node/@type = "list" or $node/@type = "item") then
                element {QName("http://www.tei-c.org/ns/1.0", $node/@type)}{
408
                    $node/(@* except (@type, @ulx, @uly, @lrx, @lry, @rotate)),
409
                    fontaneSimple:transform($node/node())
410
411
                }

MRodz's avatar
MRodz committed
412
413
            else if($node/@type = "legend") then
                element {QName("http://www.tei-c.org/ns/1.0", "div")}{
414
                    (if($node/@style
415
416
417
418
419
                    or $node/@rendition) then
                        attribute rendition {simpleHelpers:filter-rendition($node)}
                    else
                        ()),
                    $node/(@* except (@rendition, @style)),
420
                    fontaneSimple:transform($node/node())
421
422
                }

423
            else if(simpleHelpers:has-valid-style($node)
424
            or matches($node/@rendition, "black_letter")
425
            or matches($node/@rendition, "roman")) then
426
                fontaneSimple:make-seg-with-rendition($node)
427

428
            else if(not($node/@xml:id)) then
429
                fontaneSimple:transform($node/node())
430

431
            else if($node/@xml:id and simpleHelpers:is-transposed($node)) then
432
                ()
433

MRodz's avatar
MRodz committed
434
            else
435
                fontaneSimple:transform($node/node())
436

MRodz's avatar
MRodz committed
437
        case element(tei:figure) return
438
            if(count($node/child::*) = 1 and $node/child::tei:figDesc) then
439
                (: genealogy lines probably shouldn't be displayed, but I still have to
440
441
442
443
                check that. in case they should be serialized, I leave the code :)
(:                if(matches($node/descendant::tei:ref, "Stammbaumverbindungslinie")) then:)
(:                    element tei:seg {:)
(:                        $node/@*,:)
444
(:                        fontaneSimple:transform($node/node()):)
445
446
447
448
449
450
(:                    }:)
(:                else if(matches($node/descendant::tei:ref, "Schlusslinie")):)
                if(matches($node/descendant::tei:ref, "Schlusslinie"))
                    then
                        element tei:ab {
                            switch ($node/descendant::tei:ref)
451
452
453
                                case "horizontale einfache Schlusslinie" return
                                    attribute type {"long-end-line"}
                                case "Schlusslinie; horizontale Halbschleife von links oben nach rechts" return
454
                                    attribute type {"long-end-line"}
455
                                case "horizontale einfache Schlusslinie (gewellt)" return
456
                                    attribute type {"long-end-line-wavy"}
457
                                case "Schlusslinien; horizontale Schleife von links oben nach rechts unten" return
458
                                    attribute type {"bottom-brace-short"}
459
460
                                default return
                                    attribute type {"end-line"}
461
462
                        }
                else if(matches($node/descendant::tei:ref, "Absatzlinie")
463
464
                (: in case of double paragraph lines the single lines are
                encoded with "oberer" resp. "unterer Teil", but we only
465
466
467
468
469
470
471
472
473
474
                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
475
476
                else if($node/parent::tei:zone[@type = "illustration"]) then
                    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
Michelle Rodzis's avatar
Michelle Rodzis committed
477
478
                        $node/@*,
                        fontaneSimple:transform($nodes/node())
MRodz's avatar
MRodz committed
479
                    }
480
                else
MRodz's avatar
MRodz committed
481
482
                    ()
            else
483
                fontaneSimple:copy-element($node)
484

MRodz's avatar
MRodz committed
485
        case element(tei:note) return
486
            if($node/@type = "authorial"
487
            and not($node/@subtype = "footnote")) then
MRodz's avatar
MRodz committed
488
                ()
489
            else
490
                fontaneSimple:copy-element($node)
491

MRodz's avatar
MRodz committed
492
493
494
495
496
497
        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,
498
                fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
499
            }
500

MRodz's avatar
MRodz committed
501
        case element(tei:figDesc) return
502
            fontaneSimple:copy-element($node)
503

MRodz's avatar
MRodz committed
504
        case element(tei:ref) return
505
            fontaneSimple:copy-element($node)
506

MRodz's avatar
MRodz committed
507
        case element(tei:space) return
508
            fontaneSimple:copy-element($node)
509

MRodz's avatar
MRodz committed
510
        case element(tei:choice) return
511
            fontaneSimple:copy-element($node)
512

MRodz's avatar
MRodz committed
513
        case element(tei:abbr) return
514
            fontaneSimple:copy-element($node)
515

MRodz's avatar
MRodz committed
516
        case element(tei:expan) return
517
            fontaneSimple:copy-element($node)
518
519
520
521
522
523
            
        case element(tei:sic) return
            fontaneSimple:copy-element($node)     
            
        case element(tei:corr) return
            fontaneSimple:copy-element($node)
524

MRodz's avatar
MRodz committed
525
        case element(tei:rs) return
526
            fontaneSimple:copy-element($node)
527

MRodz's avatar
MRodz committed
528
        case element(tei:date) return
529
            element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
530
531
                (if($node/@when-iso) then
                    attribute when {$node/@when-iso}
532
533
                else
                    ()),
534
535
                (if($node/@from-iso) then
                    attribute from {$node/@from-iso}
536
537
                else
                    ()),
538
539
                (if($node/@to-iso) then
                    attribute to {$node/@to-iso}
Michelle Rodzis's avatar
Michelle Rodzis committed
540
                else
541
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
542
543
                (if($node/@notAfter-iso) then
                    attribute notAfter {$node/@notAfter-iso}
544
                else
545
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
546
                $node/(@* except (@when-iso, @to-iso, @from-iso, @notAfter-iso)),
547
                fontaneSimple:transform($node/node())
548
            }
549

550
        case element(tei:ptr) return
Michelle Rodzis's avatar
Michelle Rodzis committed
551
            text{"test"}
552

MRodz's avatar
MRodz committed
553
        default return
554
            fontaneSimple:transform($node/node())
555
};
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620

(:~
 : 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())}{
        $node/@*,
        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
            attribute type {simpleHelpers:get-font-size($node)}
        else
            attribute type {"default"}
        ),
        $node/@subtype,
        (if($node/@rendition) then
            $node/@rendition
        else
            ()),
        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)),
621
622
623
624
        (if($node[self::tei:line or self::tei:zone]) then
            attribute unit {$node/name()}
        else
            ()),
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
        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
                ()
        }
};
681
682


683
declare function fontaneSimple:mark-intervention($node as element(*)) 
684
685
as element(tei:seg) {
    element tei:seg {
686
687
688
689
690
691
        if($node[self::tei:lb]) then
            attribute type {"missing-hyphen"}
        else if($node[self::tei:surplus]) then
            attribute type {"surplus"}
        else
            attribute type {"reduplication"},
692
            
693
        <tei:hi xmlns="http://www.tei-c.org/ns/1.0">‹</tei:hi>,
694
        
695
696
697
698
        if($node[self::tei:lb]) then
            simpleHelpers:find-chars($node)
        else
            fontaneSimple:transform($node/node()),
699
            
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
        <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"}
730
731
    }
};