tei2teisimple.xqm 40.4 KB
Newer Older
MRodz's avatar
MRodz committed
1
2
xquery version "3.1";

3
(:~
Michelle Rodzis's avatar
Michelle Rodzis committed
4
5
 : This modules handles the conversion of the Fontante-TEI/XML into TEI simplePrint
 : for the edited text. The resulting TEI simplePrint is the basis for the "Editerter
6
 : Text" (edited text) view on the website and the book. It represents the latest
Michelle Rodzis's avatar
Michelle Rodzis committed
7
 : layer of text.
8
 :
MRodz's avatar
MRodz committed
9
 : @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";
22
import module namespace simpleHelpers="http://fontane-nb.dariah.eu/teisimplehelpers" at "teisimplehelpers.xqm";
mrodzis's avatar
mrodzis committed
23
import module namespace tbleapi="https://fontane-nb.dariah.eu/tble" at "../tble-api.xqm";
24
import module namespace index-info="http://fontane-nb.dariah.eu/index-info" at "index-info.xqm";
MRodz's avatar
MRodz committed
25

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

MRodz's avatar
Fix #23    
MRodz committed
41
42
    let $front-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "front_cover")]
    let $back-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "back_cover")]
43
    let $content := $doc//tei:sourceDoc/tei:surface[not(contains(@n, "cover")
MRodz's avatar
MRodz committed
44
        or matches(@n, "spine"))]
45

46
    let $tei := <TEI xmlns="http://www.tei-c.org/ns/1.0">
MRodz's avatar
MRodz committed
47
        {$doc//tei:teiHeader}
MRodz's avatar
MRodz committed
48
        <text>
49
50
51
            <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
52
        </text>
MRodz's avatar
MRodz committed
53
      </TEI>
54
     let $store := xmldb:store("/db/apps/SADE/resources/xml/", "fontane-tei-tmp.xml", $tei)
MRodz's avatar
MRodz committed
55
    return $tei
MRodz's avatar
MRodz committed
56
57
};

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

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

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

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

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

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

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

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

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

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

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

239
        case element(tei:handShift) return
240
            fontaneSimple:enhance-handshift($node)
241

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

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

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

            else if(matches($node/@style, "underline")
260
            and not(matches($node/@style, "vertical-align"))) then
261
                fontaneSimple:transform($node/node(), $uri)
262

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

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

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

307
            else
308
                fontaneSimple:transform($node/node(), $uri)
309

MRodz's avatar
MRodz committed
310
        case element(tei:hi) return
311
            fontaneSimple:copy-element($node, $uri)
312
313

        (: TODO if $node/@type = "highlighted" then make
314
        a hi[@type = "vertical-mark"] in the second stage of creating the
315
        simple format. use simpleHelpers:get-xml-chunk($node) for this.:)
316
317
        case element(tei:mod) return
            if($node/@type = "highlighted"
318
            and simpleHelpers:is-hand-contemporary($node/@hand)) then
319
                $node
mrodzis's avatar
mrodzis committed
320
321
322
323
324
325
326
327
            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)
328
            else
329
                fontaneSimple:transform($node/node(), $uri)
330

331
        case element(tei:anchor) return
332
            fontaneSimple:copy-element($node, $uri)
333
334

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

MRodz's avatar
MRodz committed
377
378
379
380
        case element(tei:milestone) return
            if($node/@unit = "illustration") then
                ()
            else
381
                fontaneSimple:copy-element($node, $uri)
382

383
        case element(tei:gap) return
384
            fontaneSimple:copy-element($node, $uri)
385

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

406
        case element(tei:surplus) return
407
            fontaneSimple:mark-intervention($node, $uri)
408

MRodz's avatar
MRodz committed
409
        case element(tei:zone) return
410
            if(matches($node/@style, "border-style:solid")
MRodz's avatar
MRodz committed
411
412
            and not(matches($node/@style, "border-radius"))
            and not($node/@rend = "border-style:house")) then
MRodz's avatar
MRodz committed
413
                element {QName("http://www.tei-c.org/ns/1.0", "div")} {
MRodz's avatar
MRodz committed
414
                    attribute type {"frame"},
415
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
416
                }
417

MRodz's avatar
MRodz committed
418
            else if(matches($node/@rend, "border-bottom-style:brace")) then
