tei2teisimple.xqm 39.8 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")]
44
    let $content := $doc//tei:sourceDoc/tei:surface[not(contains(@n, "cover")
MRodz's avatar
MRodz committed
45
        or matches(@n, "spine"))]
46

47
    let $tei := <TEI xmlns="http://www.tei-c.org/ns/1.0">
MRodz's avatar
MRodz committed
48
        {$doc//tei:teiHeader}
MRodz's avatar
MRodz committed
49
        <text>
50
51
52
            <front>{fontaneSimple:transform($front-covers, $uri)}</front>
            <body>{fontaneSimple:transform($content, $uri)}</body>
            <back>{fontaneSimple:transform($back-covers, $uri)}</back>
MRodz's avatar
MRodz committed
53
        </text>
MRodz's avatar
MRodz committed
54
      </TEI>
55
     let $store := xmldb:store("/db/apps/SADE/resources/xml/", "fontane-tei-tmp.xml", $tei)
MRodz's avatar
MRodz committed
56
    return $tei
MRodz's avatar
MRodz committed
57
58
};

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

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

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

MRodz's avatar
MRodz committed
107
108
        case element(tei:del) return
            if($node/parent::tei:restore) then
109
                fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
110
            else if($node/descendant::tei:restore) then
111
                fontaneSimple:transform($node/descendant::tei:restore, $uri)
MRodz's avatar
MRodz committed
112
            else
MRodz's avatar
MRodz committed
113
                ()
114

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

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

131
        case element(tei:add) return
132
            (if($node/@type = "edited_text"
133
            or $node/child::tei:seg[@type = "multiphrase"]) then
134
                fontaneSimple:copy-element($node, $uri)
135
136
137
138
139
            
            else if($node/@cause = "unclear") then
                ()
                
            else if($node[matches(@copyOf, $node/preceding::tei:seg/@xml:id)]) then
140
                fontaneSimple:mark-intervention($node, $uri)
141
                
142
            else if($node/@cause ="catchword") then
MRodz's avatar
MRodz committed
143
                ()
144
                
MRodz's avatar
MRodz committed
145
            else if($node/@rend ="|") then
146
                fontaneSimple:transform($node/node(), $uri)
147
                
148
            else if(not($node/@xml:id)) then
149
                fontaneSimple:transform($node/node(), $uri)
150
                
151
            else if(simpleHelpers:is-transposed($node)) then
152
153
                let $corresp := //tei:metamark[matches(@target, $node/@xml:id)]
                return
154
155
                    (fontaneSimple:transform($corresp/node(), $uri),
                    fontaneSimple:transform($node/node(), $uri))
156
                    
157
            else
158
                fontaneSimple:transform($node/node(), $uri))
159

160
161
        case element(tei:addSpan) return
            if($node/@type = "edited_text") then
162
                fontaneSimple:copy-element($node, $uri)
163
            else
164
165
                ()

166
167
        case element(tei:fw) return
            ()
168

169
        case element(tei:line) return
Michelle Rodzis's avatar
Michelle Rodzis committed
170
            if($node/@type = "heading") then
171
                fontaneSimple:make-head($node, $uri)
172

173
            else if(simpleHelpers:has-valid-style($node)
174
            or matches($node/@rendition, "black_letter")
175
            or matches($node/@rendition, "roman")) then
176
                fontaneSimple:make-seg-with-rendition($node, $uri)
177
178
                
            else if($node/following::*[1][self::tei:lb[@break = "no"]]) then
179
                (simpleHelpers:start-line($node),
180
                simpleHelpers:trim-last-char($node))
181
182
                
            else if ($node/preceding::*[1][self::tei:lb[@break = "no"]]) then
183
                (simpleHelpers:start-line($node),
184
                simpleHelpers:trim-first-char($node))
185
186
                
            else if($node/@type = "verse") then
MRodz's avatar
MRodz committed
187
188
189
190
191
                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
