tei2teisimple.xqm 22.4 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
17
18

declare namespace tei="http://www.tei-c.org/ns/1.0";

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

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

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

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

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

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

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

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

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

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

116
        case element(tei:add) return
117
            if($node/@type = "edited_text"
118
            or $node/child::tei:seg[@type = "multiphrase"]) then
119
                fontaneSimple:copy-element($node)
MRodz's avatar
MRodz committed
120
121
            else if($node/@cause ="catchword" or $node/@cause ="unclear") then
                ()
MRodz's avatar
MRodz committed
122
            else if($node/@rend ="|") then
123
                fontaneSimple:transform($node/node())
124
            else if(not($node/@xml:id)) then
125
                fontaneSimple:transform($node/node())
126
            else if(simpleHelpers:is-transposed($node)) then
127
128
                let $corresp := //tei:metamark[matches(@target, $node/@xml:id)]
                return
129
130
                    (fontaneSimple:transform($corresp/node()),
                    fontaneSimple:transform($node/node()))
131
            else
132
                fontaneSimple:transform($node/node())
133

134
135
        case element(tei:addSpan) return
            if($node/@type = "edited_text") then
136
                fontaneSimple:copy-element($node)
137
            else
138
139
                ()

140
141
        case element(tei:fw) return
            ()
142

