tei2teisimple.xqm 43 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
84
            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
85
                if($node/parent::tei:rs and starts-with($node, " ")
mrodzis's avatar
mrodzis committed
86
                and not($node/preceding-sibling::*[1][self::tei:handShift or self::tei:hi])
87
                and simpleHelpers:is-trimming-necessary($node)) then
88
89
90
                    simpleHelpers:prepare-text(text{substring-after($node, " ")})
                else
                    simpleHelpers:prepare-text($node)
MRodz's avatar
MRodz committed
91
92
            else
                ()
93

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

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

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

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

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

134
        case element(tei:add) return
135
            (if($node/@type = "edited_text"
136
            or $node/child::tei:seg[@type = "multiphrase"]) then
137
                fontaneSimple:copy-element($node, $uri)
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
                
mrodzis's avatar
mrodzis committed
151
152
153
154
155
            else if($node/@place = "above"
            and $node/preceding::node()[1][normalize-space(.) = ""]) then
                (text{" "},
                fontaneSimple:transform($node/node(), $uri))
                
156
            else if(not($node/@xml:id)) then
157
                fontaneSimple:transform($node/node(), $uri)
158
                
159
            else if(simpleHelpers:is-transposed($node)) then
160
161
                let $corresp := //tei:metamark[matches(@target, $node/@xml:id)]
                return
162
163
                    (fontaneSimple:transform($corresp/node(), $uri),
                    fontaneSimple:transform($node/node(), $uri))
164
                    
165
            else
mrodzis's avatar
mrodzis committed
166
167
                (fontaneSimple:transform($node/node(), $uri)),
                text{" "})
168

169
170
        case element(tei:addSpan) return
            if($node/@type = "edited_text") then
171
                fontaneSimple:copy-element($node, $uri)
172
            else
173
174
                ()

175
176
        case element(tei:fw) return
            ()
177

178
        case element(tei:line) return
Michelle Rodzis's avatar
Michelle Rodzis committed
179
            if($node/@type = "heading") then
180
                fontaneSimple:make-head($node, $uri)
181

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

245
        case element(tei:handShift) return
246
            fontaneSimple:enhance-handshift($node)
247

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

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

MRodz's avatar
MRodz committed
262
            else if($node/@type = "heading") then
263
                fontaneSimple:make-head($node, $uri)
264
265

            else if(matches($node/@style, "underline")
266
            and not(matches($node/@style, "vertical-align"))) then
267
                fontaneSimple:transform($node/node(), $uri)
268

269
            else if(simpleHelpers:has-valid-style($node)
270
            or matches($node/@rendition, "black_letter")
271
            or matches($node/@rendition, "roman")) then
272
                fontaneSimple:make-seg-with-rendition($node, $uri)
273
274
275

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

            else if($node/@type = "auction_number"
286
            or $node/@type = "cancel"
MRodz's avatar
MRodz committed
287
288
            or $node/@type = "abort"
            or $node/@function ="unknown")
289
290
                then
                    ()
291
292
                    
            else if($node/parent::tei:add and $node/@copyOf) then
293
                fontaneSimple:mark-intervention($node, $uri)
MRodz's avatar
MRodz committed
294
295
296
297
298
299
300
301
302
                
            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
303
                        (element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
304
                            $node/@type,
305
306
                            fontaneSimple:transform($node/node(), $uri),
                            fontaneSimple:transform($corresp/node(), $uri)
MRodz's avatar
MRodz committed
307
                        },
MRodz's avatar
MRodz committed
308
                        element {QName("http://www.tei-c.org/ns/1.0", "lb")} {
MRodz's avatar
MRodz committed
309
310
311
                            attribute type {"edited_text"}
                        })
                else
MRodz's avatar
MRodz committed
312
                    element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
MRodz's avatar
MRodz committed
313
                        $node/@type,
314
                        fontaneSimple:transform($node/node(), $uri)
MRodz's avatar
MRodz committed
315
                    }
316
317
318
319
320
321
322
323
324
325
            
            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)
                }
326

327
            else
328
                fontaneSimple:transform($node/node(), $uri)
329

MRodz's avatar
MRodz committed
330
        case element(tei:hi) return
331
332
333
334
335
336
337
338
339
340
            (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
                ())