192
                    element {QName("http://www.tei-c.org/ns/1.0", "l")} {
193
                            fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
194
195
196
197
198
199
                        },
                    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 :)
200
                else
MRodz's avatar
MRodz committed
201
202
203
204
                    let $corresp := $node/following::tei:seg[@type = "verse" 
                        and matches($node/@next, @xml:id)]
                    return
                        (fontaneSimple:mark-linegroup-beginning(),
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
                            simpleHelpers:start-line($node),
208
                            fontaneSimple:transform($corresp/node(), $uri)
MRodz's avatar
MRodz committed
209
210
211
212
                        },
                        fontaneSimple:mark-linegroup-end())
                    
            else if($node/parent::tei:zone[@type = "verse"]/child::*[1] = $node) then
213
                fontaneSimple:transform($node/node(), $uri)             
214
                
215
216
217
            (: 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:)
218
            else if(not($node/@type = "item")) then
219
                (simpleHelpers:start-line($node),
220
                fontaneSimple:transform($node/node(), $uri))
221
                
MRodz's avatar
MRodz committed
222
            else if($node/@type = "item") then
MRodz's avatar
MRodz committed
223
                element {QName("http://www.tei-c.org/ns/1.0", "item")} {
MRodz's avatar
MRodz committed
224
                    $node/(@* except (@rend, @type, @style)),
Michelle Rodzis's avatar
Michelle Rodzis committed
225
226
227
228
                    if($node/@rend) then
                        attribute rendition {$node/@rend}
                    else
                        (),
229
                    fontaneSimple:transform($node/node(), $uri)
230
                }
231
                
232
            else
233
                (simpleHelpers:start-line($node),
234
                fontaneSimple:transform($node/node(), $uri))
235

236
        case element(tei:handShift) return
237
            fontaneSimple:enhance-handshift($node)
238

239
        case element(tei:stamp) return
Michelle Rodzis's avatar
Michelle Rodzis committed
240
            if($node/ancestor::tei:surface[matches(@n, "Beilage")]) then
