transform2teisimple.xqm 24.4 KB
Newer Older
MRodz's avatar
MRodz committed
1
2
3
xquery version "3.1";

(:~ 
Michelle Rodzis's avatar
Michelle Rodzis committed
4
5
6
7
 : 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
 : Text" (edited text) view on the website and the book and represent the latest 
 : layer of text.
MRodz's avatar
MRodz committed
8
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
15
 :)

module namespace fontane-simple="http://fontane-nb.dariah.eu/teisimple";

MRodz's avatar
MRodz committed
16

MRodz's avatar
MRodz committed
17
18
19
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace test="http://exist-db.org/xquery/xqsuite";

20
import module namespace config="http://textgrid.de/ns/SADE/config" at "../config/config.xqm";
MRodz's avatar
MRodz committed
21
import module namespace console="http://exist-db.org/xquery/console";
MRodz's avatar
MRodz committed
22
import module namespace functx = "http://www.functx.com";
MRodz's avatar
MRodz committed
23
24
25
26
27
28
29

(:~ 
 : The main function initiates the transformation of a given notebook.
 : 
 : TODO: adapt to several input files?
 : 
 : :)
30
declare function fontane-simple:main($file as xs:string) as xs:string? {
MRodz's avatar
MRodz committed
31
32
33
34
35
36
37
  let $doc := 
    try {
      (doc("/db/sade-projects/textgrid/data/xml/data/" || $file))
    } catch * {
      (console:log("It was not possible to open the requested file " || $file))
    }
    
MRodz's avatar
Fix #23    
MRodz committed
38
39
    let $front-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "front_cover")]
    let $back-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "back_cover")]
MRodz's avatar
MRodz committed
40
    let $content := $doc//tei:sourceDoc/tei:surface[not(contains(@n, "cover") 
MRodz's avatar
MRodz committed
41
        or matches(@n, "spine"))]
MRodz's avatar
MRodz committed
42
    
43
    let $tei := <TEI xmlns="http://www.tei-c.org/ns/1.0">
MRodz's avatar
MRodz committed
44
        {$doc//tei:teiHeader}
MRodz's avatar
MRodz committed
45
46
47
48
49
        <text>
            <front>{fontane-simple:transform($front-covers)}</front>
            <body>{fontane-simple:transform($content)}</body>
            <back>{fontane-simple:transform($back-covers)}</back>
        </text>
MRodz's avatar
MRodz committed
50
      </TEI>
51
    return xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple.xml", $tei)
MRodz's avatar
MRodz committed
52
53
};

MRodz's avatar
MRodz committed
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". 
 : 
 : The requirements are part of the encoding documentation, c.f.
 : https://fontane-nb.dariah.eu/doku.html.
 : 
 : @author Michelle Rodzis
 : @param $nodes
Michelle Rodzis's avatar
Michelle Rodzis committed
63
 : @return $node()* a TEI simplePrint element
MRodz's avatar
MRodz committed
64
65
 :)
declare function fontane-simple: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
70
71
72
73
74
75
        case text() return
            local:prepare-text($node)
        
        case element(tei:lb) return
            if($node[@break = "keepHyphen"]) then
                ()
            else
Michelle Rodzis's avatar
Michelle Rodzis committed
76
                local:copy-element($node)
MRodz's avatar
MRodz committed
77
78
79
80
81
                
        case element(tei:g) return
            if($node[@ref = "#vds"]) then
                ()
            else if($node/@ref ="#rth" or $node/@ref ="#hb") then
Michelle Rodzis's avatar
Michelle Rodzis committed
82
                local:copy-element($node)
MRodz's avatar
MRodz committed
83
84
            else
                fontane-simple:transform($node/node())
85
                
MRodz's avatar
MRodz committed
86
87
88
89
90
91
        case element(tei:del) return
            if($node/parent::tei:restore) then
                fontane-simple:transform($node/node())
            else if($node/descendant::tei:restore) then
                fontane-simple:transform($node/descendant::tei:restore)
            else