341
342

        (: TODO if $node/@type = "highlighted" then make
343
        a hi[@type = "vertical-mark"] in the second stage of creating the
344
        simple format. use simpleHelpers:get-xml-chunk($node) for this.:)
345
346
        case element(tei:mod) return
            if($node/@type = "highlighted"
347
            and simpleHelpers:is-hand-contemporary($node/@hand)) then
348
                $node
mrodzis's avatar
mrodzis committed
349
350
351
352
353
354
355
356
            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)
357
            else
358
                fontaneSimple:transform($node/node(), $uri)
359

360
        case element(tei:anchor) return
361
            fontaneSimple:copy-element($node, $uri)
362
363

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

MRodz's avatar
MRodz committed
406
407
408
409
        case element(tei:milestone) return
            if($node/@unit = "illustration") then
                ()
            else
410
                fontaneSimple:copy-element($node, $uri)
411

412
        case element(tei:gap) return
413
            fontaneSimple:copy-element($node, $uri)
414

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

435
        case element(tei:surplus) return
436
            fontaneSimple:mark-intervention($node, $uri)
437

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

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

MRodz's avatar
MRodz committed
453
454
            else if($node/@type = "cancel") then
                ()
455

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

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

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

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

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

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

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

562
            else if(simpleHelpers:has-valid-style($node)
563
            or matches($node/@rendition, "black_letter")
564
            or matches($node/@rendition, "script")
565
            or matches($node/@rendition, "roman")) then
566
                fontaneSimple:make-seg-with-rendition($node, $uri)
567

568
            else if(not($node/@xml:id)) then
569
                fontaneSimple:transform($node/node(), $uri)
570

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

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

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

MRodz's avatar
MRodz committed
647
        case element(tei:note) return
648
            if($node/@type = "authorial"
649
            and not($node/@subtype = "footnote")) then
MRodz's avatar
MRodz committed
650
                ()
651
            else
mrodzis's avatar
mrodzis committed
652
                fontaneSimple:copy-element($node, $uri)
653

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

MRodz's avatar
MRodz committed
663
        case element(tei:figDesc) return
664
            fontaneSimple:copy-element($node, $uri)
665

MRodz's avatar
MRodz committed
666
        case element(tei:ref) return
667
            fontaneSimple:copy-element($node, $uri)
668

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

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

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

MRodz's avatar
MRodz committed
678
        case element(tei:expan) return
679
            fontaneSimple:copy-element($node, $uri)
680
681
            
        case element(tei:sic) return
682
            fontaneSimple:copy-element($node, $uri)     
683
684
            
        case element(tei:corr) return
685
            fontaneSimple:copy-element($node, $uri)
686

MRodz's avatar
MRodz committed
687
        case element(tei:rs) return
MRodz's avatar
MRodz committed
688
689
            let $index-type := substring-before($node/@ref, ":")
            return
mrodzis's avatar
mrodzis committed
690
691
692
693
694
695
696
                (: 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),
697
                        fontaneSimple:transform($node/node(), $uri)
mrodzis's avatar
mrodzis committed
698
                    },
mrodzis's avatar
mrodzis committed
699
700
701
                    if(not($node//tei:abbr/text()[ends-with(., ":")]
                    or $node//text()[last()][ends-with(., "-")]
                    or $node/following::node()[1][self::text()][starts-with(., "-") or starts-with(., ".")])) then
mrodzis's avatar
mrodzis committed
702
703
704
                        text{" "}
                    else
                        ())
mrodzis's avatar
mrodzis committed
705
706
                else
                    ()
707

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

730
        case element(tei:ptr) return
731
            ()
732

MRodz's avatar
MRodz committed
733
        default return
734
            fontaneSimple:transform($node/node(), $uri)
735
};
736
737
738
739

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

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

(:~
 : Creates a tei:div.
 :
MRodz's avatar
MRodz committed
789
 : @author Michelle Weidling
790
791
792
 : @param $node the current tei:surface node
 : @return element(tei:div)
 : :)
793
declare function fontaneSimple:make-div($node as element(tei:surface), $uri as xs:string)
794
as element(tei:div) {
MRodz's avatar
MRodz committed
795
    element {QName("http://www.tei-c.org/ns/1.0", "div")} {
796
        $node/(@* except (@facs, @n, @attachment, @subtype, @ulx, @uly, @lrx, @lry, @points)),
797
        fontaneSimple:transform($node/node(), $uri)
MRodz's avatar