tei2teisimple.xqm 43.7 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
 : @author Michelle Weidling
MRodz's avatar
MRodz committed
10
 : @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

MRodz's avatar
MRodz committed
16
declare namespace svg="http://www.w3.org/2000/svg";
MRodz's avatar
MRodz committed
17
declare namespace tei="http://www.tei-c.org/ns/1.0";
MRodz's avatar
MRodz committed
18
declare namespace test="http://exist-db.org/xquery/xqsuite";
MRodz's avatar
MRodz committed
19
declare namespace xlink="http://www.w3.org/1999/xlink";
MRodz's avatar
MRodz committed
20
21

import module namespace console="http://exist-db.org/xquery/console";
mrodzis's avatar
mrodzis committed
22
import module namespace functx="http://www.functx.com";
23
import module namespace simpleHelpers="http://fontane-nb.dariah.eu/teisimplehelpers" at "teisimplehelpers.xqm";
mrodzis's avatar
mrodzis committed
24
import module namespace tbleapi="https://fontane-nb.dariah.eu/tble" at "../tble-api.xqm";
25
import module namespace index-info="http://fontane-nb.dariah.eu/index-info" at "index-info.xqm";
MRodz's avatar
MRodz committed
26

27
(:~
MRodz's avatar
MRodz committed
28
 : The main function initiates the transformation of a given notebook.
29
 :
MRodz's avatar
MRodz committed
30
 : TODO: adapt to several input files?
31
 :
MRodz's avatar
MRodz committed
32
 : :)
33
declare function fontaneSimple:main($doc as node()*, $uri as xs:string) as node()? {
34
35
36
37
38
39
40
(:declare function fontaneSimple:main($file as xs:string) as node()? {:)
(:  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)):)
(:    }:)
41

MRodz's avatar
Fix #23    
MRodz committed
42
43
    let $front-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "front_cover")]
    let $back-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "back_cover")]
mrodzis's avatar
mrodzis committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    let $content := ($doc//tei:sourceDoc/tei:surface[not(contains(@n, "cover")
        or matches(@n, "spine"))], $doc//tei:sourceDoc/tei:note[@type = "editorial"])

    let $tei := 
        <teiCorpus xmlns="http://www.tei-c.org/ns/1.0">
          <TEI id="{$doc//tei:teiHeader//tei:titleStmt/tei:title/string()}">
            {$doc//tei:teiHeader}
            <text>
                <front>{fontaneSimple:transform($front-covers, $uri)}</front>
                <body>{fontaneSimple:transform($content, $uri)}</body>
                <back>{fontaneSimple:transform($back-covers, $uri)}</back>
            </text>
          </TEI>
        </teiCorpus>
58
     let $store := xmldb:store("/db/apps/SADE/resources/xml/", "fontane-tei-tmp.xml", $tei)
MRodz's avatar
MRodz committed
59
    return $tei
MRodz's avatar
MRodz committed
60
61
};

62
(:~
63
64
65
66
67
68
69
70
71
 : 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
72
 : @author Michelle Weidling
73
 : @param $nodes the elements of the book covers and the book content
Michelle Rodzis's avatar
Michelle Rodzis committed
74
 : @return $node()* a TEI simplePrint element
MRodz's avatar
MRodz committed
75
 :)