419
                (fontaneSimple:transform($node/node(), $uri),
MRodz's avatar
MRodz committed
420
                element {QName("http://www.tei-c.org/ns/1.0", "ab")} {
MRodz's avatar
MRodz committed
421
                    attribute type {"bottom-brace"}
422
423
                })

MRodz's avatar
MRodz committed
424
425
            else if($node/@type = "cancel") then
                ()
426

MRodz's avatar
MRodz committed
427
            else if($node/@type = "marked_off") then
MRodz's avatar
MRodz committed
428
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
429
430
                    $node/@type,
                    $node/@xml:id,
431
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
432
                }
433

MRodz's avatar
MRodz committed
434
435
            else if($node/@type = "highlighted") then
                if($node/child::tei:zone[@type = "highlighted"]) then
436
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
437
                else
MRodz's avatar
MRodz committed
438
                    element {QName("http://www.tei-c.org/ns/1.0", "hi")} {
MRodz's avatar
MRodz committed
439
                        attribute type {"vertical-mark"},
440
                        fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
441
                    }
442

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

463
464
            else if($node/parent::tei:zone/@type = "illustration"
            or $node/parent::tei:zone/@type = "printed_illustration") then
MRodz's avatar
MRodz committed
465
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
466
                    attribute type {"caption"},
467
                    fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
468
                }
469

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

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

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

533
            else if(simpleHelpers:has-valid-style($node)
534
            or matches($node/@rendition, "black_letter")
535
            or matches($node/@rendition, "script")
536
            or matches($node/@rendition, "roman")) then
537
                fontaneSimple:make-seg-with-rendition($node, $uri)
538

539
            else if(not($node/@xml:id)) then
540
                fontaneSimple:transform($node/node(), $uri)
541

542
            else if($node/@xml:id) then
MRodz's avatar
MRodz committed
543
                element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
544
545
546
547
                    $node/@xml:id,
                    $node/@prev,
                    $node/@next,
                    $node/@corresp,
548
                    fontaneSimple:transform($node/node(), $uri)
549
                }
550

MRodz's avatar
MRodz committed
551
            else
552
                fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
553
554
                
        case element(tei:said) return
MRodz's avatar
MRodz committed
555
            (element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
556
                attribute type {"said"},
557
                fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
558
559
            },
            if($node/ancestor::tei:zone[@type = "dialogue"]/descendant::tei:said[position() != last()] = $node) then
MRodz's avatar
MRodz committed
560
                element {QName("http://www.tei-c.org/ns/1.0", "lb")} {
MRodz's avatar
MRodz committed
561
562
563
564
                        attribute type {"edited_text"}
                }
            else
                ())
565

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

MRodz's avatar
MRodz committed
616
        case element(tei:note) return
617
            if($node/@type = "authorial"
618
            and not($node/@subtype = "footnote")) then
MRodz's avatar
MRodz committed
619
                ()
620
            else
621
                fontaneSimple:copy-element($node, $uri)
622

MRodz's avatar
MRodz committed
623
        case element(tei:certainty) return
MRodz's avatar
MRodz committed
624
            element {QName("http://www.tei-c.org/ns/1.0", "note")} {
MRodz's avatar
MRodz committed
625
626
627
628
                attribute type {"editorial"},
                attribute subtype {"certainty"},
                $node/@cert,
                $node/@target,
629
                fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
630
            }
631

MRodz's avatar
MRodz committed
632
        case element(tei:figDesc) return
633
            fontaneSimple:copy-element($node, $uri)
634

MRodz's avatar
MRodz committed
635
        case element(tei:ref) return
636
            fontaneSimple:copy-element($node, $uri)
637

MRodz's avatar
MRodz committed
638
        case element(tei:space) return
639
            fontaneSimple:copy-element($node, $uri)
640

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

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

MRodz's avatar
MRodz committed
647
        case element(tei:expan) return
648
            fontaneSimple:copy-element($node, $uri)
649
650
            
        case element(tei:sic) return
651
            fontaneSimple:copy-element($node, $uri)     
652
653
            
        case element(tei:corr) return
654
            fontaneSimple:copy-element($node, $uri)
655

MRodz's avatar
MRodz committed
656
        case element(tei:rs) return
mrodzis's avatar
mrodzis committed
657
            let $bla := util:log-system-out($node)
MRodz's avatar
MRodz committed
658
659
            let $index-type := substring-before($node/@ref, ":")
            return