241
                fontaneSimple:copy-element($node, $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
242
243
            else
                ()
244

245
        case element(tei:seg) return
246
            if(count($node/*) = 1 and
Michelle Rodzis's avatar
Michelle Rodzis committed
247
248
249
            (($node/tei:stamp 
                and not($node/ancestor::tei:surface[matches(@n, "Beilage")]))
            or $node/tei:metamark[@function = "caret"]))
250
251
                then
                    ()
252

MRodz's avatar
MRodz committed
253
            else if($node/@type = "heading") then
254
                fontaneSimple:make-head($node, $uri)
255
256

            else if(matches($node/@style, "underline")
257
            and not(matches($node/@style, "vertical-align"))) then
258
                fontaneSimple:transform($node/node(), $uri)
259

260
            else if(simpleHelpers:has-valid-style($node)
261
            or matches($node/@rendition, "black_letter")
262
            or matches($node/@rendition, "roman")) then
263
                fontaneSimple:make-seg-with-rendition($node, $uri)
264
265
266

            else if($node/@type = "initials"
            or $node/@type = "monogram"
MRodz's avatar
MRodz committed
267
268
            or $node/@type = "multiphrase"
            or $node/@xml:lang)
269
                then
270
                    fontaneSimple:copy-element($node, $uri)
271
272

            else if($node/@type = "auction_number"
273
            or $node/@type = "cancel"
MRodz's avatar
MRodz committed
274
275
            or $node/@type = "abort"
            or $node/@function ="unknown")
276
277
                then
                    ()
278
279
                    
            else if($node/parent::tei:add and $node/@copyOf) then
280
                fontaneSimple:mark-intervention($node, $uri)
MRodz's avatar
MRodz committed
281
282
283
284
285
286
287
288
289
                
            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
290
                        (element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
291
                            $node/@type,
292
293
                            fontaneSimple:transform($node/node(), $uri),
                            fontaneSimple:transform($corresp/node(), $uri)
MRodz's avatar
MRodz committed
294
                        },
MRodz's avatar
MRodz committed
295
                        element {QName("http://www.tei-c.org/ns/1.0", "lb")} {
MRodz's avatar
MRodz committed
296
297
298
                            attribute type {"edited_text"}
                        })
                else
MRodz's avatar
MRodz committed
299
                    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
300
                        $node/@type,
301
                        fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
302
                    }
303
304
305
306
307
308
309
310
311
312
            
            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)
                }
313

314
            else
315
                fontaneSimple:transform($node/node(), $uri)
316

MRodz's avatar
MRodz committed
317
        case element(tei:hi) return
318
            fontaneSimple:copy-element($node, $uri)
319
320

        (: TODO if $node/@type = "highlighted" then make
321
        a hi[@type = "vertical-mark"] in the second stage of creating the
322
        simple format. use simpleHelpers:get-xml-chunk($node) for this.:)
323
324
        case element(tei:mod) return
            if($node/@type = "highlighted"
325
            and simpleHelpers:is-hand-contemporary($node/@hand)) then
326
                $node
mrodzis's avatar
mrodzis committed
327
328
329
330
331
332
333
334
            else if($node/following::node()[1][self::text()]) then
                let $first-char := $node/following::node()[1][self::text()]
                    => substring(1, 1)
                return
                    if(matches($first-char, "[\s]")) then
                        (fontaneSimple:transform($node/node(), $uri), text{" "})
                    else
                        fontaneSimple:transform($node/node(), $uri)
335
            else
336
                fontaneSimple:transform($node/node(), $uri)
337

338
        case element(tei:anchor) return
339
            fontaneSimple:copy-element($node, $uri)
340
341

        case element(tei:surface) return
MRodz's avatar
MRodz committed
342
            if(matches($node/@n, "cover")) then
Michelle Rodzis's avatar
Michelle Rodzis committed
343
                (fontaneSimple:make-pb-with-type($node/@n),
344
                fontaneSimple:transform($node/node(), $uri))
Michelle Rodzis's avatar
Michelle Rodzis committed
345
346
                
            else if(matches($node/@n, "Beilage")) then
MRodz's avatar
MRodz committed
347
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
348
                    $node/@*,
349
                    fontaneSimple:transform($node/node(), $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
350
351
352
353
                }
                
            else if($node/@type = "pocket") then
                (fontaneSimple:make-pb($node),
MRodz's avatar
MRodz committed
354
                element {QName("http://www.tei-c.org/ns/1.0", "div")}{
Michelle Rodzis's avatar
Michelle Rodzis committed
355
                    $node/(@* except (@n, @ulx, @uly, @lry, @lrx)),
356
                    fontaneSimple:transform($node/node(), $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
357
                })
Michelle Rodzis's avatar
Michelle Rodzis committed
358
            
359
            else if(simpleHelpers:is-page($node)
MRodz's avatar
MRodz committed
360
            and $node/@type = "clipping") then
361
                (fontaneSimple:make-pb($node),
MRodz's avatar
MRodz committed
362
363
                (if(not($node/@subtype = "Kalenderblatt"
                or $node/@subtype = "Zeitungsausschnitt_Fragment")) then
MRodz's avatar
MRodz committed
364
                    element {QName("http://www.tei-c.org/ns/1.0", "div")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
365
                        $node/(@* except (@n, @ulx, @uly, @lry, @lrx)),
366
                        fontaneSimple:transform($node/node(), $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
367
                    }
MRodz's avatar
MRodz committed
368
369
                else
                    ()))
Michelle Rodzis's avatar
Michelle Rodzis committed
370
            
371
            else if(simpleHelpers:is-page($node)) then
372
                (fontaneSimple:make-pb($node),
373
                fontaneSimple:transform($node/node(), $uri))
Michelle Rodzis's avatar
Michelle Rodzis committed
374
            
375
            else if($node/@type = "label" and
376
            (contains($node/@subtype, "Fontane")
377
            or contains($node/@subtype, "Hersteller"))
378
            ) then
379
                fontaneSimple:make-div($node, $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
380
            
MRodz's avatar
MRodz committed
381
382
            else
                ()
383

MRodz's avatar
MRodz committed
384
385
386
387
        case element(tei:milestone) return
            if($node/@unit = "illustration") then
                ()
            else
388
                fontaneSimple:copy-element($node, $uri)
389

390
        case element(tei:gap) return
391
            fontaneSimple:copy-element($node, $uri)
392

393
        case element(tei:metamark) return
394
            if($node/@function = "integrate"
395
            or $node/@function = "authorial_note") then
MRodz's avatar
MRodz committed
396
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
397
398
                    $node/@*
                }
399
            else if($node/@function = "placeholder"
400
401
            or $node/@function ="etc."
            or $node/@function ="caret"
MRodz's avatar
MRodz committed
402
            or $node/@function = "footnote-mark"
403
404
405
            or $node/@function ="footnotes"
            or $node/@function ="ellipsis"
            or $node/@function = "paragraph") then
MRodz's avatar
MRodz committed
406
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
MRodz's avatar
MRodz committed
407
                    attribute type {$node/@function},
408
                    fontaneSimple:transform($node/node(), $uri)
409
                }
410
411
            else
                ()
412

413
        case element(tei:surplus) return
414
            fontaneSimple:mark-intervention($node, $uri)
415

MRodz's avatar
MRodz committed
416
        case element(tei:zone) return
417
            if(matches($node/@style, "border-style:solid")
MRodz's avatar
MRodz committed
418
419
            and not(matches($node/@style, "border-radius"))
            and not($node/@rend = "border-style:house")) then
MRodz's avatar
MRodz committed
420
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
MRodz's avatar
MRodz committed
421
                    attribute type {"frame"},
422
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
423
                }
424

MRodz's avatar
MRodz committed
425
            else if(matches($node/@rend, "border-bottom-style:brace")) then
426
                (fontaneSimple:transform($node/node(), $uri),
MRodz's avatar
MRodz committed
427
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
MRodz's avatar
MRodz committed
428
                    attribute type {"bottom-brace"}
429
430
                })

MRodz's avatar
MRodz committed
431
432
            else if($node/@type = "cancel") then
                ()
433

MRodz's avatar
MRodz committed
434
            else if($node/@type = "marked_off") then
MRodz's avatar
MRodz committed
435
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
436
437
                    $node/@type,
                    $node/@xml:id,
438
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
439
                }
440

MRodz's avatar
MRodz committed
441
442
            else if($node/@type = "highlighted") then
                if($node/child::tei:zone[@type = "highlighted"]) then
443
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
444
                else
MRodz's avatar
MRodz committed
445
                    element {QName("http://www.tei-c.org/ns/1.0", "hi")} {
MRodz's avatar
MRodz committed
446
                        attribute type {"vertical-mark"},
447
                        fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
448
                    }
449

450
451
            else if($node/@type = "illustration"
            or $node/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
452
                if(not($node//tei:figure/parent::tei:del)) then
MRodz's avatar
MRodz committed
453
                    element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
MRodz's avatar
MRodz committed
454
455
456
457
458
                        (if($node/child::tei:zone[@type = "illustration"]) then
                            attribute type {"composed-sketch"}
                        else
                            (attribute type {"sketch"},
                            if($node/parent::tei:zone[@type = "illustration"]) then
459
                                attribute rendition {"margin-left:" || $node/@ulx
MRodz's avatar
MRodz committed
460
461
462
463
464
                                || "cm; " || "margin-top:" || $node/@uly || "cm"}
                            else
                                ()
                            )
                        ),
465
                        fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
466
                    }
467
                else
MRodz's avatar
MRodz committed
468
                    ()
469

470
471
            else if($node/parent::tei:zone/@type = "illustration"
            or $node/parent::tei:zone/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
472
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
473
                    attribute type {"caption"},
474
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
475
                }
476

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

480
481
            else if($node/@type = "list" 
            or $node/@type = "item") then
482
                element {QName("http://www.tei-c.org/ns/1.0", $node/@type)} {
Michelle Rodzis's avatar
Michelle Rodzis committed
483
484
485
486
487
                    $node/(@xml:id, @subtype, @rendition, @prev, @next),
                    if($node/@rend) then
                        attribute rendition {$node/@rend}
                    else
                        (),                    
488
                    fontaneSimple:transform($node/node(), $uri)
489
                }
Michelle Rodzis's avatar
Michelle Rodzis committed
490
                
MRodz's avatar
MRodz committed
491
            else if($node/@type = "dialogue") then
MRodz's avatar
MRodz committed
492
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
MRodz's avatar
MRodz committed
493
                    $node/@type,
494
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
495
496
497
498
                }
                
            else if($node/@type = "verse") then
                (fontaneSimple:mark-linegroup-beginning(),
MRodz's avatar
MRodz committed
499
                element {QName("http://www.tei-c.org/ns/1.0", "l")} {
500
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
501
502
503
504
505
506
507
                },
                fontaneSimple:mark-linegroup-end())
                
            else if($node/@type = "said" and $node/@prev) then
                ()
                
            else if($node/@type = "said") then
MRodz's avatar
MRodz committed
508
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
509
                    $node/@type,
510
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
511
512
                }
                
MRodz's avatar
MRodz committed
513
514
515
516
            else if($node/@type = "toc" 
            and matches($node/@subtype, "ungültig")) then
                ()
                
Michelle Rodzis's avatar
Michelle Rodzis committed
517
            else if($node/@type = "toc") then
518
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
519
                    $node/(@type, @subtype),
520
                    fontaneSimple:transform($node/node(), $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
521
                }
522

MRodz's avatar
MRodz committed
523
            else if($node/@type = "legend") then
MRodz's avatar
MRodz committed
524
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
525
                    (if($node/@style
526
527
528
529
530
                    or $node/@rendition) then
                        attribute rendition {simpleHelpers:filter-rendition($node)}
                    else
                        ()),
                    $node/(@* except (@rendition, @style)),
531
                    fontaneSimple:transform($node/node(), $uri)
532
                }
Michelle Rodzis's avatar
Michelle Rodzis committed
533
534
                
            else if($node/@type = "additional") then
MRodz's avatar
MRodz committed
535
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
Michelle Rodzis's avatar
Michelle Rodzis committed
536
                    $node/(@* except (@ulx, @uly, @lry, @lrx)),
537
                    fontaneSimple:transform($node/node(), $uri)
Michelle Rodzis's avatar
Michelle Rodzis committed
538
                }
539

540
            else if(simpleHelpers:has-valid-style($node)
541
            or matches($node/@rendition, "black_letter")
542
            or matches($node/@rendition, "script")
543
            or matches($node/@rendition, "roman")) then
544
                fontaneSimple:make-seg-with-rendition($node, $uri)
545

546
            else if(not($node/@xml:id)) then
547
                fontaneSimple:transform($node/node(), $uri)
548

549
            else if($node/@xml:id) then
550
551
552
                (if($node/@xml:id = "C06_14r_9") then
                    util:log-system-out($node)
                else (),
MRodz's avatar
MRodz committed
553
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
554
555
556
557
                    $node/@xml:id,
                    $node/@prev,
                    $node/@next,
                    $node/@corresp,
558
                    fontaneSimple:transform($node/node(), $uri)
559
                })
560

MRodz's avatar
MRodz committed
561
            else
562
                fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
563
564
                
        case element(tei:said) return
MRodz's avatar
MRodz committed
565
            (element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
566
                attribute type {"said"},
567
                fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
568
569
            },
            if($node/ancestor::tei:zone[@type = "dialogue"]/descendant::tei:said[position() != last()] = $node) then
MRodz's avatar
MRodz committed
570
                element {QName("http://www.tei-c.org/ns/1.0", "lb")} {
MRodz's avatar
MRodz committed
571
572
573
574
                        attribute type {"edited_text"}
                }
            else
                ())
575

MRodz's avatar
MRodz committed
576
        case element(tei:figure) return
577
            if(count($node/child::*) = 1 and $node/child::tei:figDesc) then
578
                (: genealogy lines probably shouldn't be displayed, but I still have to
579
580
                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
581
(:                    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {:)
582
(:                        $node/@*,:)
583
(:                        fontaneSimple:transform($node/node(), $uri):)
584
585
586
587
(:                    }:)
(:                else if(matches($node/descendant::tei:ref, "Schlusslinie")):)
                if(matches($node/descendant::tei:ref, "Schlusslinie"))
                    then
MRodz's avatar
MRodz committed
588
                        element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
589
                            switch ($node/descendant::tei:ref)
590
591
592
                                case "horizontale einfache Schlusslinie" return
                                    attribute type {"long-end-line"}
                                case "Schlusslinie; horizontale Halbschleife von links oben nach rechts" return
593
                                    attribute type {"long-end-line"}
594
                                case "horizontale einfache Schlusslinie (gewellt)" return
595
                                    attribute type {"long-end-line-wavy"}
596
                                case "Schlusslinien; horizontale Schleife von links oben nach rechts unten" return
597
                                    attribute type {"bottom-brace-short"}
598
599
                                default return
                                    attribute type {"end-line"}
600
601
                        }
                else if(matches($node/descendant::tei:ref, "Absatzlinie")
602
603
                (: in case of double paragraph lines the single lines are
                encoded with "oberer" resp. "unterer Teil", but we only
604
605
606
                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
607
                    element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
608
609
610
611
612
613
                        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
614
                else if($node/ancestor::tei:zone[@type = "illustration"]) then
615
                    (element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
Michelle Rodzis's avatar
Michelle Rodzis committed
616
                        $node/@*,
617
                        attribute href {tbleapi:get-url($uri, $node/@xml:id, "png")},
618
                        fontaneSimple:transform($node/node(), $uri)
619
                    })
620
                else
MRodz's avatar
MRodz committed
621
622
                    ()
            else
623
                fontaneSimple:copy-element($node, $uri)
624

MRodz's avatar
MRodz committed
625
        case element(tei:note) return
626
            if($node/@type = "authorial"
627
            and not($node/@subtype = "footnote")) then
MRodz's avatar
MRodz committed
628
                ()
629
            else
630
                fontaneSimple:copy-element($node, $uri)
631

MRodz's avatar
MRodz committed
632
        case element(tei:certainty) return
MRodz's avatar
MRodz committed
633
            element {QName("http://www.tei-c.org/ns/1.0", "note")} {
MRodz's avatar
MRodz committed
634
635
636
637
                attribute type {"editorial"},
                attribute subtype {"certainty"},
                $node/@cert,
                $node/@target,
638
                fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
639
            }
640

MRodz's avatar
MRodz committed
641
        case element(tei:figDesc) return
642
            fontaneSimple:copy-element($node, $uri)
643

MRodz's avatar
MRodz committed
644
        case element(tei:ref) return
645
            fontaneSimple:copy-element($node, $uri)
646

MRodz's avatar
MRodz committed
647
        case element(tei:space) return
648
            fontaneSimple:copy-element($node, $uri)
649

MRodz's avatar
MRodz committed
650
        case element(tei:choice) return
651
            fontaneSimple:copy-element($node, $uri)
652

MRodz's avatar
MRodz committed
653
        case element(tei:abbr) return
654
            fontaneSimple:copy-element($node, $uri)
655

MRodz's avatar
MRodz committed
656
        case element(tei:expan) return
657
            fontaneSimple:copy-element($node, $uri)
658
659
            
        case element(tei:sic) return
660
            fontaneSimple:copy-element($node, $uri)     
661
662
            
        case element(tei:corr) return
663
            fontaneSimple:copy-element($node, $uri)
664

MRodz's avatar
MRodz committed
665
        case element(tei:rs) return
MRodz's avatar
MRodz committed
666
667
            let $index-type := substring-before($node/@ref, ":")
            return
mrodzis's avatar
mrodzis committed
668
669
670
671
672
673
674
                (: 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),
675
                        fontaneSimple:transform($node/node(), $uri)
mrodzis's avatar
mrodzis committed
676
677
678
679
                    },
                    text{" "})
                else
                    ()
680

MRodz's avatar
MRodz committed
681
        case element(tei:date) return
MRodz's avatar
MRodz committed
682
            element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
683
684
                (if($node/@when-iso) then
                    attribute when {$node/@when-iso}
685
686
                else
                    ()),
687
688
                (if($node/@from-iso) then
                    attribute from {$node/@from-iso}
689
690
                else
                    ()),
691
692
                (if($node/@to-iso) then
                    attribute to {$node/@to-iso}
Michelle Rodzis's avatar
Michelle Rodzis committed
693
                else
694
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
695
696
                (if($node/@notAfter-iso) then
                    attribute notAfter {$node/@notAfter-iso}
697
                else
698
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
699
                $node/(@* except (@when-iso, @to-iso, @from-iso, @notAfter-iso)),
700
                fontaneSimple:transform($node/node(), $uri)
701
            }
702

703
        case element(tei:ptr) return
704
            ()
705

MRodz's avatar
MRodz committed
706
        default return
707
            fontaneSimple:transform($node/node(), $uri)
708
};
709
710
711
712

(:~
 : Takes a given element over as is since it is compliant to TEI simplePrint.
 :
MRodz's avatar
MRodz committed
713
 : @author Michelle Weidling
714
715
716
 : @param $node the current text node
 : @return node() a copy of the current node
 :)
717
declare function fontaneSimple:copy-element($node as node(), $uri as xs:string) as node() {
718
719
720
721
    if($node[self::tei:note]) then
        util:log-system-out($node)
    else
        (),
722
    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
Michelle Rodzis's avatar
Michelle Rodzis committed
723
724
725
726
727
        $node/(@* except @rend),
        if($node/@rend) then
            attribute rendition {$node/@rend}
        else
            (),
728
        fontaneSimple:transform($node/node(), $uri)
729
730
731
732
733
734
    }
};

(:~
 : Creates a tei:head with an @rendition and a font-size, if available.
 :
MRodz's avatar
MRodz committed
735
 : @author Michelle Weidling
736
737
738
 : @param $node the current tei:line, tei:zone or tei:seg node
 : @return element(tei:head)
 : :)
739
declare function fontaneSimple:make-head($node as node(), $uri as xs:string) as element(tei:head) {
MRodz's avatar
MRodz committed
740
    element {QName("http://www.tei-c.org/ns/1.0", "head")} {
741
        (if($node/descendant::tei:seg[matches(@style, "font-size")]) then
MRodz's avatar
MRodz committed
742
            attribute style {simpleHelpers:get-font-size($node)}
743
        else
MRodz's avatar
MRodz committed
744
            attribute style {"default"}
745
746
747
748
749
        ),
        $node/@subtype,
        (if($node/@rendition) then
            $node/@rendition
        else
MRodz's avatar
MRodz committed
750
751
752
753
754
            ()),         
        (if($node/@rend) then
            $node/@rend
        else
            ()),        
755
        fontaneSimple:transform($node/node(), $uri)
756
757
758
759
760
761
    }
};

(:~
 : Creates a tei:div.
 :
MRodz's avatar
MRodz committed
762
 : @author Michelle Weidling
763
764
765
 : @param $node the current tei:surface node
 : @return element(tei:div)
 : :)
766
declare function fontaneSimple:make-div($node as element(tei:surface), $uri as xs:string)
767
as element(tei:div) {
MRodz's avatar
MRodz committed