transform.xqm 108 KB
Newer Older
Mathias Goebel's avatar
Mathias Goebel committed
1
xquery version "3.1";
Mathias Goebel's avatar
Mathias Goebel committed
2
3
4
5
6
7
8
9
(:~
 : This module provides the main transformations. It is called during
 : publication.
 : @author Mathias Göbel
 : @todo
  <xhtml:ul>
    <xhtml:li>bootstrap classes defined in here.</xhtml:li>
    <xhtml:li>at least two methods for rendering borders, one directly in local:magic()</xhtml:li>
10
    <xhtml:li>pre Text with link is disabled</xhtml:li>
Mathias Goebel's avatar
Mathias Goebel committed
11
12
13
14
    <xhtml:li></xhtml:li>
  </xhtml:ul>
 :)

Mathias Goebel's avatar
Mathias Goebel committed
15
module namespace transfo="http://fontane-nb.dariah.eu/Transfo";
Mathias Goebel's avatar
Mathias Goebel committed
16
17
18
19
20
21

declare boundary-space preserve;
declare default element namespace "http://www.tei-c.org/ns/1.0";

declare namespace digilib="digilib:digilib";
declare namespace svg="http://www.w3.org/2000/svg";
22
23
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace test="http://exist-db.org/xquery/xqsuite";
24
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
25
26
declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare namespace xlink="http://www.w3.org/1999/xlink";
Mathias Goebel's avatar
Mathias Goebel committed
27

Mathias Goebel's avatar
Mathias Goebel committed
28
import module namespace caret="http://fontane-nb.dariah.eu/Transfo/caret" at "transform-caret.xqm";
29
import module namespace code="http://bdn-edition.de/ns/code-view";
30
import module namespace config="http://textgrid.de/ns/SADE/config" at "../config/config.xqm";
Mathias Goebel's avatar
Mathias Goebel committed
31
import module namespace index="https://fontane-nb.dariah.eu/indexapi" at "index-api.xqm";
Mathias Goebel's avatar
Mathias Goebel committed
32
import module namespace f-misc="http://fontane-nb.dariah.eu/ns/SADE/misc" at "misc.xqm";
Mathias Goebel's avatar
Mathias Goebel committed
33

Mathias Goebel's avatar
   
Mathias Goebel committed
34
declare variable $transfo:tooltipReplacementPattern := '“$|\s$|,$|\.|\($|\)$|;|&#x2003;|\[\d+\]$|^Wohn⸗|^ſonder-|^\(|Landſchaften$|^Oelbil|^Schwedens|Schwedens$';
Mathias Goebel's avatar
Mathias Goebel committed
35

Mathias Goebel's avatar
Mathias Goebel committed
36
declare variable $transfo:dataCollection := collection("/db/sade-projects/textgrid/data/xml/data");
37

Mathias Goebel's avatar
Mathias Goebel committed
38
declare variable $transfo:base-url :=
Mathias Goebel's avatar
Mathias Goebel committed
39
40
41
42
    if (config:get("sade.develop") = "true")
    then "https://fontane-nb.dariah.eu/test/"
    else "https://fontane-nb.dariah.eu/";

Mathias Goebel's avatar
Mathias Goebel committed
43
declare variable $transfo:numberPattern := ".#####";
Mathias Goebel's avatar
Mathias Goebel committed
44

Mathias Goebel's avatar
Mathias Goebel committed
45
46
declare function transfo:magic($nodes as node()*) {
    transfo:magic(($nodes), "undefined")
Mathias Goebel's avatar
Mathias Goebel committed
47
48
};

Mathias Goebel's avatar
Mathias Goebel committed
49
50
51
(:~
 : Main function in this module, called in recursion. Used with a tei:TEI node to create a complete
 : transformation of a document.
Mathias Goebel's avatar
Mathias Goebel committed
52
53
 : @param $node A tei:TEI
 : @param $inital The inital tei:surface is wrapped in a specific xhtml:div
Mathias Goebel's avatar
Mathias Goebel committed
54
55
 : @return is specific to $nodes, so nothing declared
 :)
Mathias Goebel's avatar
Mathias Goebel committed
56
declare function transfo:magic($nodes as node()*, $inital as xs:string?) {
Mathias Goebel's avatar
Mathias Goebel committed
57
58
for $node in $nodes return
typeswitch($node)
Mathias Goebel's avatar
Mathias Goebel committed
59
60
61
62
  case element(tei:TEI)
    return
      element xhtml:div {
        attribute class {'TEI', 'clearfix' (: damn bootstrap in this code? damn it! :) },
Mathias Goebel's avatar
Mathias Goebel committed
63
        transfo:magic($node/node())
Mathias Goebel's avatar
Mathias Goebel committed
64
      }
Mathias Goebel's avatar
Mathias Goebel committed
65

Mathias Goebel's avatar
Mathias Goebel committed
66
67
    case element(tei:teiHeader)
      return ()
Mathias Goebel's avatar
Mathias Goebel committed
68
    case element(tei:sourceDoc)
Mathias Goebel's avatar
Mathias Goebel committed
69
      return
Mathias Goebel's avatar
Mathias Goebel committed
70
        transfo:sourceDoc($node)
Mathias Goebel's avatar
Mathias Goebel committed
71
    case element(tei:surface)
Mathias Goebel's avatar
Mathias Goebel committed
72
      return
Mathias Goebel's avatar
Mathias Goebel committed
73
        transfo:surfaceWrapper($node, $inital)
Mathias Goebel's avatar
Mathias Goebel committed
74
    case element(tei:zone)
Mathias Goebel's avatar
Mathias Goebel committed
75
      return
Mathias Goebel's avatar
Mathias Goebel committed
76
        transfo:zoneWrapper($node)
Mathias Goebel's avatar
Mathias Goebel committed
77
    case element(tei:figure)
Mathias Goebel's avatar
Mathias Goebel committed
78
      return
Mathias Goebel's avatar
Mathias Goebel committed
79
        transfo:figure($node)
Mathias Goebel's avatar
Mathias Goebel committed
80
    case element(tei:line)
Mathias Goebel's avatar
Mathias Goebel committed
81
      return
Mathias Goebel's avatar
Mathias Goebel committed
82
        transfo:line($node)
Mathias Goebel's avatar
Mathias Goebel committed
83
    case element(tei:seg)
Mathias Goebel's avatar
Mathias Goebel committed
84
      return
Mathias Goebel's avatar
Mathias Goebel committed
85
        transfo:seg($node)
Mathias Goebel's avatar
Mathias Goebel committed
86
    case element(tei:fw)
Mathias Goebel's avatar
Mathias Goebel committed
87
      return
Mathias Goebel's avatar
Mathias Goebel committed
88
        transfo:fw($node)
Mathias Goebel's avatar
Mathias Goebel committed
89
    case element(tei:mod)
Mathias Goebel's avatar
Mathias Goebel committed
90
      return
Mathias Goebel's avatar
Mathias Goebel committed
91
        transfo:mod($node)
Mathias Goebel's avatar
Mathias Goebel committed
92
    case element(tei:del)
Mathias Goebel's avatar
Mathias Goebel committed
93
      return
Mathias Goebel's avatar
Mathias Goebel committed
94
        transfo:del($node)
Mathias Goebel's avatar
Mathias Goebel committed
95
    case element(tei:hi)
Mathias Goebel's avatar
Mathias Goebel committed
96
      return
Mathias Goebel's avatar
Mathias Goebel committed
97
        transfo:hi($node)
Mathias Goebel's avatar
Mathias Goebel committed
98
    case element(tei:add)
Mathias Goebel's avatar
Mathias Goebel committed
99
      return
Mathias Goebel's avatar
Mathias Goebel committed
100
        transfo:add($node)
Mathias Goebel's avatar
Mathias Goebel committed
101
    case element(tei:retrace)
Mathias Goebel's avatar
Mathias Goebel committed
102
      return (
Mathias Goebel's avatar
Mathias Goebel committed
103
104
        transfo:retrace($node),
        transfo:magic($node/node()))
Mathias Goebel's avatar
Mathias Goebel committed
105

Mathias Goebel's avatar
Mathias Goebel committed
106
    case element(tei:restore)
Mathias Goebel's avatar
Mathias Goebel committed
107
      return
Mathias Goebel's avatar
Mathias Goebel committed
108
        transfo:restore($node)
Mathias Goebel's avatar
Mathias Goebel committed
109
    case element(tei:choice)
Mathias Goebel's avatar
Mathias Goebel committed
110
      return
Mathias Goebel's avatar
Mathias Goebel committed
111
        transfo:choice($node)
Mathias Goebel's avatar
Mathias Goebel committed
112
    case element(tei:abbr)
Mathias Goebel's avatar
Mathias Goebel committed
113
      return
Mathias Goebel's avatar
Mathias Goebel committed
114
        transfo:abbr($node)
Mathias Goebel's avatar
Mathias Goebel committed
115
    case element(tei:rs)
Mathias Goebel's avatar
Mathias Goebel committed
116
      return
Mathias Goebel's avatar
Mathias Goebel committed
117
        transfo:rs($node)
Mathias Goebel's avatar
Mathias Goebel committed
118
    case element(tei:date)
Mathias Goebel's avatar
Mathias Goebel committed
119
      return
Mathias Goebel's avatar
Mathias Goebel committed
120
        transfo:date($node)
Mathias Goebel's avatar
Mathias Goebel committed
121
    case element(tei:stamp)
Mathias Goebel's avatar
Mathias Goebel committed
122
      return
Mathias Goebel's avatar
Mathias Goebel committed
123
        transfo:stamp($node)
Mathias Goebel's avatar
Mathias Goebel committed
124
    case element(tei:metamark)
Mathias Goebel's avatar
Mathias Goebel committed
125
      return
Mathias Goebel's avatar
Mathias Goebel committed
126
        transfo:metamark($node)
Mathias Goebel's avatar
Mathias Goebel committed
127
    case element(tei:g)
Mathias Goebel's avatar
Mathias Goebel committed
128
      return
129
        (: horizontal bars are rendered as fractions within a tei:seg :)
Mathias Goebel's avatar
Mathias Goebel committed
130
        if($node[@ref="#hb"]) then () else
131
        transfo:glyph($node)
Mathias Goebel's avatar
Mathias Goebel committed
132
    case element(tei:unclear)
Mathias Goebel's avatar
Mathias Goebel committed
133
      return
Mathias Goebel's avatar
Mathias Goebel committed
134
        transfo:unclear($node)
Mathias Goebel's avatar
Mathias Goebel committed
135
    case element(tei:gap)
Mathias Goebel's avatar
Mathias Goebel committed
136
      return
Mathias Goebel's avatar
Mathias Goebel committed
137
        transfo:gap($node)
Mathias Goebel's avatar
Mathias Goebel committed
138
139
    case element(tei:milestone)
      return
Mathias Goebel's avatar
Mathias Goebel committed
140
        transfo:milestone($node)
Mathias Goebel's avatar
Mathias Goebel committed
141
    case element(tei:ref)
Mathias Goebel's avatar
Mathias Goebel committed
142
      return
Mathias Goebel's avatar
Mathias Goebel committed
143
        transfo:ref($node)
Mathias Goebel's avatar
Mathias Goebel committed
144
    case element(tei:space)
Mathias Goebel's avatar
Mathias Goebel committed
145
      return
Mathias Goebel's avatar
Mathias Goebel committed
146
        transfo:space($node)
Mathias Goebel's avatar
Mathias Goebel committed
147
    case element(tei:said)
Mathias Goebel's avatar
Mathias Goebel committed
148
      return
Mathias Goebel's avatar
Mathias Goebel committed
149
        transfo:said($node)
Mathias Goebel's avatar
Mathias Goebel committed
150
151
    case element(tei:note)
      return
Mathias Goebel's avatar
Mathias Goebel committed
152
        transfo:note($node)
Mathias Goebel's avatar
Mathias Goebel committed
153
154
    case element(tei:anchor)
      return
Mathias Goebel's avatar
Mathias Goebel committed
155
        transfo:anchor($node)
Mathias Goebel's avatar
Mathias Goebel committed
156

Mathias Goebel's avatar
Mathias Goebel committed
157
158
159
160
    case element(tei:expan) return ()
    case element(tei:addSpan) return ()
    case element(tei:handShift) return ()
    case element(tei:lb) return ()
Mathias Goebel's avatar
Mathias Goebel committed
161

Mathias Goebel's avatar
Mathias Goebel committed
162
    case text()
Mathias Goebel's avatar
Mathias Goebel committed
163
      return
Mathias Goebel's avatar
Mathias Goebel committed
164
          transfo:text($node)
Mathias Goebel's avatar
Mathias Goebel committed
165

Mathias Goebel's avatar
Mathias Goebel committed
166
    default return transfo:magic($node/node())
Mathias Goebel's avatar
Mathias Goebel committed
167
};
Mathias Goebel's avatar
Mathias Goebel committed
168
169
170
171