143
144
145
        case element(tei:line) return
            if(count($node/*) = 1 and $node/child::tei:fw) then
                ()
MRodz's avatar
MRodz committed
146
            else if($node/@type = "heading") then
147
                fontaneSimple:make-head($node)
148

149
            else if(simpleHelpers:has-valid-style($node)
150
            or matches($node/@rendition, "black_letter")
151
            or matches($node/@rendition, "roman")) then
152
                fontaneSimple:make-seg-with-rendition($node)
153

154
            else if(not($node/@type = "item")) then
155
                fontaneSimple:transform($node/node())
156
157
            else if($node/@type = "item" and not($node/@xml:id)) then
                element tei:item {
158
                    fontaneSimple:transform($node/node())
159
                }
160
            else if($node/@type = "item"
161
            and simpleHelpers:is-transposed($node)) then
162
                ()
163
            else
164
                fontaneSimple:transform($node/node())
165

166
        case element(tei:handShift) return
167
            fontaneSimple:enhance-handshift($node)
168

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

172
        case element(tei:seg) return
173
            if(count($node/*) = 1 and
174
175
176
            ($node/child::tei:stamp or $node/child::tei:metamark[@function = "caret"]))
                then
                    ()
177

MRodz's avatar
MRodz committed
178
            else if($node/@type = "heading") then
179
                fontaneSimple:make-head($node)
180
181

            else if(matches($node/@style, "underline")
182
            and not(matches($node/@style, "vertical-align"))) then
183
                fontaneSimple:transform($node/node())
184

185
            else if(simpleHelpers:has-valid-style($node)
186
            or matches($node/@rendition, "black_letter")
187
            or matches($node/@rendition, "roman")) then
188
                fontaneSimple:make-seg-with-rendition($node)
189
190
191

            else if($node/@type = "initials"
            or $node/@type = "monogram"
MRodz's avatar
MRodz committed
192
193
            or $node/@type = "multiphrase"
            or $node/@xml:lang)
194
                then
195
                    fontaneSimple:copy-element($node)
196
197

            else if($node/@type = "auction_number"
198
            or $node/@type = "cancel"
MRodz's avatar
MRodz committed
199
200
            or $node/@type = "abort"
            or $node/@function ="unknown")
201
202
                then
                    ()
203

204
            else
205
                fontaneSimple:transform($node/node())
206

MRodz's avatar
MRodz committed
207
        case element(tei:hi) return
208
            fontaneSimple:copy-element($node)
209
210

        (: TODO if $node/@type = "highlighted" then make
211
        a hi[@type = "vertical-mark"] in the second stage of creating the
212
        simple format. use simpleHelpers:get-xml-chunk($node) for this.:)
213
214
        case element(tei:mod) return
            if($node/@type = "highlighted"
215
            and simpleHelpers:is-hand-contemporary($node/@hand)) then
216
                fontaneSimple:copy-element($node)
217
218
            else
                fontaneSimple:transform($node/node())
219

220
        case element(tei:anchor) return
221
            fontaneSimple:copy-element($node)
222
223

        case element(tei:surface) return
MRodz's avatar
MRodz committed
224
            if(matches($node/@n, "cover")) then
225
                fontaneSimple:make-pb-with-type($node/@n)
226
            else if(simpleHelpers:is-page($node)
MRodz's avatar
MRodz committed
227
            and $node/@type = "clipping") then
228
                (fontaneSimple:make-pb($node),
MRodz's avatar
MRodz committed
229
230
                (if(not($node/@subtype = "Kalenderblatt"
                or $node/@subtype = "Zeitungsausschnitt_Fragment")) then
231
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
232
233
                else
                    ()))
234
            else if(simpleHelpers:is-page($node)) then
235
                (fontaneSimple:make-pb($node),
236
                fontaneSimple:transform($node/node()))
237
            else if($node/@type = "label" and
238
            (contains($node/@subtype, "Fontane")
239
            or contains($node/@subtype, "Hersteller"))
240
            ) then
241
                fontaneSimple:make-div($node)
MRodz's avatar
MRodz committed
242
243
            else
                ()
244

MRodz's avatar
MRodz committed
245
246
247
        case element(tei:milestone) return
            if($node/@unit = "illustration") then
                ()
248
(:            else if($node/@unit = "section") then:)
249
(:                simpleHelpers:make-section($node):)
250
251
(:            else if($node/@unit = "pararaph") then:)
(:                fontaneSimple:make-paragraph($node):)
MRodz's avatar
MRodz committed
252
            else
253
                fontaneSimple:copy-element($node)
254

255
        case element(tei:gap) return
256
            fontaneSimple:copy-element($node)
257

258
        case element(tei:metamark) return
259
            if($node/@function = "integrate"
260
261
262
263
            or $node/@function = "authorial_note") then
                element tei:ab {
                    $node/@*
                }
264
            else if($node/@function = "placeholder"
265
266
267
268
269
            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
270
271
                element tei:ab {
                    attribute type {$node/@function},
272
                    fontaneSimple:transform($node/node())
273
                }
274
275
            else
                ()
276

277
278
279
        (: TODO: check if correct :)
        case element(tei:surplus) return
            ()
280

MRodz's avatar
MRodz committed
281
        case element(tei:zone) return
282
            if(matches($node/@style, "border-style:solid")
MRodz's avatar
MRodz committed
283
284
285
286
            and not(matches($node/@style, "border-radius"))
            and not($node/@rend = "border-style:house")) then
                element tei:div {
                    attribute type {"frame"},
287
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
288
                }
289

MRodz's avatar
MRodz committed
290
            else if(matches($node/@rend, "border-bottom-style:brace")) then
291
                (fontaneSimple:transform($node/node()),
MRodz's avatar
MRodz committed
292
293
                element tei:ab {
                    attribute type {"bottom-brace"}
294
295
                })

MRodz's avatar
MRodz committed
296
297
            else if($node/@type = "cancel") then
                ()
298

MRodz's avatar
MRodz committed
299
300
301
302
            else if($node/@type = "marked_off") then
                element tei:seg {
                    $node/@type,
                    $node/@xml:id,
303
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
304
                }
305

MRodz's avatar
MRodz committed
306
307
            else if($node/@type = "highlighted") then
                if($node/child::tei:zone[@type = "highlighted"]) then
308
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
309
310
311
                else
                    element tei:hi {
                        attribute type {"vertical-mark"},
312
                        fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
313
                    }
314

315
316
            else if($node/@type = "illustration"
            or $node/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
317
318
319
320
321
322
323
                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
324
                                attribute rendition {"margin-left:" || $node/@ulx
MRodz's avatar
MRodz committed
325
326
327
328
329
                                || "cm; " || "margin-top:" || $node/@uly || "cm"}
                            else
                                ()
                            )
                        ),
330
                        fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
331
                    }
332
                else
MRodz's avatar
MRodz committed
333
                    ()
334

335
336
            else if($node/parent::tei:zone/@type = "illustration"
            or $node/parent::tei:zone/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
337
338
                element {QName("http://www.tei-c.org/ns/1.0", "seg")}{
                    attribute type {"caption"},
339
                    attribute rendition {"margin-left:" || $node/@ulx || "cm; "
MRodz's avatar
MRodz committed
340
                        || "margin-top:" || $node/@uly || "cm"},
341
                    fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
342
                }
343

MRodz's avatar
MRodz committed
344
            else if($node/@type = "heading") then
345
                fontaneSimple:make-head($node)
346

MRodz's avatar
MRodz committed
347
348
            else if($node/@type = "list" or $node/@type = "item") then
                element {QName("http://www.tei-c.org/ns/1.0", $node/@type)}{
349
                    $node/(@* except (@type, @ulx, @uly, @lrx, @lry, @rotate)),
350
                    fontaneSimple:transform($node/node())
351
352
                }

MRodz's avatar
MRodz committed
353
354
            else if($node/@type = "legend") then
                element {QName("http://www.tei-c.org/ns/1.0", "div")}{
355
                    (if($node/@style
356
357
358
359
360
                    or $node/@rendition) then
                        attribute rendition {simpleHelpers:filter-rendition($node)}
                    else
                        ()),
                    $node/(@* except (@rendition, @style)),
361
                    fontaneSimple:transform($node/node())
362
363
                }

364
            else if(simpleHelpers:has-valid-style($node)
365
            or matches($node/@rendition, "black_letter")
366
            or matches($node/@rendition, "roman")) then
367
                fontaneSimple:make-seg-with-rendition($node)
368

369
            else if(not($node/@xml:id)) then
370
                fontaneSimple:transform($node/node())
371

372
            else if($node/@xml:id and simpleHelpers:is-transposed($node)) then
373
                ()
374

MRodz's avatar
MRodz committed
375
            else
376
                fontaneSimple:transform($node/node())
377

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

MRodz's avatar
MRodz committed
426
        case element(tei:note) return
427
            if($node/@type = "authorial"
428
            and not($node/@subtype = "footnote")) then
MRodz's avatar
MRodz committed
429
                ()
430
            else
431
                fontaneSimple:copy-element($node)
432

MRodz's avatar
MRodz committed
433
434
435
436
437
438
        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,
439
                fontaneSimple:transform($node/node())
MRodz's avatar
MRodz committed
440
            }
441

MRodz's avatar
MRodz committed
442
        case element(tei:figDesc) return
443
            fontaneSimple:copy-element($node)
444

MRodz's avatar
MRodz committed
445
        case element(tei:ref) return
446
            fontaneSimple:copy-element($node)
447

MRodz's avatar
MRodz committed
448
        case element(tei:space) return
449
            fontaneSimple:copy-element($node)
450

MRodz's avatar
MRodz committed
451
        case element(tei:choice) return
452
            fontaneSimple:copy-element($node)
453

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

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

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

MRodz's avatar
MRodz committed
463
        case element(tei:date) return
464
            element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
465
466
                (if($node/@when-iso) then
                    attribute when {$node/@when-iso}
467
468
                else
                    ()),
469
470
                (if($node/@from-iso) then
                    attribute from {$node/@from-iso}
471
472
                else
                    ()),
473
474
                (if($node/@to-iso) then
                    attribute to {$node/@to-iso}
Michelle Rodzis's avatar
Michelle Rodzis committed
475
                else
476
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
477
478
                (if($node/@notAfter-iso) then
                    attribute notAfter {$node/@notAfter-iso}
479
                else
480
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
481
                $node/(@* except (@when-iso, @to-iso, @from-iso, @notAfter-iso)),
482
                fontaneSimple:transform($node/node())
483
            }
484

485
        case element(tei:ptr) return
Michelle Rodzis's avatar
Michelle Rodzis committed
486
            text{"test"}
487

MRodz's avatar
MRodz committed
488
        default return
489
            fontaneSimple:transform($node/node())
490
};
491
492
493
494
495
496
497
498
499
500
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

(:~
 : 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
                ()
        }
};