transform2teisimple.xqm 24.8 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
            writer or a change of writing medium :)
            if($node/@new and (fontane-simple:is-hand-contemporary($node/@new) or
158
            ($node/@new = "#Friedrich_Fontane" and $node/ancestor::tei:surface[@type = "label"])) or not($node/@new))
159
                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
212
213
214
                (local:make-pb-with-type($node/@n),
                local:make-div-with-type($node, $node/@n))
            else if(local:is-page($node)
MRodz's avatar
MRodz committed
215
216
            and $node/@type = "clipping") then
                (local:make-pb($node),
MRodz's avatar
MRodz committed
217
218
                (if(not($node/@subtype = "Kalenderblatt"
                or $node/@subtype = "Zeitungsausschnitt_Fragment")) then
219
                    local:make-div($node)
MRodz's avatar
MRodz committed
220
221
                else
                    ()))
222
            else if(local:is-page($node)
MRodz's avatar
MRodz committed
223
224
            and $node/@type = "fragment") then
                (local:make-pb($node), 
225
                local:make-div($node)) 
226
            else if(local:is-page($node)
MRodz's avatar
MRodz committed
227
            and $node/@type = "pocket") then
228
229
                local:make-pb($node) 
            else if(local:is-page($node)) then
MRodz's avatar
MRodz committed
230
                (local:make-pb($node), 
231
                local:make-div-with-type($node, "page"))
232
            else if($node/@type = "label" and
233
234
235
236
            (contains($node/@subtype, "Fontane")
            or contains($node/@subtype, "Hersteller"))    
            ) then
                local:make-div($node)
MRodz's avatar
MRodz committed
237
238
            else
                ()
MRodz's avatar
MRodz committed
239
240
241
242
243
244
        
        case element(tei:milestone) return
            if($node/@unit = "illustration") then
                ()
            else
                fontane-simple:transform($node/node())
245
246
                    
        case element(tei:gap) return
Michelle Rodzis's avatar
Michelle Rodzis committed
247
            local:copy-element($node)
248
                
249
250
251
252
253
254
        case element(tei:metamark) return
            if($node/@function = "integrate" 
            or $node/@function = "authorial_note") then
                element tei:ab {
                    $node/@*
                }
255
256
257
258
259
260
            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
261
262
263
                element tei:ab {
                    attribute type {$node/@function},
                    fontane-simple:transform($node/node())
264
                }            
265
266
            else
                ()
267
268
269
270
271
        
        (: TODO: check if correct :)
        case element(tei:surplus) return
            ()
            
MRodz's avatar
MRodz committed
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
        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
293
294
295
296
297
298
299
            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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
                    }
            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
326
            else if($node/@type = "heading") then
Michelle Rodzis's avatar
Michelle Rodzis committed
327
                local:make-head($node)                 
MRodz's avatar
MRodz committed
328
329
            else if($node/@type = "list" or $node/@type = "item") then
                element {QName("http://www.tei-c.org/ns/1.0", $node/@type)}{
330
                    $node/(@* except (@type, @ulx, @uly, @lrx, @lry, @rotate)),
MRodz's avatar
MRodz committed
331
332
333
334
335
336
337
                    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())
                }            
338
339
340
341
            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
342
343
            else
                fontane-simple:transform($node/node())
344
                
MRodz's avatar
MRodz committed
345
        case element(tei:figure) return
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
            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
383
384
385
386
                else if($node/parent::tei:zone[@type = "illustration"]) then
                    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
                        $node/@*
                    }
387
                else
MRodz's avatar
MRodz committed
388
389
                    ()
            else
Michelle Rodzis's avatar
Michelle Rodzis committed
390
                local:copy-element($node)
391
                    
MRodz's avatar
MRodz committed
392
        case element(tei:note) return
393
394
            if($node/@type = "authorial" 
            and not($node/@subtype = "footnote")) then
MRodz's avatar
MRodz committed
395
396
                ()
            else 
Michelle Rodzis's avatar
Michelle Rodzis committed
397
                local:copy-element($node)
MRodz's avatar
MRodz committed
398
399
400
401
402
403
404
405
406
                
        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
407
                    
MRodz's avatar
MRodz committed
408
        case element(tei:figDesc) return
Michelle Rodzis's avatar
Michelle Rodzis committed
409
            local:copy-element($node)
410
            
MRodz's avatar
MRodz committed
411
        case element(tei:ref) return
Michelle Rodzis's avatar
Michelle Rodzis committed
412
            local:copy-element($node)
MRodz's avatar
MRodz committed
413
414
        
        case element(tei:space) return
Michelle Rodzis's avatar
Michelle Rodzis committed
415
            local:copy-element($node)
MRodz's avatar
MRodz committed
416
417
            
        case element(tei:choice) return
Michelle Rodzis's avatar
Michelle Rodzis committed
418
            local:copy-element($node)
MRodz's avatar
MRodz committed
419
420
            
        case element(tei:abbr) return
Michelle Rodzis's avatar
Michelle Rodzis committed
421
            local:copy-element($node)
MRodz's avatar
MRodz committed
422
423
            
        case element(tei:expan) return
Michelle Rodzis's avatar
Michelle Rodzis committed
424
            local:copy-element($node)        
MRodz's avatar
MRodz committed
425
426
            
        case element(tei:rs) return
Michelle Rodzis's avatar
Michelle Rodzis committed
427
            local:copy-element($node)        