MRodz's avatar
MRodz committed
92
                ()
93
                
MRodz's avatar
MRodz committed
94
95
96
97
98
99
        case element(tei:restore) return
            if(count($node/child::*) = 1 and $node/child::tei:del
            and $node/ancestor::tei:del) then
                ()
            else
                fontane-simple:transform($node/node())
100
                
MRodz's avatar
MRodz committed
101
102
103
104
105
106
107
108
        case element(tei:retrace) return
            if($node/@rend) then
                element tei:seg {
                    $node/@rend,
                    fontane-simple:transform($node/node())
                }
            else
                fontane-simple:transform($node/node())
109
110
                
        case element(tei:add) return
111
112
            if($node/@type = "edited_text" 
            or $node/child::tei:seg[@type = "multiphrase"]) then
Michelle Rodzis's avatar
Michelle Rodzis committed
113
                local:copy-element($node)
MRodz's avatar
MRodz committed
114
115
            else if($node/@cause ="catchword" or $node/@cause ="unclear") then
                ()
MRodz's avatar
MRodz committed
116
117
            else if($node/@rend ="|") then
                fontane-simple:transform($node/node())
118
119
120
121
122
123
124
125
126
127
128
129
            else if(not($node/@xml:id)) then
                fontane-simple:transform($node/node())
            else if(fontane-simple:is-transposed($node)) then
                let $corresp := //tei:metamark[matches(@target, $node/@xml:id)]
                return
                    (fontane-simple:transform($corresp/node()),
                    fontane-simple:transform($node/node()))
            else
                fontane-simple:transform($node/node())
                
        case element(tei:addSpan) return
            if($node/@type = "edited_text") then
Michelle Rodzis's avatar
Michelle Rodzis committed
130
                local:copy-element($node)
131
132
133
            else
                ()       
                
134
135
        case element(tei:fw) return
            ()
136
                