76
declare function fontaneSimple:transform($nodes as node()*, $uri as xs:string) as node()* {
MRodz's avatar
MRodz committed
77
78
79
    for $node in $nodes
      return
        typeswitch ($node)
MRodz's avatar
MRodz committed
80
        case text() return
MRodz's avatar
MRodz committed
81
82
83
            if($node/ancestor::tei:line
            or $node/ancestor::tei:figDesc
            or $node/ancestor::tei:desc[@type = "edited_text"]
mrodzis's avatar
mrodzis committed
84
85
            or $node/ancestor::tei:note[@type = "editorial"]
            or $node/ancestor::tei:ref[not(matches(@target, "getty") or matches(@target, "xpath"))]) then
86
                if($node/parent::tei:rs and starts-with($node, " ")
mrodzis's avatar
mrodzis committed
87
                and not($node/preceding-sibling::*[1][self::tei:handShift or self::tei:hi])
88
                and simpleHelpers:is-trimming-necessary($node)) then
89
90
91
                    simpleHelpers:prepare-text(text{substring-after($node, " ")})
                else
                    simpleHelpers:prepare-text($node)
MRodz's avatar
MRodz committed
92
93
            else
                ()
94

MRodz's avatar
MRodz committed
95
96
97
        case element(tei:lb) return
            if($node[@break = "keepHyphen"]) then
                ()
98
            else if($node[@break = "no"]) then
99
                fontaneSimple:mark-intervention($node, $uri)
MRodz's avatar
MRodz committed
100
            else
101
                fontaneSimple:copy-element($node, $uri)
102

MRodz's avatar
MRodz committed
103
104
105
106
        case element(tei:g) return
            if($node[@ref = "#vds"]) then
                ()
            else if($node/@ref ="#rth" or $node/@ref ="#hb") then
107
                fontaneSimple:copy-element($node, $uri)
MRodz's avatar
MRodz committed
108
            else
109
                fontaneSimple:transform($node/node(), $uri)
110

MRodz's avatar
MRodz committed
111
112
        case element(tei:del) return
            if($node/parent::tei:restore) then
113
                fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
114
            else if($node/descendant::tei:restore) then
115
                fontaneSimple:transform($node/descendant::tei:restore, $uri)
MRodz's avatar
MRodz committed
116
            else
MRodz's avatar
MRodz committed
117
                ()
118

MRodz's avatar
MRodz committed
119
120
121
122
123
        case element(tei:restore) return
            if(count($node/child::*) = 1 and $node/child::tei:del
            and $node/ancestor::tei:del) then
                ()
            else
124
                fontaneSimple:transform($node/node(), $uri)
125

MRodz's avatar
MRodz committed
126
127
        case element(tei:retrace) return
            if($node/@rend) then
MRodz's avatar
MRodz committed
128
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
129
                    attribute rendition {$node/@rend},
130
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
131
132
                }
            else
133
                fontaneSimple:transform($node/node(), $uri)
134

135
        case element(tei:add) return
136
            if($node/@type = "edited_text"
137
            or $node/child::tei:seg[@type = "multiphrase"]) then
138
                fontaneSimple:copy-element($node, $uri)
139
140
141
142
143
            
            else if($node/@cause = "unclear") then
                ()
                
            else if($node[matches(@copyOf, $node/preceding::tei:seg/@xml:id)]) then
144
                fontaneSimple:mark-intervention($node, $uri)
145
                
146
            else if($node/@cause ="catchword") then
MRodz's avatar
MRodz committed
147
                ()
148
                
MRodz's avatar
MRodz committed
149
            else if($node/@rend ="|") then
150
                fontaneSimple:transform($node/node(), $uri)
151
                
mrodzis's avatar
mrodzis committed
152
153
154
155
156
            else if($node/@place = "above"
            and $node/preceding::node()[1][normalize-space(.) = ""]) then
                (text{" "},
                fontaneSimple:transform($node/node(), $uri))
                
157
158
159
160
            else if($node[@place = "superimposed"]) then
                fontaneSimple:preserve-whitespace($node, $uri)

                
161
            else if(not($node/@xml:id)) then
162
                fontaneSimple:transform($node/node(), $uri)
163
                
164
            else if(simpleHelpers:is-transposed($node)) then
165
166
                let $corresp := //tei:metamark[matches(@target, $node/@xml:id)]
                return
167
168
                    (fontaneSimple:transform($corresp/node(), $uri),
                    fontaneSimple:transform($node/node(), $uri))
169
                    
170
            else
171
                fontaneSimple:transform($node/node(), $uri)
172

173
174
        case element(tei:addSpan) return
            if($node/@type = "edited_text") then
175
                fontaneSimple:copy-element($node, $uri)
176
            else
177
178
                ()

179
180
        case element(tei:fw) return
            ()
181

182
        case element(tei:line) return
Michelle Rodzis's avatar
Michelle Rodzis committed
183
            if($node/@type = "heading") then
184
                fontaneSimple:make-head($node, $uri)
185

186
            else if(simpleHelpers:has-valid-style($node)
187
            or matches($node/@rendition, "black_letter")
188
            or matches($node/@rendition, "roman")) then
189
                fontaneSimple:make-seg-with-rendition($node, $uri)
190
191
                
            else if($node/following::*[1][self::tei:lb[@break = "no"]]) then
192
                (simpleHelpers:start-line($node),
193
                simpleHelpers:trim-last-char($node))
194
195
                
            else if ($node/preceding::*[1][self::tei:lb[@break = "no"]]) then