MRodz's avatar
MRodz committed
428
429
            
        case element(tei:date) return
430
            element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
431
432
433
                (if($node/@when-iso) then
                    attribute when {$node/@when-iso}
                else 
434
435
436
437
438
                    ()), 
                (if($node/@from-iso) then
                    attribute from {$node/@from-iso}
                else 
                    ()),                    
439
440
441
442
                (if($node/@to-iso) then
                    attribute to {$node/@to-iso}
                else 
                    ()),
443
                $node/(@* except (@when-iso, @to-iso, @from-iso)),
444
445
                fontane-simple:transform($node/node())
            }
446
447
448
449
450
451
            
        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
452
            
MRodz's avatar
MRodz committed
453
        default return
454
            fontane-simple:transform($node/node())
MRodz's avatar
MRodz committed
455
456
457
};

(: TODO: adapt to general XML :)
Michelle Rodzis's avatar
Michelle Rodzis committed
458
459
460
461
462
463
464
465
466
467
468
(:~
 : 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
 : :)
469
declare function fontane-simple:is-hand-contemporary($hand as xs:string?) as xs:boolean {
MRodz's avatar
MRodz committed
470
471
472
473
474
475
476
477
478
    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()
479
480
};

Michelle Rodzis's avatar
Michelle Rodzis committed
481
482


483
484
485
486
487
488
489
490
491
492
493
494
495
496
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
497
498
};

Michelle Rodzis's avatar
Michelle Rodzis committed
499
500
501
502
503
504
505
506
507
508
509
510

(:~
 : 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
 : :)
511
512
513
514
515
516
517
518
519
520
521
522
523
declare function local:prepare-text($node as text()) as text()? {
    if(local:is-valid-text($node)) then
        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}
    else
        ()
MRodz's avatar
MRodz committed
524
525
};

Michelle Rodzis's avatar
Michelle Rodzis committed
526
527
528
529
530
531
532
533

(:~
 : 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
534
535
536
537
538
539
540
541
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
542
543
544
545
546
547
548
549
(:~
 : 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
550
551
552
553
    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
        $node/@*,
        fontane-simple:transform($node/node())
    }
MRodz's avatar
MRodz committed
554
555
};

556

MRodz's avatar
MRodz committed
557
declare function local:has-valid-text($node as node()) as xs:boolean {
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
    let $text-nodes := $node/descendant::text()
    let $results := 
        for $text-node in $text-nodes
            return 
                local:is-valid-text($text-node)
    return 
        if(functx:is-value-in-sequence(true(), $results)) then
            (true(), console:log("true"))
        else
            false()
};


declare function local:is-valid-text($node as text()) as xs:boolean {
    let $current-hand := $node/preceding::tei:handShift[@new][1]/@new
    return
    if(fontane-simple:is-hand-contemporary($current-hand)
    or $node/ancestor::*[@type = "edited_text"]) then
        true()
    else 
        false()
MRodz's avatar
MRodz committed
579
580
};

Michelle Rodzis's avatar
Michelle Rodzis committed
581

582
583
584
585
declare function local:is-page($node as node()) as xs:boolean {
    matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")
};

Michelle Rodzis's avatar
Michelle Rodzis committed
586
587
588
589
590
591
592
(:~
 : Creates a tei:pb.
 : 
 : @author Michelle Rodzis
 : @param $node the current tei:surface node
 : @return element(tei:pb)
 : :)
MRodz's avatar
MRodz committed
593
594
595
596
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
597
598
};

Michelle Rodzis's avatar
Michelle Rodzis committed
599

600
601
602
603
604
605
606
declare function local: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}
    }
};


Michelle Rodzis's avatar
Michelle Rodzis committed
607
608
609
610
611
612
613
614
(:~
 : 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
615
616
    element tei:head {
        (if($node/descendant::tei:seg[matches(@style, "font-size")]) then
Michelle Rodzis's avatar
Michelle Rodzis committed
617
            attribute type {local:get-font-size($node)}
MRodz's avatar
MRodz committed
618
619
620
621
622
623
624
625
        else 
            attribute type {"default"}
        ),
        $node/@subtype,
        fontane-simple:transform($node/node())
    }
};

Michelle Rodzis's avatar
Michelle Rodzis committed
626
627
628
629
630
631
632
633

(:~
 : Creates a tei:div.
 : 
 : @author Michelle Rodzis
 : @param $node the current tei:surface node
 : @return element(tei:div)
 : :)
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
declare function local:make-div($node as node()) as element(tei:div)? {
    if(local:has-valid-text($node)) then
        element tei:div{
            $node/(@* except (@facs, @n, @attachment, @subtype, @ulx, @uly, @lrx, @lry, @points)),
            fontane-simple:transform($node/node())
        }
    else
        ()
};


declare function local:make-div-with-type($node as node(), $type as xs:string) 
as element(tei:div)? {
    if(local:has-valid-text($node)) then
        element tei:div{
            attribute type {$type},
            $node/(@* except (@facs, @n, @attachment, @subtype, @ulx, @uly, @lrx, @lry, @points)),
            fontane-simple:transform($node/node())
        }    
    else
        ()
655
656
};

Michelle Rodzis's avatar
Michelle Rodzis committed
657
658
659
660
661
662
663
664
665

(:~
 : 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
666
667
668
    (: 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
669
};