tei2teisimple.xqm 39.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";
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
83
84
85
86
                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
87
88
            else
                ()
89

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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