196
                (simpleHelpers:start-line($node),
197
                simpleHelpers:trim-first-char($node))
198
199
                
            else if($node/@type = "verse") then
MRodz's avatar
MRodz committed
200
201
202
203
204
                if(not($node/@next)) then
                    (if(not($node/preceding-sibling::tei:line[@type = "verse"])) then
                        fontaneSimple:mark-linegroup-beginning()
                    else
                        (),
MRodz's avatar
MRodz committed
205
                    element {QName("http://www.tei-c.org/ns/1.0", "l")} {
206
                            fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
207
208
209
210
211
212
                        },
                    if(not($node/following-sibling::tei:line[@type = "verse"])) then
                        fontaneSimple:mark-linegroup-end()
                    else
                        ())  
                (: 3.8.2.2.1.3 Vers mit anderer Beschriftung in einer Zeile :)
213
                else
MRodz's avatar
MRodz committed
214
215
216
217
                    let $corresp := $node/following::tei:seg[@type = "verse" 
                        and matches($node/@next, @xml:id)]
                    return
                        (fontaneSimple:mark-linegroup-beginning(),
MRodz's avatar
MRodz committed
218
                        element {QName("http://www.tei-c.org/ns/1.0", "l")} {
219
                            fontaneSimple:transform($node/node(), $uri),
MRodz's avatar
MRodz committed
220
                            simpleHelpers:start-line($node),
221
                            fontaneSimple:transform($corresp/node(), $uri)
MRodz's avatar
MRodz committed
222
223
224
225
                        },
                        fontaneSimple:mark-linegroup-end())
                    
            else if($node/parent::tei:zone[@type = "verse"]/child::*[1] = $node) then
226
                fontaneSimple:transform($node/node(), $uri)             
227
                
228
229
230
            (: with opting for a tei:milestone we try to meet the project's
            requirements on the one hand while avoiding to run into hierarchical
            problems in the further processing on the other hand:)
231
            else if(not($node/@type = "item")) then
232
                (simpleHelpers:start-line($node),
233
                fontaneSimple:transform($node/node(), $uri))
234
                
MRodz's avatar
MRodz committed
235
            else if($node/@type = "item") then
MRodz's avatar
MRodz committed
236
                element {QName("http://www.tei-c.org/ns/1.0", "item")} {
MRodz's avatar
MRodz committed
237
                    $node/(@* except (@rend, @type, @style)),
Michelle Rodzis's avatar
Michelle Rodzis committed
238
239
240
241
                    if($node/@rend) then
                        attribute rendition {$node/@rend}
                    else
                        (),
242
                    fontaneSimple:transform($node/node(), $uri)
243
                }
244
                
245
            else
246
                (simpleHelpers:start-line($node),
247
                fontaneSimple:transform($node/node(), $uri))
248

249
        case element(tei:handShift) return
250
            fontaneSimple:enhance-handshift($node)
251

252
        case element(tei:stamp) return
Michelle Rodzis's avatar
Michelle Rodzis committed
253
            if($node/ancestor::tei:surface[matches(@n, "Beilage")]) then