mrodzis's avatar
mrodzis committed
660
661
662
663
664
665
666
                (: 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),
667
                        fontaneSimple:transform($node/node(), $uri)
mrodzis's avatar
mrodzis committed
668
669
670
671
                    },
                    text{" "})
                else
                    ()
672

MRodz's avatar
MRodz committed
673
        case element(tei:date) return
MRodz's avatar
MRodz committed
674
            element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
675
676
                (if($node/@when-iso) then
                    attribute when {$node/@when-iso}
677
678
                else
                    ()),
679
680
                (if($node/@from-iso) then
                    attribute from {$node/@from-iso}
681
682
                else
                    ()),
683
684
                (if($node/@to-iso) then
                    attribute to {$node/@to-iso}
Michelle Rodzis's avatar
Michelle Rodzis committed
685
                else
686
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
687
688
                (if($node/@notAfter-iso) then
                    attribute notAfter {$node/@notAfter-iso}
689
                else
690
                    ()),
Michelle Rodzis's avatar
Michelle Rodzis committed
691
                $node/(@* except (@when-iso, @to-iso, @from-iso, @notAfter-iso)),
692
                fontaneSimple:transform($node/node(), $uri)
693
            }
694

695
        case element(tei:ptr) return
696
            ()
697

MRodz's avatar
MRodz committed
698
        default return
699
            fontaneSimple:transform($node/node(), $uri)
700
};
701
702
703
704

(:~
 : Takes a given element over as is since it is compliant to TEI simplePrint.
 :
MRodz's avatar
MRodz committed
705
 : @author Michelle Weidling
706
707
708
 : @param $node the current text node
 : @return node() a copy of the current node
 :)
709
declare function fontaneSimple:copy-element($node as node(), $uri as xs:string) as node() {
710
    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
Michelle Rodzis's avatar
Michelle Rodzis committed
711
712
713
714
715
        $node/(@* except @rend),
        if($node/@rend) then
            attribute rendition {$node/@rend}
        else
            (),
716
        fontaneSimple:transform($node/node(), $uri)
717
718
719
720
721
722
    }
};

(:~
 : Creates a tei:head with an @rendition and a font-size, if available.
 :
MRodz's avatar
MRodz committed
723
 : @author Michelle Weidling
724
725
726
 : @param $node the current tei:line, tei:zone or tei:seg node
 : @return element(tei:head)
 : :)
727
declare function fontaneSimple:make-head($node as node(), $uri as xs:string) as element(tei:head) {
MRodz's avatar
MRodz committed
728
    element {QName("http://www.tei-c.org/ns/1.0", "head")} {
729
        (if($node/descendant::tei:seg[matches(@style, "font-size")]) then
MRodz's avatar
MRodz committed
730
            attribute style {simpleHelpers:get-font-size($node)}
731
        else
MRodz's avatar
MRodz committed
732
            attribute style {"default"}
733
734
735
736
737
        ),
        $node/@subtype,
        (if($node/@rendition) then
            $node/@rendition
        else
MRodz's avatar
MRodz committed
738
739
740
741
742
            ()),         
        (if($node/@rend) then
            $node/@rend
        else
            ()),        
743
        fontaneSimple:transform($node/node(), $uri)
744
745
746
747
748
749
    }
};

(:~
 : Creates a tei:div.
 :
MRodz's avatar
MRodz committed
750
 : @author Michelle Weidling
751
752
753
 : @param $node the current tei:surface node
 : @return element(tei:div)
 : :)
754
declare function fontaneSimple:make-div($node as element(tei:surface), $uri as xs:string)
755
as element(tei:div) {
MRodz's avatar
MRodz committed
756
    element {QName("http://www.tei-c.org/ns/1.0", "div")} {
757
        $node/(@* except (@facs, @n, @attachment, @subtype, @ulx, @uly, @lrx, @lry, @points)),
758
        fontaneSimple:transform($node/node(), $uri)
759
760
761
762
763
764
    }
};

(:~
 : Creates a new tei:seg with all relevant rendition information.
 :
MRodz's avatar
MRodz committed
765
 : @author Michelle Weidling
766
767
768
 : @param $node the current tei:zone, tei:line, or tei:seg element
 : @return element(tei:seg)
 :)
769
declare function fontaneSimple:make-seg-with-rendition($node as element(*), $uri as xs:string)
770
as element(tei:seg) {