137
138
139
        case element(tei:line) return
            if(count($node/*) = 1 and $node/child::tei:fw) then
                ()
MRodz's avatar
MRodz committed
140
            else if($node/@type = "heading") then
Michelle Rodzis's avatar
Michelle Rodzis committed
141
                local:make-head($node)
142
143
144
145
            else if(not($node/@type = "item")) then
                fontane-simple:transform($node/node())
            else if($node/@type = "item" and not($node/@xml:id)) then
                element tei:item {
146
                    fontane-simple:transform($node/node())
147
148
149
                }
            else if($node/@type = "item" 
            and fontane-simple:is-transposed($node)) then
MRodz's avatar
MRodz committed
150
                ()            
151
152
            else
                fontane-simple:transform($node/node())
153
                        
154
        case element(tei:handShift) return
Michelle Rodzis's avatar
Michelle Rodzis committed
155
            (: tei:local:copy-element($node)ft without @new denote the duct of the current 
156
157
158
159
            writer or a change of writing medium :)
            if($node/@new and (fontane-simple:is-hand-contemporary($node/@new) or
            $node/@new = "#Friedrich_Fontane") or not($node/@new))
                then
Michelle Rodzis's avatar
Michelle Rodzis committed
160
                    local:copy-element($node)
161
162
                else
                    ()
MRodz's avatar
MRodz committed
163
164
165
166
167
168
                
(:                if($node/following-sibling::*[1][count(./*) = 1 :)
(:                    and child::tei:fw or child::tei:stamp]):)
(:                    then:)
(:                        ():)
(:                    else:)
Michelle Rodzis's avatar
Michelle Rodzis committed
169
(:                        element tei:local:copy-element($node)ft {:)
MRodz's avatar
MRodz committed
170
171
(:                            $node/@*:)
(:                        }:)
172
173
        case element(tei:stamp) return
            ()
174
                
175
176
177
178
179
        case element(tei:seg) return
            if(count($node/*) = 1 and 
            ($node/child::tei:stamp or $node/child::tei:metamark[@function = "caret"]))
                then
                    ()
MRodz's avatar
MRodz committed
180
            else if($node/@type = "heading") then
Michelle Rodzis's avatar
Michelle Rodzis committed
181
                local:make-head($node)
182
183
184
            else if(matches($node/@style, "underline") 
            and not(matches($node/@style, "vertical-align"))) then
                fontane-simple:transform($node/node())
MRodz's avatar
MRodz committed
185
186
187
188
189
190
            else if($node/@style) then
                element{QName("http://www.tei-c.org/ns/1.0", $node/name())}{
                    attribute rendition {$node/@style},
                    $node/(@* except @style),
                    fontane-simple:transform($node/node())
                }                   
191
            else if($node/@type = "initials" or $node/@type = "monogram" 
MRodz's avatar
MRodz committed
192
            or $node/@type = "multiphrase")
193
                then
Michelle Rodzis's avatar
Michelle Rodzis committed
194
                    local:copy-element($node)
195
196
            else if($node/@type = "auction_number" 
            or $node/@type = "cancel"
MRodz's avatar
MRodz committed
197
198
            or $node/@type = "abort"
            or $node/@function ="unknown")
199
200
201
202
                then
                    ()
            else
                fontane-simple:transform($node/node())
MRodz's avatar
MRodz committed
203
204
                    
        case element(tei:hi) return
Michelle Rodzis's avatar
Michelle Rodzis committed
205
            local:copy-element($node)
206
207
        
        case element(tei:anchor) return
Michelle Rodzis's avatar
Michelle Rodzis committed
208
            local:copy-element($node)
209
                        
210
        case element(tei:surface) return 
MRodz's avatar
MRodz committed
211
            if(matches($node/@n, "cover")) then
MRodz's avatar
Fix #23    
MRodz committed
212
                ((if(not($node/@n = "outer_front_cover"))
MRodz's avatar
MRodz committed
213
214
215
216
217
218
219
220
221
222
                    then
                        element tei:pb {
                            if($node/@n = "inner_front_cover" 
                            or $node/@n = "outer_back_cover")
                                then
                                    attribute type {"flyleaf"} 
                                else
                                    attribute type {"cover"}
                        }
                    else
MRodz's avatar
Fix #23    
MRodz committed
223
                        ()),
MRodz's avatar
MRodz committed
224
225
                element tei:div {
                    attribute type {$node/@n},
226
                    $node/(@* except (@facs, @n)),
MRodz's avatar
MRodz committed
227
228
229
230
231
                    fontane-simple:transform($node/node())
                })
            else if(matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")
            and $node/@type = "clipping") then
                (local:make-pb($node),
MRodz's avatar
MRodz committed
232
233
                (if(not($node/@subtype = "Kalenderblatt"
                or $node/@subtype = "Zeitungsausschnitt_Fragment")) then
234
                    local:make-div($node)
MRodz's avatar
MRodz committed
235
236
237
238
239
                else
                    ()))
            else if(matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")
            and $node/@type = "fragment") then
                (local:make-pb($node), 
240
                local:make-div($node)) 
MRodz's avatar
MRodz committed
241
242
            else if(matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")
            and $node/@type = "pocket") then
243
                local:make-pb($node)    
MRodz's avatar
MRodz committed
244
245
246
247
248
249
250
            else if(matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")
            and $node/@type = "label" and $node/@subtype = "Oblate") then
                ()
            else if(matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")) then
                (local:make-pb($node), 
                element tei:div{
                    attribute type {"page"},
251
                    $node/(@* except (@facs, @n)),
MRodz's avatar
MRodz committed
252
253
                    fontane-simple:transform($node/node())
                })
254
            else if($node/@type = "label" and
255
256
257
258
            (contains($node/@subtype, "Fontane")
            or contains($node/@subtype, "Hersteller"))    
            ) then
                local:make-div($node)
MRodz's avatar
MRodz committed
259
260
            else
                ()
MRodz's avatar
MRodz committed
261
262
263
264
265
266
        
        case element(tei:milestone) return
            if($node/@unit = "illustration") then
                ()
            else
                fontane-simple:transform($node/node())
267
268
                    
        case element(tei:gap) return
Michelle Rodzis's avatar
Michelle Rodzis committed
269
            local:copy-element($node)
270
                
271
272
273
274
275
276
        case element(tei:metamark) return
            if($node/@function = "integrate" 
            or $node/@function = "authorial_note") then
                element tei:ab {
                    $node/@*
                }
277
278
279
280
281
282
            else if($node/@function = "placeholder" 
            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
283
284
285
                element tei:ab {
                    attribute type {$node/@function},
                    fontane-simple:transform($node/node())
286
                }            
287
288
            else
                ()
289
290
291
292
293
        
        (: TODO: check if correct :)
        case element(tei:surplus) return
            ()
            
MRodz's avatar
MRodz committed
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
        case element(tei:zone) return
            if(matches($node/@style, "border-style:solid") 
            and not(matches($node/@style, "border-radius"))
            and not($node/@rend = "border-style:house")) then
                element tei:div {
                    attribute type {"frame"},
                    fontane-simple:transform($node/node())
                }
            else if(matches($node/@rend, "border-bottom-style:brace")) then
                (fontane-simple:transform($node/node()),
                element tei:ab {
                    attribute type {"bottom-brace"}
                })                    
            else if($node/@type = "cancel") then
                ()
            else if($node/@type = "marked_off") then
                element tei:seg {
                    $node/@type,
                    $node/@xml:id,
                    fontane-simple:transform($node/node())
                }
MRodz's avatar
MRodz committed
315
316
317
318
319
320
321
            else if($node/@type = "highlighted") then
                if($node/child::tei:zone[@type = "highlighted"]) then
                    fontane-simple:transform($node/node())
                else
                    element tei:hi {
                        attribute type {"vertical-mark"},
                        fontane-simple:transform($node/node())
MRodz's avatar
MRodz committed
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
                    }
            else if($node/@type = "illustration") then
                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
                                attribute rendition {"margin-left:" || $node/@ulx 
                                || "cm; " || "margin-top:" || $node/@uly || "cm"}
                            else
                                ()
                            )
                        ),
                        fontane-simple:transform($node/node())
                    }
                else 
                    ()
            else if($node/parent::tei:zone/@type = "illustration") then
                element {QName("http://www.tei-c.org/ns/1.0", "seg")}{
                    attribute type {"caption"},
                    attribute rendition {"margin-left:" || $node/@ulx || "cm; " 
                        || "margin-top:" || $node/@uly || "cm"},
                    fontane-simple:transform($node/node())
                }
MRodz's avatar
MRodz committed
348
            else if($node/@type = "heading") then
Michelle Rodzis's avatar
Michelle Rodzis committed
349
                local:make-head($node)                 
MRodz's avatar
MRodz committed
350
351
            else if($node/@type = "list" or $node/@type = "item") then
                element {QName("http://www.tei-c.org/ns/1.0", $node/@type)}{
352
                    $node/(@* except (@type, @ulx, @uly, @lrx, @lry, @rotate)),
MRodz's avatar
MRodz committed
353
354
355
356
357
358
359
                    fontane-simple:transform($node/node())
                }            
            else if($node/@type = "legend") then
                element {QName("http://www.tei-c.org/ns/1.0", "div")}{
                    $node/@*,
                    fontane-simple:transform($node/node())
                }            
360
361
362
363
            else if(not($node/@xml:id)) then
                fontane-simple:transform($node/node())
            else if($node/@xml:id and fontane-simple:is-transposed($node)) then
                ()
MRodz's avatar
MRodz committed
364
365
            else
                fontane-simple:transform($node/node())
366
                
MRodz's avatar
MRodz committed
367
        case element(tei:figure) return
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
            if(count($node/child::*) = 1 and $node/child::tei:figDesc) then
                (: genealogy lines probably shouldn't be displayed, but I still have to 
                check that. in case they should be serialized, I leave the code :)
(:                if(matches($node/descendant::tei:ref, "Stammbaumverbindungslinie")) then:)
(:                    element tei:seg {:)
(:                        $node/@*,:)
(:                        fontane-simple:transform($node/node()):)
(:                    }:)
(:                else if(matches($node/descendant::tei:ref, "Schlusslinie")):)
                if(matches($node/descendant::tei:ref, "Schlusslinie"))
                    then
                        element tei:ab {
                            switch ($node/descendant::tei:ref)
                                case "horizontale einfache Schlusslinie" return 
                                    attribute type {"long-end-line"}                                    
                                case "Schlusslinie; horizontale Halbschleife von links oben nach rechts" return 
                                    attribute type {"long-end-line"}
                                case "horizontale einfache Schlusslinie (gewellt)" return 
                                    attribute type {"long-end-line-wavy"}
                                case "Schlusslinien; horizontale Schleife von links oben nach rechts unten" return 
                                    attribute type {"bottom-brace-short"}
                                default return 
                                    attribute type {"end-line"}  
                        }
                else if(matches($node/descendant::tei:ref, "Absatzlinie")
                (: in case of double paragraph lines the single lines are 
                encoded with "oberer" resp. "unterer Teil", but we only 
                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
405
406
407
408
                else if($node/parent::tei:zone[@type = "illustration"]) then
                    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
                        $node/@*
                    }
409
                else
MRodz's avatar
MRodz committed
410
411
                    ()
            else
Michelle Rodzis's avatar
Michelle Rodzis committed
412
                local:copy-element($node)
413
                    
MRodz's avatar
MRodz committed
414
        case element(tei:note) return
415
416
            if($node/@type = "authorial" 
            and not($node/@subtype = "footnote")) then
MRodz's avatar
MRodz committed
417
418
                ()
            else 
Michelle Rodzis's avatar
Michelle Rodzis committed
419
                local:copy-element($node)
MRodz's avatar
MRodz committed
420
421
422
423
424
425
426
427
428
                
        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,
                fontane-simple:transform($node/node())
            }
MRodz's avatar
MRodz committed
429
                    
MRodz's avatar
MRodz committed
430
        case element(tei:figDesc) return
Michelle Rodzis's avatar
Michelle Rodzis committed
431
            local:copy-element($node)
432
            
MRodz's avatar
MRodz committed
433
        case element(tei:ref) return
Michelle Rodzis's avatar
Michelle Rodzis committed
434
            local:copy-element($node)
MRodz's avatar
MRodz committed
435
436
        
        case element(tei:space) return
Michelle Rodzis's avatar
Michelle Rodzis committed
437
            local:copy-element($node)
MRodz's avatar
MRodz committed
438
439
            
        case element(tei:choice) return
Michelle Rodzis's avatar
Michelle Rodzis committed
440
            local:copy-element($node)
MRodz's avatar
MRodz committed
441
442
            
        case element(tei:abbr) return
Michelle Rodzis's avatar
Michelle Rodzis committed
443
            local:copy-element($node)
MRodz's avatar
MRodz committed
444
445
            
        case element(tei:expan) return
Michelle Rodzis's avatar
Michelle Rodzis committed
446
            local:copy-element($node)        
MRodz's avatar
MRodz committed
447
448
            
        case element(tei:rs) return
Michelle Rodzis's avatar
Michelle Rodzis committed
449
            local:copy-element($node)        
MRodz's avatar
MRodz committed
450
451
            
        case element(tei:date) return
452
            element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
453
454
455
                (if($node/@when-iso) then
                    attribute when {$node/@when-iso}
                else 
456
457
458
459
460
                    ()), 
                (if($node/@from-iso) then
                    attribute from {$node/@from-iso}
                else 
                    ()),                    
461
462
463
464
                (if($node/@to-iso) then
                    attribute to {$node/@to-iso}
                else 
                    ()),
465
                $node/(@* except (@when-iso, @to-iso, @from-iso)),
466
467
                fontane-simple:transform($node/node())
            }
468
469
470
471
472
473
            
        case element(tei:ptr) return
            let $target-id := substring-after($node/@target, "#")
            let $target := $node/ancestor::tei:TEI//*[matches(@xml:id, $target-id)]
            let $stripped-target := fontane-simple:strip-element($target)
            return fontane-simple:transform($stripped-target)
MRodz's avatar
MRodz committed
474
            
MRodz's avatar
MRodz committed
475
        default return
476
            fontane-simple:transform($node/node())
MRodz's avatar
MRodz committed
477
478
479
};

(: TODO: adapt to general XML :)
Michelle Rodzis's avatar
Michelle Rodzis committed
480
481
482
483
484
485
486
487
488
489
490
(:~
 : Determines whether the passed tei:handShift is contemporary or not. For the 
 : edited text we only need to consider contemporary hands or additions of 
 : Friedrich Fontane if they occur on labels and on the backside of calendar 
 : pages.
 : 
 : TODO: check if we reach backside of calendar pages at all
 : @author Michelle Rodzis
 : @param $hand the tei:handShift/@new to be checked
 : @return xs:boolean
 : :)
MRodz's avatar
MRodz committed
491
492
493
494
495
496
497
498
499
500
declare function fontane-simple:is-hand-contemporary($hand as xs:string) as xs:boolean {
    let $hand := replace($hand, "#", "")
    let $file := doc("/db/sade-projects/textgrid/data/xml/data/16b00.xml")
    let $handNote := $file//tei:handNote[@xml:id = $hand]
    return 
        if($handNote/@script = "contemporary")
            then
                true()
            else
                false()
501
502
};

Michelle Rodzis's avatar
Michelle Rodzis committed
503
504


505
506
507
508
509
510
511
512
513
514
515
516
517
518
declare function fontane-simple:is-transposed($node as node()) as xs:boolean {
    let $root := $node/ancestor::tei:TEI
    return
        if($root//tei:ptr[contains(@target, $node/@xml:id)]) then
            true()
        else
            false()
};

declare function fontane-simple:strip-element($node as node()) {
    element {$node/name()} {
        $node/@type,
        fontane-simple:transform($node/node())
    }
MRodz's avatar
MRodz committed
519
520
};

Michelle Rodzis's avatar
Michelle Rodzis committed
521
522
523
524
525
526
527
528
529
530
531
532
533

(:~
 : Performs a couple of processing steps on a text node:
 : 
 : 1.   for the edited text only hyphens that are marked with
 :      <tei:lb break="keepHyphen"/> should be displayed
 : 2.   round s (ſ) is normalized to s
 : 
 : @author Michelle Rodzis
 : @param $node the current text node
 : @return text() the formatted text
 : :)
declare function local:prepare-text($node as text()) as text() {
MRodz's avatar
MRodz committed
534
535
536
537
538
539
540
541
542
543
544
    let $cleared-hyphen := 
        if(ends-with($node, "-") and not(local:keep-hyphen($node))) then
            text {functx:substring-before-last($node, "-")}
        else if(ends-with($node, "⸗") and not(local:keep-hyphen($node))) then
            text {functx:substring-before-last($node, "⸗")}
        else
            $node
    let $cleared-round-s := replace($cleared-hyphen, "ſ", "s")
    return text {$cleared-round-s}
};

Michelle Rodzis's avatar
Michelle Rodzis committed
545
546
547
548
549
550
551
552

(:~
 : Checks if a hyphen should be kept for the edited text or not. 
 : 
 : @author Michelle Rodzis
 : @param $node the current text node
 : @return xs:boolean
 : :)
MRodz's avatar
MRodz committed
553
554
555
556
557
558
559
560
declare function local:keep-hyphen($node as text()) as xs:boolean {
    if($node/parent::tei:line/following-sibling::*[1][self::tei:lb[@break = "keepHyphen"]])
        then
            true()
    else
        false()
};

Michelle Rodzis's avatar
Michelle Rodzis committed
561
562
563
564
565
566
567
568
(:~
 : 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 local:copy-element($node as node()) as node() {
MRodz's avatar
MRodz committed
569
570
571
572
    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
        $node/@*,
        fontane-simple:transform($node/node())
    }
MRodz's avatar
MRodz committed
573
574
};

MRodz's avatar
MRodz committed
575
576
577
declare function local:has-valid-text($node as node()) as xs:boolean {
    (: TODO :)
    true()
MRodz's avatar
MRodz committed
578
579
};

Michelle Rodzis's avatar
Michelle Rodzis committed
580
581
582
583
584
585
586
587

(:~
 : Creates a tei:pb.
 : 
 : @author Michelle Rodzis
 : @param $node the current tei:surface node
 : @return element(tei:pb)
 : :)
MRodz's avatar
MRodz committed
588
589
590
591
declare function local:make-pb($node as node()) as element(tei:pb) {
    element {QName("http://www.tei-c.org/ns/1.0", "pb")}{
        $node/@n
    }
MRodz's avatar
MRodz committed
592
593
};

Michelle Rodzis's avatar
Michelle Rodzis committed
594
595
596
597
598
599
600
601
602

(:~
 : Creates a tei:head.
 : 
 : @author Michelle Rodzis
 : @param $node the current tei:line, tei:zone or tei:seg node
 : @return element(tei:head)
 : :)
declare function local:make-head($node as node()) as element(tei:head) {
MRodz's avatar
MRodz committed
603
604
    element tei:head {
        (if($node/descendant::tei:seg[matches(@style, "font-size")]) then
Michelle Rodzis's avatar
Michelle Rodzis committed
605
            attribute type {local:get-font-size($node)}
MRodz's avatar
MRodz committed
606
607
608
609
610
611
612
613
        else 
            attribute type {"default"}
        ),
        $node/@subtype,
        fontane-simple:transform($node/node())
    }
};

Michelle Rodzis's avatar
Michelle Rodzis committed
614
615
616
617
618
619
620
621

(:~
 : Creates a tei:div.
 : 
 : @author Michelle Rodzis
 : @param $node the current tei:surface node
 : @return element(tei:div)
 : :)
622
623
declare function local:make-div($node as node()) as element(tei:div) {
    element tei:div{
MRodz's avatar
Fix #23    
MRodz committed
624
        $node/(@* except (@facs, @n, @attachment, @subtype, @ulx, @uly, @lrx, @lry, @points)),
625
626
627
628
        fontane-simple:transform($node/node())
    }
};

Michelle Rodzis's avatar
Michelle Rodzis committed
629
630
631
632
633
634
635
636
637

(:~
 : Retrieves the font size from the @style of a tei:seg.
 : 
 : @author Michelle Rodzis
 : @param $node the current tei:line, tei:zone or tei:seg node with @type = heading
 : @return xs:string the font size value
 : :)
declare function local:get-font-size($node as node()) as xs:string {
MRodz's avatar
MRodz committed
638
639
640
    (: example for style: "font-size:large; letter-spacing:0.2cm; text-decoration:underline" :)
    let $tmp := substring-after($node/descendant-or-self::tei:seg[matches(@style, "font-size")]/@style, "font-size:")
    return substring-before($tmp, ";")
MRodz's avatar
MRodz committed
641
};