254
                fontaneSimple:copy-element($node, $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
255
256
            else
                ()
257

258
        case element(tei:seg) return
259
            if(count($node/*) = 1 and
Michelle Rodzis's avatar
Michelle Rodzis committed
260
261
262
            (($node/tei:stamp 
                and not($node/ancestor::tei:surface[matches(@n, "Beilage")]))
            or $node/tei:metamark[@function = "caret"]))
263
264
                then
                    ()
265

MRodz's avatar
MRodz committed
266
            else if($node/@type = "heading") then
267
                fontaneSimple:make-head($node, $uri)
268
269

            else if(matches($node/@style, "underline")
270
            and not(matches($node/@style, "vertical-align"))) then
271
                fontaneSimple:transform($node/node(), $uri)
272

273
            else if(simpleHelpers:has-valid-style($node)
274
            or matches($node/@rendition, "black_letter")
275
            or matches($node/@rendition, "roman")) then
276
                fontaneSimple:make-seg-with-rendition($node, $uri)
277
278
279

            else if($node/@type = "initials"
            or $node/@type = "monogram"
MRodz's avatar
MRodz committed
280
281
            or $node/@type = "multiphrase"
            or $node/@xml:lang)
282
                then
mrodzis's avatar
mrodzis committed
283
284
285
286
287
                    (fontaneSimple:copy-element($node, $uri),
                    if($node/@type = "multiphrase") then
                        text{" "}
                    else
                        ())
288
289

            else if($node/@type = "auction_number"
290
            or $node/@type = "cancel"
MRodz's avatar
MRodz committed
291
292
            or $node/@type = "abort"
            or $node/@function ="unknown")
293
294
                then
                    ()
295
296
                    
            else if($node/parent::tei:add and $node/@copyOf) then
297
                fontaneSimple:mark-intervention($node, $uri)
MRodz's avatar
MRodz committed
298
299
300
301
302
303
304
305
306
                
            else if($node/@type = "verse" and $node/@prev) then
                ()
                
            else if($node/@type = "said") then
                if($node/@next) then
                    let $next := replace($node/@next, "#", "")
                    let $corresp := $node/following::*[@xml:id = $next]
                    return
MRodz's avatar
MRodz committed
307
                        (element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
308
                            $node/@type,
309
310
                            fontaneSimple:transform($node/node(), $uri),
                            fontaneSimple:transform($corresp/node(), $uri)
MRodz's avatar
MRodz committed
311
                        },
MRodz's avatar
MRodz committed
312
                        element {QName("http://www.tei-c.org/ns/1.0", "lb")} {
MRodz's avatar
MRodz committed
313
314
315
                            attribute type {"edited_text"}
                        })
                else
MRodz's avatar
MRodz committed
316
                    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
317
                        $node/@type,
318
                        fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
319
                    }
320
321
322
323
324
325
326
327
328
329
            
            else if($node/@type = "item") then
                element {QName("http://www.tei-c.org/ns/1.0", $node/@type)} {
                    $node/(@xml:id, @subtype, @rendition, @prev, @next),
                    if($node/@rend) then
                        attribute rendition {$node/@rend}
                    else
                        (),                    
                    fontaneSimple:transform($node/node(), $uri)
                }
330
331
332
333
334
335
                
            else if($node/@type = "integration") then
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
                    $node/@*,              
                    fontaneSimple:transform($node/node(), $uri)
                }
336

337
            else
338
                fontaneSimple:transform($node/node(), $uri)
339

MRodz's avatar
MRodz committed
340
        case element(tei:hi) return
341
342
343
344
345
346
347
348
349
350
            (element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
                $node/@*,
                fontaneSimple:transform($node/node(), $uri)
            },
            if(not($node/@prev or $node/@next)
            and $node/following::node()[1][self::text()][normalize-space(.) = ""]
            and $node/following::*[1][self::tei:hi]) then
                text{"@"}
            else
                ())
351
352

        (: TODO if $node/@type = "highlighted" then make
353
        a hi[@type = "vertical-mark"] in the second stage of creating the
354
        simple format. use simpleHelpers:get-xml-chunk($node) for this.:)
355
356
        case element(tei:mod) return
            if($node/@type = "highlighted"
357
            and simpleHelpers:is-hand-contemporary($node/@hand)) then
358
                $node
mrodzis's avatar
mrodzis committed
359
            else if($node/following::node()[1][self::text()]) then
360
                fontaneSimple:preserve-whitespace($node, $uri)
361
            else
362
                fontaneSimple:transform($node/node(), $uri)
363

364
        case element(tei:anchor) return
365
            fontaneSimple:copy-element($node, $uri)
366
367

        case element(tei:surface) return
MRodz's avatar
MRodz committed
368
            if(matches($node/@n, "cover")) then
Michelle Rodzis's avatar
Michelle Rodzis committed
369
                (fontaneSimple:make-pb-with-type($node/@n),
370
                fontaneSimple:transform($node/node(), $uri))
Michelle Rodzis's avatar
Michelle Rodzis committed
371
372
                
            else if(matches($node/@n, "Beilage")) then
MRodz's avatar
MRodz committed
373
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
374
                    $node/@*,
375
                    fontaneSimple:transform($node/node(), $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
376
377
378
379
                }
                
            else if($node/@type = "pocket") then
                (fontaneSimple:make-pb($node),
MRodz's avatar
MRodz committed
380
                element {QName("http://www.tei-c.org/ns/1.0", "div")}{
Michelle Rodzis's avatar
Michelle Rodzis committed
381
                    $node/(@* except (@n, @ulx, @uly, @lry, @lrx)),
382
                    fontaneSimple:transform($node/node(), $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
383
                })
Michelle Rodzis's avatar
Michelle Rodzis committed
384
            
385
            else if(simpleHelpers:is-page($node)
MRodz's avatar
MRodz committed
386
            and $node/@type = "clipping") then
387
                (fontaneSimple:make-pb($node),
MRodz's avatar
MRodz committed
388
389
                (if(not($node/@subtype = "Kalenderblatt"
                or $node/@subtype = "Zeitungsausschnitt_Fragment")) then
MRodz's avatar
MRodz committed
390
                    element {QName("http://www.tei-c.org/ns/1.0", "div")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
391
                        $node/(@* except (@n, @ulx, @uly, @lry, @lrx)),
392
                        fontaneSimple:transform($node/node(), $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
393
                    }
MRodz's avatar
MRodz committed
394
395
                else
                    ()))
Michelle Rodzis's avatar
Michelle Rodzis committed
396
            
397
            else if(simpleHelpers:is-page($node)) then
398
                (fontaneSimple:make-pb($node),
399
                fontaneSimple:transform($node/node(), $uri))
Michelle Rodzis's avatar
Michelle Rodzis committed
400
            
401
            else if($node/@type = "label" and
402
            (contains($node/@subtype, "Fontane")
403
            or contains($node/@subtype, "Hersteller"))
404
            ) then
405
                fontaneSimple:make-div($node, $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
406
            
MRodz's avatar
MRodz committed
407
408
            else
                ()
409

MRodz's avatar
MRodz committed
410
411
412
413
        case element(tei:milestone) return
            if($node/@unit = "illustration") then
                ()
            else
414
                fontaneSimple:copy-element($node, $uri)
415

416
        case element(tei:gap) return
417
            fontaneSimple:copy-element($node, $uri)
418

419
        case element(tei:metamark) return
420
            if($node/@function = "integrate"
421
            or $node/@function = "authorial_note") then
MRodz's avatar
MRodz committed
422
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
423
424
                    $node/@*
                }
425
            else if($node/@function = "placeholder"
426
427
            or $node/@function ="etc."
            or $node/@function ="caret"
MRodz's avatar
MRodz committed
428
            or $node/@function = "footnote-mark"
429
430
431
            or $node/@function ="footnotes"
            or $node/@function ="ellipsis"
            or $node/@function = "paragraph") then
MRodz's avatar
MRodz committed
432
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
MRodz's avatar
MRodz committed
433
                    attribute type {$node/@function},
434
                    fontaneSimple:transform($node/node(), $uri)
435
                }
436
437
            else
                ()
438

439
        case element(tei:surplus) return
440
            fontaneSimple:mark-intervention($node, $uri)
441

MRodz's avatar
MRodz committed
442
        case element(tei:zone) return
443
            if(matches($node/@style, "border-style:solid")
MRodz's avatar
MRodz committed
444
445
            and not(matches($node/@style, "border-radius"))
            and not($node/@rend = "border-style:house")) then
MRodz's avatar
MRodz committed
446
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
MRodz's avatar
MRodz committed
447
                    attribute type {"frame"},
448
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
449
                }
450

MRodz's avatar
MRodz committed
451
            else if(matches($node/@rend, "border-bottom-style:brace")) then
452
                (fontaneSimple:transform($node/node(), $uri),
MRodz's avatar
MRodz committed
453
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
MRodz's avatar
MRodz committed
454
                    attribute type {"bottom-brace"}
455
456
                })

MRodz's avatar
MRodz committed
457
458
            else if($node/@type = "cancel") then
                ()
459

MRodz's avatar
MRodz committed
460
            else if($node/@type = "marked_off") then
MRodz's avatar
MRodz committed
461
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
462
463
                    $node/@type,
                    $node/@xml:id,
464
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
465
                }
466

MRodz's avatar
MRodz committed
467
468
            else if($node/@type = "highlighted") then
                if($node/child::tei:zone[@type = "highlighted"]) then
469
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
470
                else
MRodz's avatar
MRodz committed
471
                    element {QName("http://www.tei-c.org/ns/1.0", "hi")} {
MRodz's avatar
MRodz committed
472
                        attribute type {"vertical-mark"},
473
                        fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
474
                    }
475

476
477
            else if($node/@type = "illustration"
            or $node/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
478
                if(not($node//tei:figure/parent::tei:del)) then
MRodz's avatar
MRodz committed
479
                    element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
MRodz's avatar
MRodz committed
480
481
482
483
484
                        (if($node/child::tei:zone[@type = "illustration"]) then
                            attribute type {"composed-sketch"}
                        else
                            (attribute type {"sketch"},
                            if($node/parent::tei:zone[@type = "illustration"]) then
485
                                attribute rendition {"margin-left:" || $node/@ulx
MRodz's avatar
MRodz committed
486
487
488
489
490
                                || "cm; " || "margin-top:" || $node/@uly || "cm"}
                            else
                                ()
                            )
                        ),
491
                        fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
492
                    }
493
                else
MRodz's avatar
MRodz committed
494
                    ()
495

496
497
            else if($node/parent::tei:zone/@type = "illustration"
            or $node/parent::tei:zone/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
498
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
499
                    attribute type {"caption"},
500
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
501
                }
502

MRodz's avatar
MRodz committed
503
            else if($node/@type = "heading") then
504
                fontaneSimple:make-head($node, $uri)
505

506
507
            else if($node/@type = "list" 
            or $node/@type = "item") then
508
                element {QName("http://www.tei-c.org/ns/1.0", $node/@type)} {
Michelle Rodzis's avatar
Michelle Rodzis committed
509
510
511
512
513
                    $node/(@xml:id, @subtype, @rendition, @prev, @next),
                    if($node/@rend) then
                        attribute rendition {$node/@rend}
                    else
                        (),                    
514
                    fontaneSimple:transform($node/node(), $uri)
515
                }
Michelle Rodzis's avatar
Michelle Rodzis committed
516
                
MRodz's avatar
MRodz committed
517
            else if($node/@type = "dialogue") then
MRodz's avatar
MRodz committed
518
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
MRodz's avatar
MRodz committed
519
                    $node/@type,
520
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
521
522
523
524
                }
                
            else if($node/@type = "verse") then
                (fontaneSimple:mark-linegroup-beginning(),
MRodz's avatar
MRodz committed
525
                element {QName("http://www.tei-c.org/ns/1.0", "l")} {
526
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
527
528
529
530
531
532
533
                },
                fontaneSimple:mark-linegroup-end())
                
            else if($node/@type = "said" and $node/@prev) then
                ()
                
            else if($node/@type = "said") then
MRodz's avatar
MRodz committed
534
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
535
                    $node/@type,
536
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
537
538
                }
                
MRodz's avatar
MRodz committed
539
540
541
542
            else if($node/@type = "toc" 
            and matches($node/@subtype, "ungültig")) then
                ()
                
Michelle Rodzis's avatar
Michelle Rodzis committed
543
            else if($node/@type = "toc") then
544
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
545
                    $node/(@type, @subtype),
546
                    fontaneSimple:transform($node/node(), $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
547
                }
548

MRodz's avatar
MRodz committed
549
            else if($node/@type = "legend") then
MRodz's avatar
MRodz committed
550
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
551
                    (if($node/@style
552
553
554
555
556
                    or $node/@rendition) then
                        attribute rendition {simpleHelpers:filter-rendition($node)}
                    else
                        ()),
                    $node/(@* except (@rendition, @style)),
557
                    fontaneSimple:transform($node/node(), $uri)
558
                }
Michelle Rodzis's avatar
Michelle Rodzis committed
559
560
                
            else if($node/@type = "additional") then
MRodz's avatar
MRodz committed
561
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
562
                    $node/(@* except (@ulx, @uly, @lry, @lrx)),
563
                    fontaneSimple:transform($node/node(), $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
564
                }
565

566
            else if(simpleHelpers:has-valid-style($node)
567
            or matches($node/@rendition, "black_letter")
568
            or matches($node/@rendition, "script")
569
            or matches($node/@rendition, "roman")) then
570
                fontaneSimple:make-seg-with-rendition($node, $uri)
571

572
            else if(not($node/@xml:id)) then
573
                fontaneSimple:transform($node/node(), $uri)
574

575
            else if($node/@xml:id) then
mrodzis's avatar
mrodzis committed
576
577
578
579
                (
(:                    if($node/@xml:id = "C06_14r_9") then:)
(:                    util:log-system-out($node):)
(:                else (),:)
MRodz's avatar
MRodz committed
580
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
581
582
583
584
                    $node/@xml:id,
                    $node/@prev,
                    $node/@next,
                    $node/@corresp,
585
                    fontaneSimple:transform($node/node(), $uri)
586
                })
587

MRodz's avatar
MRodz committed
588
            else
589
                fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
590
591
                
        case element(tei:said) return
MRodz's avatar
MRodz committed
592
            (element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
593
                attribute type {"said"},
594
                fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
595
596
            },
            if($node/ancestor::tei:zone[@type = "dialogue"]/descendant::tei:said[position() != last()] = $node) then
MRodz's avatar
MRodz committed
597
                element {QName("http://www.tei-c.org/ns/1.0", "lb")} {
MRodz's avatar
MRodz committed
598
599
600
601
                        attribute type {"edited_text"}
                }
            else
                ())
602

MRodz's avatar
MRodz committed
603
        case element(tei:figure) return
604
            if(count($node/child::*) = 1 and $node/child::tei:figDesc) then
605
                (: genealogy lines probably shouldn't be displayed, but I still have to
606
607
                check that. in case they should be serialized, I leave the code :)
(:                if(matches($node/descendant::tei:ref, "Stammbaumverbindungslinie")) then:)
MRodz's avatar
MRodz committed
608
(:                    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {:)
609
(:                        $node/@*,:)
610
(:                        fontaneSimple:transform($node/node(), $uri):)
611
612
613
614
(:                    }:)
(:                else if(matches($node/descendant::tei:ref, "Schlusslinie")):)
                if(matches($node/descendant::tei:ref, "Schlusslinie"))
                    then
MRodz's avatar
MRodz committed
615
                        element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
616
                            switch ($node/descendant::tei:ref)
617
618
619
                                case "horizontale einfache Schlusslinie" return
                                    attribute type {"long-end-line"}
                                case "Schlusslinie; horizontale Halbschleife von links oben nach rechts" return
620
                                    attribute type {"long-end-line"}
621
                                case "horizontale einfache Schlusslinie (gewellt)" return
622
                                    attribute type {"long-end-line-wavy"}
623
                                case "Schlusslinien; horizontale Schleife von links oben nach rechts unten" return
624
                                    attribute type {"bottom-brace-short"}
625
626
                                default return
                                    attribute type {"end-line"}
627
628
                        }
                else if(matches($node/descendant::tei:ref, "Absatzlinie")
629
630
                (: in case of double paragraph lines the single lines are
                encoded with "oberer" resp. "unterer Teil", but we only
631
632
633
                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
MRodz's avatar
MRodz committed
634
                    element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
635
636
637
638
639
640
                        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
641
                else if($node/ancestor::tei:zone[@type = "illustration"]) then
642
                    (element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
Michelle Rodzis's avatar
Michelle Rodzis committed
643
                        $node/@*,
644
                        attribute href {tbleapi:get-url($uri, $node/@xml:id, "png")},
645
                        fontaneSimple:transform($node/node(), $uri)
646
                    })
647
                else
MRodz's avatar
MRodz committed
648
649
                    ()
            else
650
                fontaneSimple:copy-element($node, $uri)
651

MRodz's avatar
MRodz committed
652
        case element(tei:note) return
653
            if($node/@type = "authorial"
654
            and not($node/@subtype = "footnote")) then
MRodz's avatar
MRodz committed
655
                ()
656
            else
mrodzis's avatar
mrodzis committed
657
                fontaneSimple:copy-element($node, $uri)
658

MRodz's avatar
MRodz committed
659
        case element(tei:certainty) return
MRodz's avatar
MRodz committed
660
            element {QName("http://www.tei-c.org/ns/1.0", "note")} {
MRodz's avatar
MRodz committed
661
662
663
664
                attribute type {"editorial"},
                attribute subtype {"certainty"},
                $node/@cert,
                $node/@target,
665
                fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
666
            }
667

MRodz's avatar
MRodz committed
668
        case element(tei:figDesc) return
669
            fontaneSimple:copy-element($node, $uri)
670

MRodz's avatar
MRodz committed
671
        case element(tei:ref) return
672
            fontaneSimple:copy-element($node, $uri)
673

MRodz's avatar
MRodz committed
674
        case element(tei:space) return
675
            fontaneSimple:copy-element($node, $uri)
676

MRodz's avatar
MRodz committed
677
        case element(tei:choice) return
678
            fontaneSimple:copy-element($node, $uri)
679

MRodz's avatar
MRodz committed
680
        case element(tei:abbr) return
681
            fontaneSimple:copy-element($node, $uri)
682

MRodz's avatar
MRodz committed
683
        case element(tei:expan) return
684
            fontaneSimple:copy-element($node, $uri)
685
686
            
        case element(tei:sic) return
687
            fontaneSimple:copy-element($node, $uri)     
688
689
            
        case element(tei:corr) return
690
            fontaneSimple:copy-element($node, $uri)
691

MRodz's avatar
MRodz committed
692
        case element(tei:rs) return
MRodz's avatar
MRodz committed
693
694
            let $index-type := substring-before($node/@ref, ":")
            return
mrodzis's avatar
mrodzis committed
695
696
697
698
699
700
701
                (: ignore tei:rs elements that are empty after presorting. this
                is important because they would cause a lot of whitespace trouble
                otherwise :)
                if($node//text()[matches(., "[\w]")]) then
                    (element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
                        $node/@*,
                        fontaneSimple:make-index-infos($node, $index-type),
702
                        fontaneSimple:transform($node/node(), $uri)
mrodzis's avatar
mrodzis committed
703
                    },
mrodzis's avatar
mrodzis committed
704
                    if(not($node//tei:abbr/text()[ends-with(., ":")]
705
                    or ($node//text()[last()][ends-with(., "-")] or$node/following-sibling::*[1][self::tei:rs])
mrodzis's avatar
mrodzis committed
706
                    or $node/following::node()[1][self::text()][starts-with(., "-") or starts-with(., ".")])) then
mrodzis's avatar
mrodzis committed
707
708
709
                        text{" "}
                    else
                        ())
mrodzis's avatar
mrodzis committed
710
711
                else
                    ()
712

MRodz's avatar
MRodz committed
713
        case element(tei:date) return
MRodz's avatar
MRodz committed
714
            element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
715
716
                (if($node/@when-iso) then
                    attribute when {$node/@when-iso}
717
718
                else
                    ()),
719
720
                (if($node/@from-iso) then
                    attribute from {$node/@from-iso}
721
722
                else
                    ()),
723
724
                (if($node/@to-iso) then
                    attribute to {$node/@to-iso}
Michelle Rodzis's avatar
Michelle Rodzis committed
725
                else
726
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
727
728
                (if($node/@notAfter-iso) then
                    attribute notAfter {$node/@notAfter-iso}
729
                else
730
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
731
                $node/(@* except (@when-iso, @to-iso, @from-iso, @notAfter-iso)),
732
                fontaneSimple:transform($node/node(), $uri)
733
            }
734

735
        case element(tei:ptr) return
736
            ()
737

MRodz's avatar
MRodz committed
738
        default return
739
            fontaneSimple:transform($node/node(), $uri)
740
};
741
742
743
744

(:~
 : Takes a given element over as is since it is compliant to TEI simplePrint.
 :
MRodz's avatar
MRodz committed
745
 : @author Michelle Weidling
746
747
748
 : @param $node the current text node
 : @return node() a copy of the current node
 :)
749
declare function fontaneSimple:copy-element($node as node(), $uri as xs:string) as node() {
mrodzis's avatar
mrodzis committed
750
751
752
753
(:    if($node[self::tei:note]) then:)
(:        util:log-system-out($node):)
(:    else:)
(:        (),:)
754
    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
Michelle Rodzis's avatar
Michelle Rodzis committed
755
756
757
758
759
        $node/(@* except @rend),
        if($node/@rend) then
            attribute rendition {$node/@rend}
        else
            (),
760
        fontaneSimple:transform($node/node(), $uri)
761
762
763
764
765
766
    }
};

(:~
 : Creates a tei:head with an @rendition and a font-size, if available.
 :
MRodz's avatar
MRodz committed
767
 : @author Michelle Weidling
768
769
770
 : @param $node the current tei:line, tei:zone or tei:seg node
 : @return element(tei:head)
 : :)
771
declare function fontaneSimple:make-head($node as node(), $uri as xs:string) as element(tei:head) {
MRodz's avatar
MRodz committed
772
    element {QName("http://www.tei-c.org/ns/1.0", "head")} {
773
        (if($node/descendant::tei:seg[matches(@style, "font-size")]) then
MRodz's avatar
MRodz committed
774
            attribute style {simpleHelpers:get-font-size($node)}
775
        else
MRodz's avatar
MRodz committed
776
            attribute style {"default"}
777
778
779
780
781
        ),
        $node/@subtype,
        (if($node/@rendition) then
            $node/@rendition
        else
MRodz's avatar
MRodz committed
782
783
784
785
786
            ()),         
        (if($node/@rend) then
            $node/@rend
        else
            ()),        
787