tei2teisimple.xqm 23 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
31
32
33
34
    try {
      (doc("/db/sade-projects/textgrid/data/xml/data/" || $file))
    } catch * {
      (console:log("It was not possible to open the requested file " || $file))
    }
35

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

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

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

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

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

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

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

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

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

145
146
        case element(tei:addSpan) return
            if($node/@type = "edited_text") then
147
                fontaneSimple:copy-element($node)
148
            else
149
150
                ()

151
152
        case element(tei:fw) return
            ()
153

154
155
156
        case element(tei:line) return
            if(count($node/*) = 1 and $node/child::tei:fw) then
                ()
MRodz's avatar
MRodz committed
157
            else if($node/@type = "heading") then
158
                fontaneSimple:make-head($node)
159

160
            else if(simpleHelpers:has-valid-style($node)
161
            or matches($node/@rendition, "black_letter")
162
            or matches($node/@rendition, "roman")) then
163
                fontaneSimple:make-seg-with-rendition($node)
164

165
            else if(not($node/@type = "item")) then
166
                fontaneSimple:transform($node/node())
167
168
            else if($node/@type = "item" and not($node/@xml:id)) then
                element tei:item {
169
                    fontaneSimple:transform($node/node())
170
                }
171
            else if($node/@type = "item"
172
            and simpleHelpers:is-transposed($node)) then
173
                ()
174
            else
175
                fontaneSimple:transform($node/node())
176

177
        case element(tei:handShift) return
178
            fontaneSimple:enhance-handshift($node)
179

180
181
        case element(tei:stamp) return
            ()
182

183
        case element(tei:seg) return
184
            if(count($node/*) = 1 and
185
            ($node/tei:stamp or $node/tei:metamark[@function = "caret"]))
186
187
                then
                    ()
188

MRodz's avatar
MRodz committed
189
            else if($node/@type = "heading") then
190
                fontaneSimple:make-head($node)
191
192

            else if(matches($node/@style, "underline")
193
            and not(matches($node/@style, "vertical-align"))) then
194
                fontaneSimple:transform($node/node())
195

196
            else if(simpleHelpers:has-valid-style($node)
197
            or matches($node/@rendition, "black_letter")
198
            or matches($node/@rendition, "roman")) then
199
                fontaneSimple:make-seg-with-rendition($node)
200
201
202

            else if($node/@type = "initials"
            or $node/@type = "monogram"
MRodz's avatar
MRodz committed
203
204
            or $node/@type = "multiphrase"
            or $node/@xml:lang)
205
                then
206
                    fontaneSimple:copy-element($node)
207
208

            else if($node/@type = "auction_number"
209
            or $node/@type = "cancel"
MRodz's avatar
MRodz committed
210
211
            or $node/@type = "abort"
            or $node/@function ="unknown")
212
213
                then
                    ()
214

215
            else
216
                fontaneSimple:transform($node/node())
217

MRodz's avatar
MRodz committed
218
        case element(tei:hi) return
219
            fontaneSimple:copy-element($node)
220
221

        (: TODO if $node/@type = "highlighted" then make
222
        a hi[@type = "vertical-mark"] in the second stage of creating the
223
        simple format. use simpleHelpers:get-xml-chunk($node) for this.:)
224
225
        case element(tei:mod) return
            if($node/@type = "highlighted"
226
            and simpleHelpers:is-hand-contemporary($node/@hand)) then
227
                fontaneSimple:copy-element($node)
228
229
            else
                fontaneSimple:transform($node/node())
230

231
        case element(tei:anchor) return
232
            fontaneSimple:copy-element($node)
233
234

        case element(tei:surface) return
MRodz's avatar
MRodz committed
235
            if(matches($node/@n, "cover")) then
236
                fontaneSimple:make-pb-with-type($node/@n)
237
            else if(simpleHelpers:is-page($node)
MRodz's avatar
MRodz committed
238
            and $node/@type = "clipping") then
239
                (fontaneSimple:make-pb($node),
MRodz's avatar
MRodz committed
240
241
                (if(not($node/@subtype = "Kalenderblatt"
                or $node/@subtype = "Zeitungsausschnitt_Fragment")) then
242
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
243
244
                else
                    ()))
245
            else if(simpleHelpers:is-page($node)) then
246
                (fontaneSimple:make-pb($node),
247
                fontaneSimple:transform($node/node()))
248
            else if($node/@type = "label" and
249
            (contains($node/@subtype, "Fontane")
250
            or contains($node/@subtype, "Hersteller"))
251
            ) then
252
                fontaneSimple:make-div($node)
MRodz's avatar
MRodz committed
253
254
            else
                ()
255

MRodz's avatar
MRodz committed
256
257
258
        case element(tei:milestone) return
            if($node/@unit = "illustration") then
                ()
259
(:            else if($node/@unit = "section") then:)
260
(:                simpleHelpers:make-section($node):)
261
262
(:            else if($node/@unit = "pararaph") then:)
(:                fontaneSimple:make-paragraph($node):)
MRodz's avatar
MRodz committed
263
            else
264
                fontaneSimple:copy-element($node)
265

266
        case element(tei:gap) return
267
            fontaneSimple:copy-element($node)
268

269
        case element(tei:metamark) return
270
            if($node/@function = "integrate"
271
272
273
274
            or $node/@function = "authorial_note") then
                element tei:ab {
                    $node/@*
                }
275
            else if($node/@function = "placeholder"
276
277
278
279
280
            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
281
282
                element tei:ab {
                    attribute type {$node/@function},
283
                    fontaneSimple:transform($node/node())
284
                }
285
286
            else
                ()
287

288
289
290
        (: TODO: check if correct :)
        case element(tei:surplus) return
            ()
291

MRodz's avatar
MRodz committed
292
        case element(tei:zone) return
293
            if(matches($node/@style, "border-style:solid")
MRodz's avatar
MRodz committed
294
295
296
297
            and not(matches($node/@style, "border-radius"))
            and not($node/@rend = "border-style:house")) then
                element tei:div {
                    attribute type {"frame"},
298
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
299
                }
300

MRodz's avatar
MRodz committed
301
            else if(matches($node/@rend, "border-bottom-style:brace")) then
302
                (fontaneSimple:transform($node/node()),
MRodz's avatar
MRodz committed
303
304
                element tei:ab {
                    attribute type {"bottom-brace"}
305
306
                })

MRodz's avatar
MRodz committed
307
308
            else if($node/@type = "cancel") then
                ()
309

MRodz's avatar
MRodz committed
310
311
312
313
            else if($node/@type = "marked_off") then
                element tei:seg {
                    $node/@type,
                    $node/@xml:id,
314
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
315
                }
316

MRodz's avatar
MRodz committed
317
318
            else if($node/@type = "highlighted") then
                if($node/child::tei:zone[@type = "highlighted"]) then
319
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
320
321
322
                else
                    element tei:hi {
                        attribute type {"vertical-mark"},
323
                        fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
324
                    }
325

326
327
            else if($node/@type = "illustration"
            or $node/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
328
329
330
331
332
333
334
                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
335
                                attribute rendition {"margin-left:" || $node/@ulx
MRodz's avatar
MRodz committed
336
337
338
339
340
                                || "cm; " || "margin-top:" || $node/@uly || "cm"}
                            else
                                ()
                            )
                        ),
341
                        fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
342
                    }
343
                else
MRodz's avatar
MRodz committed
344
                    ()
345

346
347
            else if($node/parent::tei:zone/@type = "illustration"
            or $node/parent::tei:zone/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
348
349
                element {QName("http://www.tei-c.org/ns/1.0", "seg")}{
                    attribute type {"caption"},
350
                    attribute rendition {"margin-left:" || $node/@ulx || "cm; "
MRodz's avatar
MRodz committed
351
                        || "margin-top:" || $node/@uly || "cm"},
352
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
353
                }
354

MRodz's avatar
MRodz committed
355
            else if($node/@type = "heading") then
356
                fontaneSimple:make-head($node)
357

MRodz's avatar
MRodz committed
358
359
            else if($node/@type = "list" or $node/@type = "item") then
                element {QName("http://www.tei-c.org/ns/1.0", $node/@type)}{
360
                    $node/(@* except (@type, @ulx, @uly, @lrx, @lry, @rotate)),
361
                    fontaneSimple:transform($node/node())
362
363
                }

MRodz's avatar
MRodz committed
364
365
            else if($node/@type = "legend") then
                element {QName("http://www.tei-c.org/ns/1.0", "div")}{
366
                    (if($node/@style
367
368
369
370
371
                    or $node/@rendition) then
                        attribute rendition {simpleHelpers:filter-rendition($node)}
                    else
                        ()),
                    $node/(@* except (@rendition, @style)),
372
                    fontaneSimple:transform($node/node())
373
374
                }

375
            else if(simpleHelpers:has-valid-style($node)
376
            or matches($node/@rendition, "black_letter")
377
            or matches($node/@rendition, "roman")) then
378
                fontaneSimple:make-seg-with-rendition($node)
379

380
            else if(not($node/@xml:id)) then
381
                fontaneSimple:transform($node/node())
382

383
            else if($node/@xml:id and simpleHelpers:is-transposed($node)) then
384
                ()
385

MRodz's avatar
MRodz committed
386
            else
387
                fontaneSimple:transform($node/node())
388

MRodz's avatar
MRodz committed
389
        case element(tei:figure) return
390
            if(count($node/child::*) = 1 and $node/child::tei:figDesc) then
391
                (: genealogy lines probably shouldn't be displayed, but I still have to
392
393
394
395
                check that. in case they should be serialized, I leave the code :)
(:                if(matches($node/descendant::tei:ref, "Stammbaumverbindungslinie")) then:)
(:                    element tei:seg {:)
(:                        $node/@*,:)
396
(:                        fontaneSimple:transform($node/node()):)
397
398
399
400
401
402
(:                    }:)
(:                else if(matches($node/descendant::tei:ref, "Schlusslinie")):)
                if(matches($node/descendant::tei:ref, "Schlusslinie"))
                    then
                        element tei:ab {
                            switch ($node/descendant::tei:ref)
403
404
405
                                case "horizontale einfache Schlusslinie" return
                                    attribute type {"long-end-line"}
                                case "Schlusslinie; horizontale Halbschleife von links oben nach rechts" return
406
                                    attribute type {"long-end-line"}
407
                                case "horizontale einfache Schlusslinie (gewellt)" return
408
                                    attribute type {"long-end-line-wavy"}
409
                                case "Schlusslinien; horizontale Schleife von links oben nach rechts unten" return
410
                                    attribute type {"bottom-brace-short"}
411
412
                                default return
                                    attribute type {"end-line"}
413
414
                        }
                else if(matches($node/descendant::tei:ref, "Absatzlinie")
415
416
                (: in case of double paragraph lines the single lines are
                encoded with "oberer" resp. "unterer Teil", but we only
417
418
419
420
421
422
423
424
425
426
                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
427
428
                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
429
430
                        $node/@*,
                        fontaneSimple:transform($nodes/node())
MRodz's avatar
MRodz committed
431
                    }
432
                else
MRodz's avatar
MRodz committed
433
434
                    ()
            else
435
                fontaneSimple:copy-element($node)
436

MRodz's avatar
MRodz committed
437
        case element(tei:note) return
438
            if($node/@type = "authorial"
439
            and not($node/@subtype = "footnote")) then
MRodz's avatar
MRodz committed
440
                ()
441
            else
442
                fontaneSimple:copy-element($node)
443

MRodz's avatar
MRodz committed
444
445
446
447
448
449
        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,
450
                fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
451
            }
452

MRodz's avatar
MRodz committed
453
        case element(tei:figDesc) return
454
            fontaneSimple:copy-element($node)
455

MRodz's avatar
MRodz committed
456
        case element(tei:ref) return
457
            fontaneSimple:copy-element($node)
458

MRodz's avatar
MRodz committed
459
        case element(tei:space) return
460
            fontaneSimple:copy-element($node)
461

MRodz's avatar
MRodz committed
462
        case element(tei:choice) return
463
            fontaneSimple:copy-element($node)
464

MRodz's avatar
MRodz committed
465
        case element(tei:abbr) return
466
            fontaneSimple:copy-element($node)
467

MRodz's avatar
MRodz committed
468
        case element(tei:expan) return
469
            fontaneSimple:copy-element($node)
470

MRodz's avatar
MRodz committed
471
        case element(tei:rs) return
472
            fontaneSimple:copy-element($node)
473

MRodz's avatar
MRodz committed
474
        case element(tei:date) return
475
            element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
476
477
                (if($node/@when-iso) then
                    attribute when {$node/@when-iso}
478
479
                else
                    ()),
480
481
                (if($node/@from-iso) then
                    attribute from {$node/@from-iso}
482
483
                else
                    ()),
484
485
                (if($node/@to-iso) then
                    attribute to {$node/@to-iso}
Michelle Rodzis's avatar
Michelle Rodzis committed
486
                else
487
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
488
489
                (if($node/@notAfter-iso) then
                    attribute notAfter {$node/@notAfter-iso}
490
                else
491
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
492
                $node/(@* except (@when-iso, @to-iso, @from-iso, @notAfter-iso)),
493
                fontaneSimple:transform($node/node())
494
            }
495

496
        case element(tei:ptr) return
Michelle Rodzis's avatar
Michelle Rodzis committed
497
            text{"test"}
498

MRodz's avatar
MRodz committed
499
        default return
500
            fontaneSimple:transform($node/node())
501
};
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
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
621
622

(:~
 : 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)),
        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
                ()
        }
};
623
624
625
626
627
628
629
630
631
632
633


declare function fontaneSimple:mark-syllable-duplication($node as element(tei:add)) 
as element(tei:seg) {
    element tei:seg {
        attribute type {"reduplication"},
        <hi>‹</hi>,
        fontaneSimple:transform($node/node()),
        <hi>›</hi>
    }
};