(:~
 : transformation from tei:sourceDoc to xhtml:div
 :)
Mathias Goebel's avatar
Mathias Goebel committed
172
declare function transfo:sourceDoc($node as element(tei:sourceDoc))
Mathias Goebel's avatar
Mathias Goebel committed
173
174
175
176
as element(xhtml:div) {
  element xhtml:div {
    attribute id {substring-after($node/@n, 'er_')},
    attribute class {'sourceDoc'},
Mathias Goebel's avatar
Mathias Goebel committed
177
    transfo:magic($node/node())
Mathias Goebel's avatar
Mathias Goebel committed
178
179
180
181
182
183
184
  }
};


(:~
 : transforms tei:surface to xhtml:div
 :)
Mathias Goebel's avatar
Mathias Goebel committed
185
declare function transfo:surfaceWrapper($node as element(tei:surface), $inital as xs:string)
Mathias Goebel's avatar
Mathias Goebel committed
186
as item()* {(
187
188
189
190
    if($node/parent::tei:sourceDoc or string($node/@n) = $inital)
    then
            element xhtml:div {
            attribute class {'rowWrapper', 'clearfix', 'butthead'},
Mathias Goebel's avatar
Mathias Goebel committed
191
(:                    attribute id { $node/string(@n) },:)
Mathias Goebel's avatar
Mathias Goebel committed
192
            transfo:facs($node),
Mathias Goebel's avatar
Mathias Goebel committed
193
(:                    if($node/string(@type) = ("clipping", "additional")):)
194
195
            element xhtml:div {
                if($node/@subtype="Kalenderblatt")
Mathias Goebel's avatar
Mathias Goebel committed
196
197
                (: cause of rotation handling, an additional div is needed for
                mostly rotated Kalenderblätter:)
198
                then
Mathias Goebel's avatar
Mathias Goebel committed
199
                    element xhtml:div {
Mathias Goebel's avatar
Mathias Goebel committed
200
201
                        transfo:surface($node, $inital),
                        transfo:magic($node/node())
202
203
                    }
                else(
Mathias Goebel's avatar
Mathias Goebel committed
204
205
                transfo:surface($node, $inital),
                transfo:magic($node/node()))
206
207
208
209
210
211
212
213
214
215
216
            },
            element xhtml:div {
                attribute class {'teixml'},
                element xhtml:pre {
                    element xhtml:b {
                        <xhtml:h3 class="xmlTitle">Auszug aus dem TEI/XML-Dokument</xhtml:h3>,
                        <xhtml:div>
                            <xhtml:a href="xml.html?id=/xml/data/{$node/preceding::tei:teiHeader//tei:idno[@type="TextGrid"]/substring-after(., 'textgrid:')}.xml">Gesamtes TEI/XML-Dokument</xhtml:a>
                            |
                            <xhtml:a target="_blank" href="rest/data/{$node/preceding::tei:teiHeader//tei:idno[@type="TextGrid"]/substring-after(., 'textgrid:')}.xml">(via REST)</xhtml:a>
                        </xhtml:div>
Mathias Goebel's avatar
Mathias Goebel committed
217
                    },
218
219
                    if( config:get("sade.develop") = "true" )
                    then code:main($node)
Mathias Goebel's avatar
Mathias Goebel committed
220
                    else code:main($node, false(), "hljs-", true()),
221
                    (: for normal tei:surfaces :)
222
                    for $n in $node/following-sibling::tei:note
223
224
225
226
227
228
229
230
231
232
233
234
                        where $n >> $node and $n << ($node/following-sibling::tei:surface)[1]
                        return  code:main($n),
                    (: for tei:surfaces that are part of a "Doppelseitenansicht".
                    in this case an associated tei:note is encoded after the first/left
                    tei:surface but should also be displayed on the second/right one. :)
                    if($node/@prev and $node/preceding-sibling::*[1][self::tei:note]) then
                        for $n in $node/preceding-sibling::tei:note
                            where $n >> $node/preceding-sibling::tei:surface[1]
                            return
                                code:main($n)
                    else
                        ()
235
                }
Mathias Goebel's avatar
minor    
Mathias Goebel committed
236
              }
237
238
239
240
            }
    else
    (
    element xhtml:div {
Mathias Goebel's avatar
Mathias Goebel committed
241
        transfo:surface($node, $inital),
242
243
        if($node/@type = ('clipping', 'additional'))
        then
Mathias Goebel's avatar
Mathias Goebel committed
244
245
            transfo:magic($node/node())
        else transfo:magic($node/node())
246
247
248
    }),
    let $ids := $node//@xml:id,
        $notes := $node/ancestor::tei:TEI//tei:note[@type="editorial"]/tokenize(replace(@target, "#", ""), " "),
Mathias Goebel's avatar
Mathias Goebel committed
249
        $test := (($ids = $notes) and string($node/@n) = $inital) or $node//tei:figDesc[exists(./parent::tei:figure/@xml:id)]
250
251
    return
        if($test) then
Mathias Goebel's avatar
Mathias Goebel committed
252
            element xhtml:div {
253
254
255
256
257
                attribute class {"notes"},
                element xhtml:ul {
                    for $i in $node/ancestor::tei:TEI//tei:note[@type="editorial"][tokenize(replace(@target, "#", ""), " ") = $ids]
                    return
                        element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
258
                            attribute class {'editorialNote'},
Mathias Goebel's avatar
Mathias Goebel committed
259
                            transfo:noteParser($i)
Mathias Goebel's avatar
Mathias Goebel committed
260
261
262
263
                        },
                        for $figDesc in $node//tei:figDesc[exists(./parent::tei:figure/@xml:id)]
                        return
                          element xhtml:li {
Mathias Goebel's avatar
Mathias Goebel committed
264
                              attribute class {'editorialNote'},
Mathias Goebel's avatar
Mathias Goebel committed
265
266
267
268
269
270
271
272
273
274
                              element xhtml:span {
                                attribute class {"target kursiv"},
                                text {"<Skizze>]"},
                                element xhtml:ul {
                                  element xhtml:li {
                                    string($figDesc)
                                  }
                                }
                              }
                          }
275
                }
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
276

277
278
            }
        else ()
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
279

Mathias Goebel's avatar
Mathias Goebel committed
280
)};
Mathias Goebel's avatar
Mathias Goebel committed
281
282
283
284

(:~
 : prepares the xhtml:div with attributes and nodes()
 :)
Mathias Goebel's avatar
Mathias Goebel committed
285
declare function transfo:surface($n, $inital) {
Mathias Goebel's avatar
Mathias Goebel committed
286
attribute class {
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
287
    'surface',
Mathias Goebel's avatar
Mathias Goebel committed
288
    (if($n/@type) then (' tei' || $n/@type) else ()),
Mathias Goebel's avatar
Mathias Goebel committed
289
    (if($n/@subtype) then string($n/@subtype) else ()),
Mathias Goebel's avatar
Mathias Goebel committed
290
    if( string($n/@subtype)="Kalenderblatt") then if(ends-with($n/@n, 'v')) then 'verso' else 'recto' else (),
Mathias Goebel's avatar
Mathias Goebel committed
291
    if( $n/parent::tei:surface ) then "nested" else (),
292
293
    if( not($n//tei:line[ancestor::tei:zone[@rotate = 180]]) or string($n/@subtype)="Kalenderblatt") then () else "rotate",
    $n/@rend ! string(.)
Mathias Goebel's avatar
Mathias Goebel committed
294
},
Mathias Goebel's avatar
Mathias Goebel committed
295
(: dont call it a label (bootstrap) :)
Mathias Goebel's avatar
Mathias Goebel committed
296
(if($n/@n) then attribute id {"s" || $n/@n} else()),
Mathias Goebel's avatar
Mathias Goebel committed
297
attribute style {
298
  let $values := distinct-values((
Mathias Goebel's avatar
Mathias Goebel committed
299
300
301
    if ($n/(@ulx or @uly)) then ('position:absolute;', 'top:' || $n/@uly || 'cm;', 'left:' || $n/@ulx || 'cm;') else (),
    if ($n/(@ulx and @lrx)) then ('position:absolute;' ,'left:' || $n/@ulx || 'cm;' , 'width:' || $n/@lrx - $n/@ulx || 'cm;') else (),
    if ($n/(@uly and @lry)) then ('position:absolute;', 'top:' || $n/@uly || 'cm;' , 'height:' || $n/@lry - $n/@uly || 'cm;') else (),
302
303
    if ($n/@subtype = 'Kalenderblatt')
    then (
Mathias Goebel's avatar
Mathias Goebel committed
304
305
306
307
            'top:' || $n/@uly || 'cm;',
            'left:' || $n/@ulx || 'cm;',
            'width:' || $n/@lrx - $n/@ulx || 'cm;',
            'height:' || $n/@lry - $n/@uly || 'cm;',
308
309
310
            "position:relative;"
        )
    else ()
Mathias Goebel's avatar
Mathias Goebel committed
311
    )) (: distinct values :)
312
313
314
315
316
  return
    (: omit top, left and position in case of a nested surface :)
      if( string($n/@n) = $inital )
      then $values[not( contains(., "absolute") ) and not( starts-with(., "top:") ) and not( starts-with(., "left:") )]
      else $values
Mathias Goebel's avatar
Mathias Goebel committed
317
318
319
}
};

Mathias Goebel's avatar
Mathias Goebel committed
320
321
322
323
(:~
 : transforms tei:zone to xhtml:div.
 : wrapper places some parts outside the actual div for the zone
 :)
Mathias Goebel's avatar
Mathias Goebel committed
324
declare function transfo:zoneWrapper($node as element(tei:zone))
325
326
327
328
329
330
331
332
333
334
335
336
as element(xhtml:div) {
element xhtml:div {
  try {
    transfo:zone($node)
  }
  catch * {
    error(QName("https://sade.textgrid.de/ns/error/fontane", "ZONE01"), "can not deal with this zone. error: " || string-join(($err:code, $err:description, $err:value), "; "))
  },
  if(
    $node/contains(@style, "border-left-style:double")
    and $node/contains(@rend,"border-left-style:wavy") )
  then
Mathias Goebel's avatar
Mathias Goebel committed
337
    element xhtml:div {
338
339
      attribute class {"border-left border-left-style wavy"},
      try {
Mathias Goebel's avatar
Mathias Goebel committed
340
        transfo:magic($node/node())
341
342
343
344
      }
      catch * {
        error(QName("https://sade.textgrid.de/ns/error/fontane", "ZONE02"), "can not deal with this zone. error: " || string-join(($err:code, $err:description, $err:value), "; "))
      }
Mathias Goebel's avatar
Mathias Goebel committed
345
    }
346
347
348
349
350
351
352
353
  else
    try {
      transfo:magic($node/node())
    }
    catch * {
      error(QName("https://sade.textgrid.de/ns/error/fontane", "ZONE03"), "can not deal with this zone. error: " || string-join(($err:code, $err:description, $err:value), "; "))
    }
}
Mathias Goebel's avatar
Mathias Goebel committed
354
355
356
357
358
359
};


(:~
 : transforms tei:zone to xhtml:div
 :)
Mathias Goebel's avatar
Mathias Goebel committed
360
declare function transfo:zone($n) {
Mathias Goebel's avatar
Mathias Goebel committed
361
$n/@xml:id ! attribute id { string(.) },
Mathias Goebel's avatar
Mathias Goebel committed
362
attribute class {
Mathias Goebel's avatar
Mathias Goebel committed
363
364
365
  'zone',
  string($n/@type),
  string($n/@subtype),
Mathias Goebel's avatar
?    
Mathias Goebel committed
366
  if (exists($n/preceding-sibling::tei:addSpan) and $n/preceding-sibling::tei:addSpan/substring-after(@spanTo, '#') = $n/following-sibling::tei:anchor/@xml:id ) then 'addSpan' else (),
Mathias Goebel's avatar
Mathias Goebel committed
367
  (: mod sequence #1 :)
Mathias Goebel's avatar
Mathias Goebel committed
368
  let $mod := ($n/preceding::tei:mod[@seq][parent::tei:zone][substring-after(@spanTo, '#') = $n/following::tei:anchor/string(@xml:id)], $n/tei:mod[@seq])
Mathias Goebel's avatar
Mathias Goebel committed
369
370
  return
    if ($mod)
Mathias Goebel's avatar
Mathias Goebel committed
371
    then 'mod-seq-' || $mod/@seq
Mathias Goebel's avatar
Mathias Goebel committed
372
  else (),
Mathias Goebel's avatar
Mathias Goebel committed
373
374
375
376
377
378
379
380
381
  if ($n/@type="illustration") then 'figure' else(),
  transfo:segStyle($n),
  if( $n/@type="illustration" and $n/parent::tei:line) then "verticalMiddel" else (),
  if(not( $n//tei:line ) and $n//tei:figure[string(.//tei:ref) = "Diagonale Streichung"]) then "deletion-diagonal" else (),
  let $id := string($n/@xml:id)
  let $metamark := $n/ancestor::tei:surface[1]//tei:metamark[contains(string(@corresp), $id)]
  return
      if( ($id != "") and ( $metamark//tei:ref/ends-with(., 'gestrichen; erledigt') = true()) ) then 'hover' else ()
},
Mathias Goebel's avatar
Mathias Goebel committed
382
383
384
385
386
387
388
attribute style {
(: place it! :)
    if (($n/@ulx or $n/@uly or $n/@lrx or $n/@lry) and not($n/ancestor::tei:zone/@rotate))
        then
            if ($n/ancestor::tei:zone[last()]//tei:figure)
                then
                ('position:absolute;',
Mathias Goebel's avatar
Mathias Goebel committed
389
390
391
392
393
                'top:' || $n/@uly - sum($n/ancestor::tei:zone/@uly) || 'cm;',
                'left:' || $n/@ulx -sum($n/ancestor::tei:zone/@ulx) || 'cm;',
(:  'width:' || (if($n/@lry) then $n/@lrx - (if($n/@ulx) then $n/@ulx else 0) - sum($n/ancestor::tei:zone/@lrx) || 'cm;'  else '' ) || :)
                    'width:' || (if($n/@lry) then $n/@lrx - (if($n/@ulx) then $n/@ulx else 0) - (if ($n/parent::tei:line) then 0 else sum($n/ancestor::tei:zone/@lrx)) || 'cm;'  else '' ),
(:  'height:' || $n/@lry - (if($n/@uly) then $n/@uly else 0)  - sum($n/ancestor::tei:zone/@lry) || 'cm;':)
394
                   'height:' || $n/@lry - (if($n/@uly) then $n/@uly else 0) || 'cm;'
Mathias Goebel's avatar
Mathias Goebel committed
395
396
397
398
399
                ) else
            if (not($n/@ulx|$n/@uly|$n/@lrx) and $n//tei:fw)
                    then 'width:100%;'
(:                then if( $n//text()[matches(., '\w')][not(./ancestor::tei:fw)]) then 'width:100%;' else 'width:100%;height:0;':)
            else
Mathias Goebel's avatar
Mathias Goebel committed
400
401
402
403
404
                'position:absolute;' ||
                'top:' || $n/@uly || 'cm;' ||
                'left:' || $n/@ulx || 'cm;' ||
                'width:' || $n/@lrx - (if($n/@ulx) then $n/@ulx else 0) || 'cm;' ||
                'height:' || $n/@lry - (if($n/@uly) then $n/@uly else 0)  || 'cm;'
Mathias Goebel's avatar
Mathias Goebel committed
405
406
407
408
409
410
411
412
413
414
415
416
    else(),
    if( $n/not(@ulx|@lrx|@rotate) and $n//tei:fw)
(:        then 'width:100%;':)
        then if( $n//text()[matches(., '\w')][not(./ancestor::tei:fw)]) then 'width:100%;' else 'width:100%;'
(: edited: 2016-12-07
 : cause: email  "Probleme mit Seitenzahlen; dringend"
 : was: then if( $n//text()[matches(., '\w')][not(./ancestor::tei:fw)]) then 'width:100%;' else 'width:100%;height:0;'
 :)
    else (),
    if($n/ancestor::tei:zone/@rotate) then
        let $rotation := sum( $n/ancestor::tei:zone/@rotate )
        let $value:=
Mathias Goebel's avatar
Mathias Goebel committed
417
            if($rotation gt 89 and $rotation lt 180) then 'position:absolute;' || 'top:-' || $n/@ulx || 'cm;left:' || $n/@uly || 'cm;'
Mathias Goebel's avatar
Mathias Goebel committed
418
419
420
421
422
423
424
425
            else ()
        return if(contains($value, '-cm') or contains($value, ':cm')) then () else $value
    else(),
(:    if( preceding-sibling::tei:*[1]/local-name="line" ) then 'position:absolute;' else(),:)
(: rotate it! :)
(:    if ($n/@rotate and not( $n/parent::tei:surface/count(tei:zone) = 1)) :)
    if ($n/@rotate)
        then
Mathias Goebel's avatar
Mathias Goebel committed
426
            'transform:rotate(' || $n/@rotate || 'deg);' || '-webkit-transform:rotate(' || $n/@rotate || 'deg);'
Mathias Goebel's avatar
Mathias Goebel committed
427
    else (),
Mathias Goebel's avatar
Mathias Goebel committed
428
    transfo:lineHeight($n),
Mathias Goebel's avatar
Mathias Goebel committed
429
(: look 4 TILE objects :)
Mathias Goebel's avatar
Mathias Goebel committed
430
    if ($n/tei:seg/tei:rs/tei:figure[@xml:id] or $n/tei:figure[@xml:id] or $n/tei:del/tei:figure[@xml:id]) then
Mathias Goebel's avatar
Mathias Goebel committed
431
432
        let $id := (: get the TILE xml:id and try to resolve deleted sketches as well :)
          string($n/tei:figure/@xml:id) || string($n/tei:del/tei:figure/@xml:id)
Mathias Goebel's avatar
Mathias Goebel committed
433
        let $uri := string($n/root()//tei:idno[@type="TextGrid"])
Mathias Goebel's avatar
Mathias Goebel committed
434

Mathias Goebel's avatar
Mathias Goebel committed
435
        let $link := transfo:newestTBLELink($uri, $id)
Mathias Goebel's avatar
Mathias Goebel committed
436
437
        let $shape := $link/substring-before(substring-after(@targets, '#'), ' ')
(:        let $image := $tei//svg:g[@id = $link/parent::tei:linkGrp/substring-after(@facs, '#')]/svg:image/@xlink:href:)
Mathias Goebel's avatar
Mathias Goebel committed
438
(:        let $image := ($n/ancestor::tei:surface)[1]/substring-after(@facs, "textgridrep.org/") || ".1":)
Mathias Goebel's avatar
Mathias Goebel committed
439
440

        let $svgg := $link/ancestor::tei:TEI//svg:g[@id = $link/parent::tei:linkGrp/substring-after(@facs, '#')]
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
441
        let $image := substring-before($svgg//svg:image/@xlink:href, ".") || ".1"
Mathias Goebel's avatar
Mathias Goebel committed
442
443
444
445
        let $x := xs:decimal($svgg//svg:rect[@id = $shape]/substring-before(@x, '%')) => format-number($transfo:numberPattern)
        let $y := xs:decimal($svgg//svg:rect[@id = $shape]/substring-before(@y, '%')) => format-number($transfo:numberPattern)
        let $w := xs:decimal($svgg//svg:rect[@id = $shape]/substring-before(@width, '%')) => format-number($transfo:numberPattern)
        let $h := xs:decimal($svgg//svg:rect[@id = $shape]/substring-before(@height, '%')) => format-number($transfo:numberPattern)
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
446

Mathias Goebel's avatar
Mathias Goebel committed
447
        let $rotation := sum( ($n/ancestor-or-self::tei:*/@rotate) )
Mathias Goebel's avatar
Mathias Goebel committed
448
        let $rotation := if($rotation ne 0) then 360 - $rotation else 0
449
450
        let $furtherAttributes :=
                if($n/ancestor::tei:line)
Mathias Goebel's avatar
Mathias Goebel committed
451
                then "width:" || $n/@lrx - $n/@ulx || "cm; height:" || $n/@lry - $n/@uly || "cm;"
452
                else ""
Mathias Goebel's avatar
Mathias Goebel committed
453
454
        return ("background-image: url('https://textgridlab.org/1.0/digilib/rest/IIIF/" || $image || '/pct:' || $x || ',' || $y || ',' || $w || ',' || $h || "/,1000/" || $rotation || "/default.jpg'); background-repeat: no-repeat; background-size: 100% 100%;" || $furtherAttributes)
(:        digilib/" || $image || '?dh=500&amp;dw=500&amp;wx=' || $x || '&amp;wy=' || $y || '&amp;ww=' || $w || '&amp;wh=' || $h || "&amp;mo=png&amp;rot=" || $rotation || "'); background-repeat: no-repeat; background-size: 100% auto;"):)
Mathias Goebel's avatar
Mathias Goebel committed
455
456
457
458
459
    else (),

    (: like on C07 15r, a zone can contain a single (nonword) character that belongs to nearby lines. in this cases, we increase the font size by rule.
    this stays against our practise to encode a font-size if semantic matters. we should discuss this.
    :)
Mathias Goebel's avatar
Mathias Goebel committed
460
461
    if (sum($n/tei:line//text()/string-length(.)) = 1 and $n/tei:line//text()/matches(., '\W' ) ) then 'font-size:' || $n/@lry - $n/@uly || 'cm;' else (),
    if (sum($n/tei:line//text()/string-length(.)) = 1 and $n/tei:line//text()/matches(., '\W' ) and ($n/@lry - $n/@uly gt 1)) then 'transform:scaleX(0.5);' else (),
Mathias Goebel's avatar
Mathias Goebel committed
462
463
464
465
466
467
468
469
470

    (: override height statements before, if we want to prepare an inline zone :)
    if($n/parent::tei:line)
        then
            (
                'display:inline-block; position:relative; left:0; top:0;'
            )
        else ()
},
471
472
473
if (exists($n/preceding-sibling::tei:addSpan) and $n/preceding-sibling::tei:addSpan/substring-after(@spanTo, '#') = $n/following-sibling::tei:anchor/@xml:id )
  then
    element xhtml:div {attribute class {'addSpanHover italic'},
474
      if($n//tei:note/@subtype = "footnote")
475
      then 'Fußnote'
476
477
478
479
      else
        if(exists($n//tei:metamark[@function="caret"]))
        then 'Hinzufügung mit Einweisungszeichen'
        else 'Hinzufügung'
480
481
   }
  else(),
Mathias Goebel's avatar
Mathias Goebel committed
482
483
484
485
486
487
488
489
490
491
let $id := string($n/@xml:id)
let $metamark := $n/ancestor::tei:surface[1]//tei:metamark[contains(string(@corresp), $id)]
return
  if( ($id != "") and ( $metamark//tei:ref/ends-with(., 'gestrichen; erledigt') = true()) )
  then
      element xhtml:div {attribute class {'zoneHover'}, 'Erledigungsstreichung'}
  else (),

if($n/tei:metamark[@function="authorial_note"])
then element xhtml:div {attribute class {'zoneHover'}, 'Klammer zusammenfassende Funktion'}
492
493
494
else (),

if($n/tei:metamark/tei:figure/tei:figDesc/tei:ref/text())
495
then
Mathias Goebel's avatar
syntax    
Mathias Goebel committed
496
  let $string := string($n/tei:metamark/tei:figure/tei:figDesc/tei:ref/text())
497
498
499
500
501
502
503
  return
      element xhtml:div {
        attribute class {'zoneHover'},
        switch($string)
          case "gestrichen; erledigt" return "Erledigungsstreichung"
          default return $string
      }
Mathias Goebel's avatar
Mathias Goebel committed
504
else ()
Mathias Goebel's avatar
Mathias Goebel committed
505
};
506

Mathias Goebel's avatar
Mathias Goebel committed
507
declare function transfo:line($node as element(tei:line)) {
Mathias Goebel's avatar
Mathias Goebel committed
508
509
510
511
512
  try {
  element xhtml:div  {
    $node/@xml:id ! attribute id { string(.) },
    attribute class {
      'line',
Mathias Goebel's avatar
Mathias Goebel committed
513
      transfo:segStyle($node),
Mathias Goebel's avatar
Mathias Goebel committed
514
515
516
517
518
519
520
521
522
      if($node/@type) then string($node/@type) else (),
      if($node/tei:seg[@type="col"][@n]) then "column" else (),
      if($node/@rendition) then replace($node/@rendition, "#", "") else ()
    },
    attribute style {
      string-join((
        ($node/@style),
        (if($node//text()[not(parent::tei:fw)]) then () else ('height:0.6cm;')),
        ( (: line-height given in div.zone[style] has no effect wheren large rendering is needed :)
Mathias Goebel's avatar
Mathias Goebel committed
523
        if($node//*[contains(string(@style), 'large')] or $node//ancestor::tei:zone[contains(string(@style), 'large')])
524
        then replace( transfo:lineHeight($node/ancestor::tei:zone[1]), 'line-height', 'max-height')
Mathias Goebel's avatar
Mathias Goebel committed
525
        else ())
Mathias Goebel's avatar
Mathias Goebel committed
526
527
    ), ';')
    },
Mathias Goebel's avatar
Mathias Goebel committed
528
    try {transfo:magic($node/node())} catch * { ($err:code , $err:description, $err:value) }
Mathias Goebel's avatar
Mathias Goebel committed
529
  }}
Mathias Goebel's avatar
Mathias Goebel committed
530
  catch * { ("line: ", $err:code, $err:description, $err:value, $err:module, $err:line-number)  }
Mathias Goebel's avatar
Mathias Goebel committed
531
532
533
534
535
536
};



(:~ transformation of any tei:seg
 :)
Mathias Goebel's avatar
Mathias Goebel committed
537
538
539
540
declare function transfo:seg($node as element(tei:seg)){
  transfo:seg($node, 0)
};
declare function transfo:seg($node as element(tei:seg), $i as xs:integer) {
Mathias Goebel's avatar
Mathias Goebel committed
541
  (: before main() :)
Mathias Goebel's avatar
Mathias Goebel committed
542
  if ($node/tei:g[@ref="#hb"]) then transfo:fraction($node)
Mathias Goebel's avatar
Mathias Goebel committed
543
544
545
546
547
548
  else if (($i = 0) and contains($node/tei:seg/@rend, "underline-style:zigzag_retrace"))
    then
      element xhtml:span {
        attribute class {'zigzag_retrace'},
        transfo:seg($node, 1)
      }
Mathias Goebel's avatar
Mathias Goebel committed
549
550
551
552
553
  else
  element xhtml:span {
    $node/@xml:id ! attribute id { string(.) },
    attribute class {
      'seg',
Mathias Goebel's avatar
Mathias Goebel committed
554
      if ($node/@style or $node/@rend or $node/@type) then transfo:segStyle($node) else ()
Mathias Goebel's avatar
Mathias Goebel committed
555
556
557
558
559
560
    },
    if(contains($node/@style, 'letter-spacing')) then
      attribute style { 'letter-spacing:' || substring-before(substring-after($node/@style, 'letter-spacing:'), 'cm') || 'cm;'}
      else (),

    (: recursion :)
Mathias Goebel's avatar
Mathias Goebel committed
561
    transfo:magic($node/node()),
Mathias Goebel's avatar
Mathias Goebel committed
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580

    (: after main() :)
    if($node/@type = "abort")
    then
      element xhtml:div {
        attribute class {'segHover italic'},
        'Schreibabbruch'}
    else (),
    if($node/@type = "multiphrase" and not($node/parent::tei:add/substring-after(@corresp, '#') = $node/ancestor::tei:surface[1]//tei:anchor/@xml:id))
    then
      element xhtml:div {
        attribute class {'segHover italic'},
        'Mehrfachformulierung'}
    else (),
    if($node/@copyOf)
    then
      element xhtml:div {
        attribute class {'segHover italic'},
        'Unterführung'}
581
582
583
584
585
586
    else (),
    if(contains($node/@rend, "underline-cancel"))
    then
      element xhtml:div {
        attribute class {'segHover italic'},
        'Unterstreichung zurückgenommen'}
Mathias Goebel's avatar
Mathias Goebel committed
587
588
589
590
    else ()
  }
};

591
(:~ returns a sequence of class names according to the given styles
Mathias Goebel's avatar
Mathias Goebel committed
592
 : not only for tei:seg, but also for tei:zone
Mathias Goebel's avatar
Mathias Goebel committed
593
 : @param $node A single element with tei:style attribute
594
 : or @rend or to calculate line-height.
Mathias Goebel's avatar
Mathias Goebel committed
595
:)
Mathias Goebel's avatar
Mathias Goebel committed
596
declare function transfo:segStyle($node) {
597
let $style := $node/@style || (if(not($node/@style) and $node/@rend and $node/parent::*/@style) then (" " || $node/parent::*/@style) else ())
Mathias Goebel's avatar
Mathias Goebel committed
598
599
let $rend :=  $node/@rend
let $type:= if(($node/local-name() = ("seg", "zone")) and ($node/@type = "cancel"))
Mathias Goebel's avatar
minor    
Mathias Goebel committed
600
        then
Mathias Goebel's avatar
Mathias Goebel committed
601
            if(not($node/@prev) and not($node/@next))
Mathias Goebel's avatar
minor    
Mathias Goebel committed
602
              then "cancelLeft cancelRight"
Mathias Goebel's avatar
Mathias Goebel committed
603
            else if($node/@next and not($node/@prev))
Mathias Goebel's avatar
minor    
Mathias Goebel committed
604
              then "cancelLeft"
Mathias Goebel's avatar
Mathias Goebel committed
605
            else if($node/@prev and not($node/@next))
Mathias Goebel's avatar
minor    
Mathias Goebel committed
606
              then
Mathias Goebel's avatar
   
Mathias Goebel committed
607
608
609
                if($node/ancestor::tei:zone//tei:metamark[@function="deletion"][contains(@corresp, $node/@xml:id)]//tei:ref != "Diagonale Streichung, begrenzt durch eine senkrechte Abgrenzung am Anfang")
                then ()
                else "cancelRight"
Mathias Goebel's avatar
Mathias Goebel committed
610
            else () (: must be an existing @next and @prev :)
Mathias Goebel's avatar
Mathias Goebel committed
611
        else if($node/@type = "initials") then "initials" else ()
Mathias Goebel's avatar
Mathias Goebel committed
612

Mathias Goebel's avatar
Mathias Goebel committed
613
let $noLineThroughInCaseOfDeletionViaMetamark :=  if(
Mathias Goebel's avatar
Mathias Goebel committed
614
615
616
617
618
619
620
621
    contains($node/@style, 'text-decoration:line-through') and
    ($node/ancestor-or-self::tei:*/concat('#', @xml:id) = tokenize( $node/ancestor::tei:TEI//tei:metamark/@corresp, ' ')) )
    then " noLineThrough"
    else ()

let $rend := replace($rend, '\s', '')
let $seq :=
    for $s in tokenize(replace(replace($style, 'radius:', 'radius'), '\s|\.|%|-style', ''), ';')
622
    where not(matches($s, "^margin\-left:\d{1,2}\.{0,1}\d{0,1}cm$"))
Mathias Goebel's avatar
Mathias Goebel committed
623
    return
624
625
626
627
628
        tokenize($s, ':') !
            (
                (if (matches(., "^\d")) then ("d" || .) else .)
             ! (if(matches(., "^\-")) then ("minus" || .) else .)
            )
Mathias Goebel's avatar
Mathias Goebel committed
629
630
631
let $rendSeq :=
    for $r in tokenize(replace($rend, '\s', ''), ';')
    return
632
        replace(replace(replace($r, "medium:", "medium_"), ':', ' '), '[\(\)]', '')
Mathias Goebel's avatar
Mathias Goebel committed
633

Mathias Goebel's avatar
Mathias Goebel committed
634
let $preMedium := transfo:getMedium($node)
635
let $medium := if (tokenize($preMedium, " ") = ('blue_pencil', 'violet_pencil', 'black_ink', 'blue_ink', 'brown_ink'))
Mathias Goebel's avatar
Mathias Goebel committed
636
637
  then $preMedium
  else ()
Mathias Goebel's avatar
Mathias Goebel committed
638

Mathias Goebel's avatar
Mathias Goebel committed
639
640
641
let $test:= if($seq = ()) then ('TODO', $medium) else ($seq, $rendSeq, $medium, $type, $noLineThroughInCaseOfDeletionViaMetamark)

return
642
    $test ! replace(replace(replace(., '/', '_'), '3_4', 'd3_4'), '\s(\d|\-)', ' d$1')
Mathias Goebel's avatar
Mathias Goebel committed
643
644
};

Mathias Goebel's avatar
Mathias Goebel committed
645
declare function transfo:mod($node as element(tei:mod))
Mathias Goebel's avatar
Mathias Goebel committed
646
647
648
as element(xhtml:span) {
  element xhtml:span {
    $node/@xml:id ! attribute id { string(.) },
Mathias Goebel's avatar
Mathias Goebel committed
649
    $node/@seq ! attribute data-seq { string(.) },
Mathias Goebel's avatar
Mathias Goebel committed
650
651
652
    attribute class {
      'mod',
      $node/@type,
Mathias Goebel's avatar
Mathias Goebel committed
653
      if($node/@rend) then "mod" || replace($node/@rend, ";", "") => replace(":", "_") => replace(" ", " mod") else (),
654
      if(local:modTest($node)) then 'addSesquipedalian' else ()
Mathias Goebel's avatar
Mathias Goebel committed
655
    },
Mathias Goebel's avatar
Mathias Goebel committed
656
    if($node/@style and not($node/@seq)) then $node/@style else (),
Mathias Goebel's avatar
Mathias Goebel committed
657
658
659
660
661
662
663
664
665
    if($node//*/@corresp = "#C01_4r_c")
      then element xhtml:div { attribute class { 'modHover italic'},
          element xhtml:span {'d'},
          '<',
          element xhtml:span {'in'},
          ' überschrieben ',
          element xhtml:span {'urch'},
          '>'
        }
666
    else if($node/tei:del[@rend=('overwritten', 'erased; overwritten')]) then
Mathias Goebel's avatar
Mathias Goebel committed
667
668
669
670
671
672
673
674
      element xhtml:div {
        attribute class {
          'modHover italic',
          if($node/ancestor::tei:*/@rotate or $node/ancestor::tei:zone/preceding-sibling::tei:addSpan) then () else 'hoverTop'},
        if(ends-with($node/preceding::text()[1][parent::tei:line = $node/parent::tei:line], ' ') or ends-with($node/preceding::text()[1][parent::tei:line = $node/parent::tei:line], ' '))
          then ()
          else
            (: do not add preText when mod starts with punctuation :)
675
            if(matches(($node//text())[1], "^\.|^\?|^,|^!")) then element xhtml:span {}
Mathias Goebel's avatar
Mathias Goebel committed
676
677
678
679
680
          else
            element xhtml:span {local:preText($node)},
        '<',
        element xhtml:span {
          if( $node//tei:g[@ref="#hb"] )
Mathias Goebel's avatar
Mathias Goebel committed
681
            then transfo:magic($node/tei:del/node())
Mathias Goebel's avatar
Mathias Goebel committed
682
            else transfo:magic($node/tei:del/node())//text()[. != "unsichere Lesart"][not(contains(string-join(ancestor::*/@class), "expan"))],
Mathias Goebel's avatar
Mathias Goebel committed
683
          (if ($node/tei:del/tei:gap) then transfo:magic($node/tei:del/tei:gap) else ())
Mathias Goebel's avatar
Mathias Goebel committed
684
        },
Mathias Goebel's avatar
Mathias Goebel committed
685
        if($node/tei:del/tei:gap[@unit='mm'][@reason='illegible']) then 'unentziffert' else (),
Mathias Goebel's avatar
Mathias Goebel committed
686
        if($node//del[@rend="erased; overwritten"]) then ' radiert ' else ' überschrieben ',
Mathias Goebel's avatar
Mathias Goebel committed
687
        element xhtml:span {
Mathias Goebel's avatar
Mathias Goebel committed
688
          (: todo: remove decendant::tei:add since it results from a coding error (mod without direkt add) :)
689
          string-join(($node//tei:add//text()[not(parent::tei:expan)][not(parent::tei:del)]))
Mathias Goebel's avatar
Mathias Goebel committed
690
        },
Mathias Goebel's avatar
Mathias Goebel committed
691
        '>', if(matches(string-join($node//tei:add/text()), '^\.$|^,$|^:$|^;$')) then () else element xhtml:span { transfo:postText($node) }
Mathias Goebel's avatar
Mathias Goebel committed
692
      }
693
    else if(
694
      $node/tei:del[not(@rend=('overwritten', 'erased; overwritten'))]
Mathias Goebel's avatar
Mathias Goebel committed
695
      or ($node/@prev and $node/root()//tei:mod[@xml:id = substring-after($node/@prev, "#")]//tei:del[not(@rend=('overwritten', 'erased; overwritten'))])
696
  ) then
Mathias Goebel's avatar
Mathias Goebel committed
697
698
699
700
      element xhtml:div {
        attribute class {
          'modHover italic',
          if($node/ancestor::tei:*/@rotate or $node/ancestor::tei:zone/preceding-sibling::tei:addSpan) then () else 'hoverTop'},
701
702
703
704
705
        ('Ersetzung',
            if( contains(string-join($node//@rend), 'caret') )
            then 'mit Einweisungszeichen'
            else
            if($node/@next and contains(string-join($node/root()//tei:mod[@xml:id = substring-after($node/@next, "#")]//@rend), 'caret') )
706
            then 'mit Einweisungszeichen'
707
708
709
            else
            if( not(exists($node//tei:add[not(tei:del)])) )
            then 'durchgestrichen'
710
711
712
713
714
715
716
717
718
719
720
721
722
723
            else ()
        )
      }
    else if($node//tei:add and not($node//tei:del))
    then
      element xhtml:div {
        attribute class {
          'modHover italic',
          if($node/ancestor::tei:*/@rotate or $node/ancestor::tei:zone/preceding-sibling::tei:addSpan) then () else 'hoverTop'},
        ('Hinzufügung',
            if( contains(string-join($node//@rend), 'caret') )
            then 'mit Einweisungszeichen'
            else
            if($node/@next and $node/@next and contains(string-join($node/root()//tei:mod[@xml:id = substring-after($node/@next, "#")]//@rend), 'caret') )
724
725
726
            then 'mit Einweisungszeichen'
            else ()
        )
Mathias Goebel's avatar
Mathias Goebel committed
727
728
      }
    else (),
Mathias Goebel's avatar
Mathias Goebel committed
729
    if($node/tei:del[@rend = ('overwritten', 'erased; overwritten')])
730
    then
731
          (
732
            transfo:magic($node/node()[. << $node/tei:add[1]][. << $node/tei:del[1]]),
733
734
            transfo:magic($node/tei:add),
            transfo:magic($node/tei:del),
Mathias Goebel's avatar
Mathias Goebel committed
735
            transfo:magic($node/node()[. >> $node/tei:add[last()]][. >> $node/tei:del[last()]])
736
          )
737
    else transfo:magic($node/node())
Mathias Goebel's avatar
Mathias Goebel committed
738
739
740
  }
};

Mathias Goebel's avatar
Mathias Goebel committed
741
742
743
(:~
 : transforms a tei:del to xhtml:span
 :)
Mathias Goebel's avatar
Mathias Goebel committed
744
declare function transfo:del($del as element(tei:del))
Mathias Goebel's avatar
Mathias Goebel committed
745
as element(xhtml:span) {
Mathias Goebel's avatar
Mathias Goebel committed
746
747
748
749
750
751
752
753
754
755
756
(: show line through on figures… :)
if ($del/parent::tei:zone and $del/tei:figure)
then
    element xhtml:div {
        transfo:zone($del/parent::tei:zone)[1],
        attribute style { "width:100%; height:100%" },
        element xhtml:span {
            attribute class {'del'}
        }
    }
else
Mathias Goebel's avatar
Mathias Goebel committed
757
  element xhtml:span {
Mathias Goebel's avatar
Mathias Goebel committed
758
759
760
    attribute class {
      'del',
      replace($del/@rend, '#', 'hash'),
761
762
      if ($del/@instant) then 'instant' else()
    (:  if($del/parent::tei:mod ! local:modTest(.)) then 'addSesquipedalian' else () :)
Mathias Goebel's avatar
Mathias Goebel committed
763
    },
Mathias Goebel's avatar
Mathias Goebel committed
764
    $del/@xml:id ! attribute id { string(.) },
Mathias Goebel's avatar
Mathias Goebel committed
765
    transfo:magic($del/node()),
Mathias Goebel's avatar
Mathias Goebel committed
766
767
768
769
770
771
772
773
774
775
776
    if($del/@instant) then
      element xhtml:div {
        attribute class {'instantHover italic'},
        'Sofortkorrektur'}
    else ()
  }
};

(:~
 : transforms a tei:hi to xhtml:span
 :)
Mathias Goebel's avatar
Mathias Goebel committed
777
declare function transfo:hi($hi as element(tei:hi))
Mathias Goebel's avatar
Mathias Goebel committed
778
779
780
781
as element(xhtml:span) {
  element xhtml:span {
    $hi/@xml:id ! attribute id { string(.) },
    attribute class { 'hi' },
Mathias Goebel's avatar
Mathias Goebel committed
782
    transfo:magic($hi/node())
Mathias Goebel's avatar
Mathias Goebel committed
783
784
785
786
787
788
  }
};

(:~
 : transforms a tei:add
 :)
Mathias Goebel's avatar
Mathias Goebel committed
789
790
791
792
793
794
795
796
797
798
declare function transfo:add($add as element(tei:add)) {
    transfo:add($add, false())
};

(:~
 : transforms a tei:add to XHTML with the option to force the rendering. This is
 : useful when a previously rendered element (with @corresp and an already
 : processed tei:anchor) is added by the typeswitch loop, we will omit it, as it
 : comes with the flag from the wrapper function local:add#1. The function on
 : tei:anchor will always trigger the rendering with a true().
Mathias Goebel's avatar
tei:add    
Mathias Goebel committed
799
 :)
Mathias Goebel's avatar
Mathias Goebel committed
800
declare function transfo:add($add as element(tei:add), $force as xs:boolean) {
Mathias Goebel's avatar
tei:add    
Mathias Goebel committed
801
802
803
804
  if(
      $add/@corresp and not($force)
      (: when a node is placed with the help of a tei:anchor, we force the
        rendering by a superior call to this function. :)
Mathias Goebel's avatar
Mathias Goebel committed
805
      and not($add/@type eq "multiphrase")
Mathias Goebel's avatar
tei:add    
Mathias Goebel committed
806
807
808
809
810
811
812
813
814
    )
  then ()
  else
(: preapre the tei:add :)
  element xhtml:span {
    $add/@xml:id ! attribute id { string(.) },
    attribute class {'add'},
    transfo:add-worker($add)
  }
Mathias Goebel's avatar
Mathias Goebel committed
815
816
};

Mathias Goebel's avatar
Mathias Goebel committed
817
declare %private function transfo:add-worker($node) {
Mathias Goebel's avatar
Mathias Goebel committed
818
let $style := (
Mathias Goebel's avatar
tei:add    
Mathias Goebel committed
819
          (:  if(contains($node/@rend, 'caret:V') and contains($node/@style, 'margin-left'))
Mathias Goebel's avatar
Mathias Goebel committed
820
            then 'left:' || number(analyze-string($node/@style, '-\d+\.\d')/fn:match/text()) + 0.2 || 'cm;'
Mathias Goebel's avatar
tei:add    
Mathias Goebel committed
821
            else :)
Mathias Goebel's avatar
Mathias Goebel committed
822
823
                if(contains($node/@style, 'margin-left'))
                then replace($node/@style, 'margin-left', 'left')
Mathias Goebel's avatar
tei:add    
Mathias Goebel committed
824
            else () (: ,
Mathias Goebel's avatar
Mathias Goebel committed
825
            if(number(substring-before(tokenize(transfo:lineHeight($node/ancestor::tei:zone[1]), ':')[2], 'cm')) lt 0.7) then ';top:-0.3cm;' else ()
Mathias Goebel's avatar
tei:add    
Mathias Goebel committed
826
  :)          )
Mathias Goebel's avatar
Mathias Goebel committed
827
828
829
830
831
return
if ($node/@place = ('above', 'below')) then (
        element xhtml:span {
            attribute class {
                $node/@place,
Mathias Goebel's avatar
Mathias Goebel committed
832
833
834
                if(contains($node/@rend, '3/4-circle')) then 'threequatercircle' else (),
                if(contains($node/@rend, 'semicircle(bottom)')) then 'semicircle bottom' else (),
                if(contains($node/@rend, 'semicircle(left)')) then 'semicircle left' else (),
Mathias Goebel's avatar
Mathias Goebel committed
835
836
                if(contains($node/@rend, 'semicircle(right)')) then 'semicircle right' else (),
                if(contains($node/@rend, 'caret:looped_arc')) then 'looped_arc' else ()
Mathias Goebel's avatar
Mathias Goebel committed
837
            },
Mathias Goebel's avatar
tei:add    
Mathias Goebel committed
838
            if($style = () ) then () else attribute style {$style},
Mathias Goebel's avatar
Mathias Goebel committed
839
840
841
842
        if($node/@rend="caret:looped_arc(pos-left)")
        then <xhtml:img src="/public/img/caret:looped-arc-pos-left.svg" width="140px" height="auto" style="left: -0.7cm; position: absolute;"/>
        else (),
        transfo:magic($node/node()),
843
844
845
846
847
        if(
                not($node/ancestor::tei:mod)
            and not( $node/@copyOf )
            and not( $node/tei:seg[@type="multiphrase"] or $node/ancestor::tei:seg[@type="multiphrase"] ) )
        then
Mathias Goebel's avatar
Mathias Goebel committed
848
849
            element xhtml:div {
                attribute class {'addHover italic'},
850
851
852
                'Hinzufügung',
                if($node/tei:del) then "durchgestrichen" else (),
                if(contains($node/@rend, 'caret')) then 'mit Einweisungszeichen' else ()
Mathias Goebel's avatar
Mathias Goebel committed
853
854
855
856
857
858
859
860
861
862
863
864
            }
        else (),
        if($node/@copyOf)
        then
            element xhtml:div {
                attribute class {'addHover italic'},
                'Wiederholung zur Verdeutlichung'
            }
        else ()
        },
        (if(starts-with(string($node/@rend), 'caret:'))then(transfo:caret($node))else())
)
Mathias Goebel's avatar
tei:add    
Mathias Goebel committed
865
866
867
868
869
870
871
872
873
874
875
else if($node/@rend = "|")
then
  element xhtml:span {
    $node/@xml:id ! attribute id { string(.) },
    attribute class {'rend-pipe'},
    text {"|"},
    element xhtml:div {
      attribute class {"addHover italic"},
      "Fontanes Korrekturzeichen: Trennstrich"
    }
  }
Mathias Goebel's avatar
Mathias Goebel committed
876
else
Mathias Goebel's avatar
tei:add    
Mathias Goebel committed
877
878
879
  element xhtml:span {
    attribute class {
      $node/@place,
Mathias Goebel's avatar
Mathias Goebel committed
880
881
      if($node/@place = "superimposed" and ($node/@next or $node/@prev))
        then 'linked'
882
883
        else()
      (:,if($node/parent::tei:mod ! local:modTest(.))
Mathias Goebel's avatar
Mathias Goebel committed
884
        then "addSesquipedalian"
885
        else ():)
Mathias Goebel's avatar
Mathias Goebel committed
886

Mathias Goebel's avatar
tei:add    
Mathias Goebel committed
887
888
889
890
891
892
893
894
895
896
897
898
899
    },
    if($node/@place = "left")
    then attribute style { "position:absolute;",$style }
    else (),
    transfo:magic($node/node()),
    if($node/@place != ('above', 'below') and contains($node/@rend, 'caret')) then transfo:caret($node) else (),
    if(not($node/ancestor::tei:mod or $node/tei:seg[@type="multiphrase"])) then
      element xhtml:div {
        attribute class {'addHover italic'},
        'Hinzufügung', if(contains($node/@rend, 'caret')) then 'mit Einweisungszeichen' else ()
      }
    else ()
  }
Mathias Goebel's avatar
Mathias Goebel committed
900
901
};

Mathias Goebel's avatar
Mathias Goebel committed
902
903
904
(:~
 : transforms a tei:restore to xhtml:span
 :)
Mathias Goebel's avatar
Mathias Goebel committed
905
declare function transfo:restore($restore as element(tei:restore))
Mathias Goebel's avatar
Mathias Goebel committed
906
as element(xhtml:span) {
907
908
909
910
911
912
913
914
915
916
917
918
  let $what := if($restore/tei:mod[@type="subst"]/tei:del[@rend="overwritten"]) then "Überschreibung" else "Durchstreichung"
  return
    element xhtml:span {
      attribute class {'restore'},
      element xhtml:div {
        attribute class {'restoreHover italic'},
        if($restore/parent::tei:seg/parent::tei:del)
        then $what || " gilt"
        else $what || " zurückgenommen"
      },
      transfo:magic($restore/node())
    }
Mathias Goebel's avatar
Mathias Goebel committed
919
920
921
922
923
};

(:~
 : transforms a tei:unclear to xhtml:span
 :)
Mathias Goebel's avatar
Mathias Goebel committed
924
declare function transfo:unclear($unclear as element(tei:unclear))
Mathias Goebel's avatar
Mathias Goebel committed
925
926
927
928
as element(xhtml:span) {
  element xhtml:span {
    attribute class { 'unclear' },
    $unclear/@xml:id ! attribute id { string(.) },
Mathias Goebel's avatar
Mathias Goebel committed
929
930
    transfo:magic($unclear/node()),
    transfo:tooltip($unclear)
Mathias Goebel's avatar
Mathias Goebel committed
931
932
933
934
935
936
  }
};

(:~
 : transforms a tei:rs to xhtml:span
 :)
Mathias Goebel's avatar
Mathias Goebel committed
937
declare function transfo:rs($rs as element(tei:rs))
Mathias Goebel's avatar
Mathias Goebel committed
938
939
940
941
942
943
944
945
946
as element(xhtml:span) {
  element xhtml:span {
    attribute class {
      'rs',
      if($rs/@type) then $rs/@type else (),
      if($rs/@ref) then substring-before($rs/@ref, ':') else ()
    },
    attribute data-ref { replace($rs/@ref, ":", "") },
    $rs/@xml:id ! attribute id { string(.) },
Mathias Goebel's avatar
Mathias Goebel committed
947
    transfo:magic($rs/node())
Mathias Goebel's avatar
Mathias Goebel committed
948
949
950
951
952
953
  }
};

(:~
 : transforms a tei:date to xhtml:span
 :)
Mathias Goebel's avatar
Mathias Goebel committed
954
declare function transfo:date($date as element(tei:date))
Mathias Goebel's avatar
Mathias Goebel committed
955
956
957
958
as element(xhtml:span) {
  element xhtml:span {
    $date/@xml:id ! attribute id { string(.) },
    attribute class {'date'},
Mathias Goebel's avatar
Mathias Goebel committed
959
    transfo:magic($date/node())
Mathias Goebel's avatar
Mathias Goebel committed
960
961
962
963
964
965
966
  }
};

(:~
 : transforms a tei:fw to xhtml:div or - in case of Fontanes hand - to
 : xhtml:span.
 :)
Mathias Goebel's avatar
Mathias Goebel committed
967
declare function transfo:fw($fw as element(tei:fw))
Mathias Goebel's avatar
Mathias Goebel committed
968
as item()* {
Mathias Goebel's avatar
   
Mathias Goebel committed
969
970
971
  if($fw/tei:figure//tei:ref/contains(., 'Seitenzahlabgrenzungslinie'))
    then <xhtml:hr class="Seitenzahlabgrenzungslinie"/>
  else if (($fw/preceding::tei:handShift[@new][1]/@new != '#Fontane')
Mathias Goebel's avatar
Mathias Goebel committed
972
973
974
975
976
977
978
      or not( exists( $fw/preceding::tei:handShift[@new] ) ))
  then
    element xhtml:div {
      attribute class {'fwWrapper'},
      element xhtml:span {
        $fw/@xml:id ! attribute id { string(.) },
        attribute class { 'fw' },
Mathias Goebel's avatar
Mathias Goebel committed
979
        transfo:magic($fw/node())}
Mathias Goebel's avatar
Mathias Goebel committed
980
981
982
983
984
    }
  else
    element xhtml:span {
      $fw/@xml:id ! attribute id { string(.) },
      attribute class {'fw-fontane'},
Mathias Goebel's avatar
Mathias Goebel committed
985
      transfo:magic($fw/node())
Mathias Goebel's avatar
Mathias Goebel committed
986
    }
Mathias Goebel's avatar
Mathias Goebel committed
987
};
Mathias Goebel's avatar
Mathias Goebel committed
988

Mathias Goebel's avatar
Mathias Goebel committed
989
990
(:~ transformation of tei:g to xhtml:span
 :)
Mathias Goebel's avatar
Mathias Goebel committed
991
declare function transfo:glyph($node as element(tei:g))
Mathias Goebel's avatar
Mathias Goebel committed
992
993
994
995
as element(xhtml:span) {
  if ($node/@ref='#mgem') then
    element xhtml:span {
      attribute class {'g mgem'},
Mathias Goebel's avatar
Mathias Goebel committed
996
      transfo:magic($node/node())
Mathias Goebel's avatar
Mathias Goebel committed
997
998
999
1000
    }
  else if ($node/@ref='#ngem') then
    element xhtml:span {
      attribute class {'g ngem'},
Mathias Goebel's avatar
Mathias Goebel committed
1001
      transfo:magic($node/node())
Mathias Goebel's avatar
Mathias Goebel committed
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
    }
  else if ($node/@ref="#rth") then
    element xhtml:span {
      attribute class {'g rth'},
      <xhtml:div class="hover">Reichstaler</xhtml:div>,
      <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="auto" viewBox="0 0 82 107">
        {element path {
          attribute fill {"none"},
          attribute stroke {"darkslategrey"},
          attribute stroke-width {"5"},
          attribute d {
            "M 24.73,35.82" ||
            " C 24.73,35.82 30.36,30.73 32.00,26.55" ||
            " 46.73,45.27 80.55,37.45 70.00,38.18" ||
            " 16.73,50.73 -2.55,99.09 19.09,101.82" ||
            " 52.00,103.45 57.09,80.00 42.91,80.91" ||
            " 11.82,83.64 35.45,105.45 52.00,99.64" }}}
      </svg>
    }
Mathias Goebel's avatar
Mathias Goebel committed
1021
1022
1023
1024
1025
  else if ($node/@ref='#vds') then
    element xhtml:span {
      attribute class {'g vds'},
      text {"&#840;"}
    }
Mathias Goebel's avatar
Mathias Goebel committed
1026
1027
1028
  else ()
};

Mathias Goebel's avatar
Mathias Goebel committed
1029
1030
1031
(:~
 : transforms a tei:space to xhtml:span
 :)
Mathias Goebel's avatar
Mathias Goebel committed
1032
declare function transfo:space($space as element(tei:space))
Mathias Goebel's avatar
Mathias Goebel committed
1033
1034
1035
1036
as element(xhtml:space) {
  element xhtml:span {
    attribute class {
      "space",
Mathias Goebel's avatar
Mathias Goebel committed
1037
1038
      string($space/@type),
      string($space/@unit) || string($space/@quantity)
Mathias Goebel's avatar
Mathias Goebel committed
1039
    },
Mathias Goebel's avatar
Mathias Goebel committed
1040
    if($space/@type = "pause")
Mathias Goebel's avatar
Mathias Goebel committed
1041
1042
1043
1044
1045
1046
    then
      element xhtml:div {
        attribute class {'spaceHover'},
        'Gedankenpause'
      }
    else (),
Mathias Goebel's avatar
Mathias Goebel committed
1047
    if($space/@type = "placeholder")
Mathias Goebel's avatar
Mathias Goebel committed
1048
1049
1050
    then
      element xhtml:div {
        attribute class {'spaceHover'},
Mathias Goebel's avatar
Mathias Goebel committed
1051
        'Platzhalter'
Mathias Goebel's avatar
Mathias Goebel committed
1052
1053
1054
1055
      }
    else ()
  }
};
Mathias Goebel's avatar
Mathias Goebel committed
1056

Mathias Goebel's avatar
Mathias Goebel committed
1057
1058
1059
(:~
 : transforms a tei:choice to xhtml:span
 :)
Mathias Goebel's avatar
Mathias Goebel committed
1060
declare function transfo:choice($choice as element(tei:choice))
Mathias Goebel's avatar
Mathias Goebel committed
1061
1062
1063
as element(xhtml:span) {
  element xhtml:span {
    attribute class {'choice'},
Mathias Goebel's avatar
Mathias Goebel committed
1064
    if ($choice/tei:expan) then
Mathias Goebel's avatar
Mathias Goebel committed
1065
1066
      element xhtml:div {
        attribute class {'expan italic'},
Mathias Goebel's avatar
Mathias Goebel committed
1067
        let $count := count($choice//tei:expan)
Mathias Goebel's avatar
Mathias Goebel committed
1068
        return
Mathias Goebel's avatar
Mathias Goebel committed
1069
          if($count = 1) then $choice//tei:expan/text()
Mathias Goebel's avatar
Mathias Goebel committed
1070
          else
Mathias Goebel's avatar
Mathias Goebel committed
1071
            for $expan at $pos in $choice//tei:expan
Mathias Goebel's avatar
Mathias Goebel committed
1072
              return
Mathias Goebel's avatar
Mathias Goebel committed
1073
                if($pos = ($count - 1)) then $expan || '&#x2003;oder&#x2003;'
Mathias Goebel's avatar
Mathias Goebel committed
1074
1075
                else if($pos = $count) then $expan/text()
                else $expan/text() || ',&#x2003;'
Mathias Goebel's avatar
Mathias Goebel committed
1076
1077
      }
    else (),
Mathias Goebel's avatar
Mathias Goebel committed
1078
    transfo:magic($choice/node())
Mathias Goebel's avatar
Mathias Goebel committed
1079