gfl-indexer.xslt 25.8 KB
Newer Older
Dennis Neumann's avatar
Dennis Neumann committed
1
2
<?xml version="1.0" encoding="utf-8"?>

Dennis Neumann's avatar
Dennis Neumann committed
3
4
<!-- 

Dennis Neumann's avatar
Dennis Neumann committed
5
This script produces two types of Solr XML documents, representing letters and individual pages of those letters.
Dennis Neumann's avatar
Dennis Neumann committed
6

Dennis Neumann's avatar
Dennis Neumann committed
7
8
9
10
11
12
13
The letter documents contain many metadata fields and two text fields. The metadata fields are
values that are copied from the TEI files. The text fields are described next.

Field 'fulltext'

This is just plain text copied from the complete TEI file. Line breaks and page beginnings are
transformed to whitespace. This field can be useful for searching or for generating highlighting snippets. 
Dennis Neumann's avatar
Dennis Neumann committed
14
15
16

Field 'fulltext_html'

Dennis Neumann's avatar
Dennis Neumann committed
17
18
19
20
21
22
This field  contains the HTML representation of the text of a TEI file (e. g. a Goethe letter).
A letter that consists of several pages is split on-the-fly into those pages.
However, the pages are all kept in this one field. The templates that are used here are the same
as the ones for the individual page documents (see below).

The letters are composed of different parts, for example 'opener', 'closer', 'salute'.
Dennis Neumann's avatar
Dennis Neumann committed
23
24
25
All those parts are represented here as <div>'s with the corresponding CSS classes.
The frontend viewer must decide how to format those parts and present them to the user.

Dennis Neumann's avatar
Dennis Neumann committed
26
The original TEI files contain mark-up for many in-text parts, like dates, names, underlined words, etc.
Dennis Neumann's avatar
Dennis Neumann committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Most of these are also transformed to <div>'s with their own CSS classes.
Although the in-text parts are by nature inline elements, we use here <div>'s and not <span>'s.
The reason is that Solr seems to have problems when highlighting fields that contain <span>'s
by sometimes producing corrupt HTML.
By using <div>'s, we avoid this problem.
In the frontend, these <div>'s must be set to 'display: inline'.

Some other in-text parts are transformed to special HTML elements.
For example, superscripted text is marked as <sup>, because HTML offers the appropriate element.

The project is still continuing and new TEI files are being produced.
That's why there might be new elements in the future that cannot be handled yet in this script.
The text of such TEI elements is enclosed in HTML elements of class 'unknown-element'.
Furthermore, a warning message is generated that contains data of the first occurrence of such a new element.


Dennis Neumann's avatar
Dennis Neumann committed
43
44
45
46
The second kind of documents that are produced are page documents.
The resulting pages are in the HTML format.
As the TEI file is processed, the TEI XML structure is split into pages using 
the page beginning elements (<pb/>).
Dennis Neumann's avatar
Dennis Neumann committed
47
Refer to comments in the code to understand the used algorithm.
Dennis Neumann's avatar
Dennis Neumann committed
48

Dennis Neumann's avatar
Dennis Neumann committed
49

50
-->
Dennis Neumann's avatar
Dennis Neumann committed
51

Dennis Neumann's avatar
Dennis Neumann committed
52
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
53
54
55
   xpath-default-namespace="http://www.tei-c.org/ns/1.0" xmlns:gfl="http://sub.gfl.de"
   xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:saxon="http://saxon.sf.net/" exclude-result-prefixes="gfl saxon xs">

Dennis Neumann's avatar
Dennis Neumann committed
56
   <xsl:output method="xml" indent="yes" saxon:suppress-indentation="div" />
Dennis Neumann's avatar
Dennis Neumann committed
57
   <xsl:strip-space elements="*" />
58
   <xsl:preserve-space elements="msIdentifier bibl p" />
59
60

   <xsl:template match="/">
61
62
63
64
      <xsl:apply-templates select="TEI" />
   </xsl:template>

   <xsl:template match="TEI">
65
66
      <add>
         <doc>
67
            <xsl:apply-templates select="teiHeader| text" />
Dennis Neumann's avatar
Dennis Neumann committed
68
69
70
71
72
            <xsl:for-each select="distinct-values(//@xml:lang)">
               <field name="language">
                  <xsl:value-of select="." />
               </field>
            </xsl:for-each>
73
            <xsl:apply-templates select="facsimile" />
bettin5's avatar
bettin5 committed
74
            <xsl:apply-templates select="//body/listBibl" />
75
         </doc>
76
         <xsl:apply-templates select="text" mode="page_splitting" />
bettin5's avatar
bettin5 committed
77
78
         
         </add>
79
   </xsl:template>
bettin5's avatar
bettin5 committed
80
   
81
   <!-- check if it is the right output -->
bettin5's avatar
bettin5 committed
82
83
84
   <xsl:template match="listBibl">
      <doc> 
         <xsl:for-each select="bibl">
bettin5's avatar
bettin5 committed
85
            <doc>
bettin5's avatar
bettin5 committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
               <field name="literatur_id"> 
                  <xsl:value-of select="./@xml:id"/>
               </field>
                  <xsl:for-each select="relatedItem">
                  <field name="uri">
                     <xsl:value-of select="ref/@target"/>
                  </field>
                  </xsl:for-each>                  
               <xsl:for-each select="author">
                  <field name="author"> 
                     <xsl:value-of select="."/>
                  </field>
               </xsl:for-each>
               <xsl:for-each select="editor">
                  <field name="editor"> 
                     <xsl:value-of select="./normalize-space()"/>
                  </field>
               </xsl:for-each>
               <xsl:for-each select="title">
105
                  <field name="title_literatur"> 
bettin5's avatar
bettin5 committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
                  <xsl:value-of select="./normalize-space()"/>
               </field>
               </xsl:for-each>
               
               <field name="edition"> 
                  <xsl:value-of select="edition"/>
               </field>
               <field name="pub_place"> 
                  <xsl:value-of select="pubPlace/name"/>
               </field>
               <field name="publisher">
                  <xsl:value-of select="publisher/normalize-space()"/>
               </field>               
               <xsl:if test="date/@type='pub'">
                  <field name="pub_date">
                     <xsl:value-of select="date"/>
                  </field>
               </xsl:if>
               <field name="idno">
                  <xsl:value-of select="idno"/> 
               </field>
               <xsl:for-each select="relatedItem">
                  <field name="refs"> 
                     <xsl:value-of select="./normalize-space()"/>
                  </field>
               </xsl:for-each>
bettin5's avatar
bettin5 committed
132
           </doc>
bettin5's avatar
bettin5 committed
133
           </xsl:for-each>
bettin5's avatar
bettin5 committed
134
         
bettin5's avatar
bettin5 committed
135
136
137
      </doc>
   </xsl:template>
   
Dennis Neumann's avatar
Dennis Neumann committed
138

139
140
141
142
   <xsl:template match="text()" mode="text_only">
      <xsl:variable name="currentText" select="replace(., '\s+', ' ')" />
      <xsl:choose>
         <xsl:when test="ends-with(., '-')">
Dennis Neumann's avatar
Dennis Neumann committed
143
144
            <!-- These are cases where one word is divided between two lines. 
            The minus sign is removed here, the line break (<lb/>) is removed in its own template. -->
145
146
147
            <xsl:value-of select="substring($currentText, 1, string-length($currentText)-1)" />
         </xsl:when>
         <xsl:when test="ends-with(., '&#0173;')">
Dennis Neumann's avatar
Dennis Neumann committed
148
149
150
            <!-- A soft hyphen is a convention to mark a hyphen that belongs to the word or is a hyphen on its own.
            For now, it is just replaced by a minus sign. 
            Later, it might be useful to differentiate between word divisions and hyphens. -->
151
152
153
154
155
156
            <xsl:value-of select="replace($currentText, '&#0173;', '-')" />
         </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="$currentText" />
         </xsl:otherwise>
      </xsl:choose>
Dennis Neumann's avatar
Dennis Neumann committed
157
158
159
160
161
   </xsl:template>
   
   <!--###########   Header   #######################-->
   
   <xsl:template match="teiHeader">
Dennis Neumann's avatar
Dennis Neumann committed
162
      <xsl:apply-templates select="fileDesc | profileDesc/textClass" />
Dennis Neumann's avatar
Dennis Neumann committed
163
164
165
166
167
168
169
   </xsl:template>
   
   <xsl:template match="fileDesc">
      <xsl:apply-templates select="titleStmt/title" />
      <xsl:apply-templates select="titleStmt/title[@type='desc']/name" />
      <xsl:apply-templates select="titleStmt/title[@type='desc']/date[@type='orn']" />
      <xsl:apply-templates select="titleStmt/author/name" />
170
      <xsl:apply-templates select="sourceDesc" />
Dennis Neumann's avatar
Dennis Neumann committed
171
      <xsl:apply-templates select="publicationStmt/availability/licence" />
Dennis Neumann's avatar
Dennis Neumann committed
172
173
   </xsl:template>
   
Dennis Neumann's avatar
Dennis Neumann committed
174
175
176
177
   <xsl:template match="profileDesc/textClass">
      <xsl:apply-templates select="keywords/term" />
   </xsl:template>
   
Dennis Neumann's avatar
Dennis Neumann committed
178
   <xsl:template match="title[@type='short']">
Dennis Neumann's avatar
Dennis Neumann committed
179
      <field name="short_title">
Dennis Neumann's avatar
Dennis Neumann committed
180
         <xsl:apply-templates mode="text_only" />
Dennis Neumann's avatar
Dennis Neumann committed
181
182
183
      </field>
   </xsl:template>

Dennis Neumann's avatar
Dennis Neumann committed
184
   <xsl:template match="title[@type='desc']">
Dennis Neumann's avatar
Dennis Neumann committed
185
      <field name="title">
Dennis Neumann's avatar
Dennis Neumann committed
186
         <xsl:apply-templates mode="text_only" />
Dennis Neumann's avatar
Dennis Neumann committed
187
188
189
      </field>
   </xsl:template>

Dennis Neumann's avatar
Dennis Neumann committed
190
   <xsl:template match="title/name[@type='place' and @subtype='orn']">
Dennis Neumann's avatar
Dennis Neumann committed
191
      <field name="origin_place">
Dennis Neumann's avatar
Dennis Neumann committed
192
         <xsl:apply-templates mode="text_only" />
Dennis Neumann's avatar
Dennis Neumann committed
193
194
195
      </field>
   </xsl:template>

Dennis Neumann's avatar
Dennis Neumann committed
196
   <xsl:template match="title/name[@type='place' and @subtype='dtn']">
Dennis Neumann's avatar
Dennis Neumann committed
197
      <field name="destination_place">
Dennis Neumann's avatar
Dennis Neumann committed
198
         <xsl:apply-templates mode="text_only" />
Dennis Neumann's avatar
Dennis Neumann committed
199
200
201
      </field>
   </xsl:template>

Dennis Neumann's avatar
Dennis Neumann committed
202
   <xsl:template match="title/name[@type='person' and @subtype='rcp']">
Dennis Neumann's avatar
Dennis Neumann committed
203
      <field name="recipient">
Dennis Neumann's avatar
Dennis Neumann committed
204
         <xsl:apply-templates mode="text_only" />
Dennis Neumann's avatar
Dennis Neumann committed
205
206
207
      </field>
   </xsl:template>

Dennis Neumann's avatar
Dennis Neumann committed
208
   <xsl:template match="title/date[@type='orn']">
Dennis Neumann's avatar
Dennis Neumann committed
209
210
211
212
213
      <field name="origin_date">
         <xsl:value-of select="@when" />
      </field>
   </xsl:template>

Dennis Neumann's avatar
Dennis Neumann committed
214
   <xsl:template match="author/name[@type='person' and @subtype='aut']">
Dennis Neumann's avatar
Dennis Neumann committed
215
      <field name="author">
Dennis Neumann's avatar
Dennis Neumann committed
216
         <xsl:apply-templates mode="text_only" />
Dennis Neumann's avatar
Dennis Neumann committed
217
218
      </field>
   </xsl:template>
219
220
221
222
223
224
   
   <xsl:template match="sourceDesc">
      <field name="source_description">
         <xsl:apply-templates mode="text_only" />
      </field>
   </xsl:template>
Dennis Neumann's avatar
Dennis Neumann committed
225

Dennis Neumann's avatar
Dennis Neumann committed
226
   <xsl:template match="licence">
Dennis Neumann's avatar
Dennis Neumann committed
227
      <field name="license">
Dennis Neumann's avatar
Dennis Neumann committed
228
229
230
231
         <xsl:value-of select="text()" />
      </field>
   </xsl:template>

Dennis Neumann's avatar
Dennis Neumann committed
232
233
234
235
236
237
238
239
240
241
242
243
   <xsl:template match="textClass/keywords[@scheme='#gnd']/term">
      <field name="gnd_keyword">
         <xsl:apply-templates mode="text_only" />
      </field>
   </xsl:template>

   <xsl:template match="textClass/keywords[@scheme='free']/term">
      <field name="free_keyword">
         <xsl:apply-templates mode="text_only" />
      </field>
   </xsl:template>

bettin5's avatar
bettin5 committed
244
   <!--###################   text/body   ##########################-->  
245
246
   
   <xsl:template match="facsimile">
bettin5's avatar
bettin5 committed
247
      <field name="image_ids"> 
248
249
         <xsl:value-of select="./graphic/@xml:id"/>
      </field>
bettin5's avatar
bettin5 committed
250
      <field name="image_urls">
251
252
253
254
         <xsl:value-of select="./graphic/@url"/>
      </field> 
   </xsl:template> 

Dennis Neumann's avatar
Dennis Neumann committed
255
256
257
258
259

   <xsl:template match="text">
      <field name="id">
         <xsl:value-of select="@xml:id" />
      </field>
260
261
262
263
      <field name="doctype">article</field>
      <field name="number_of_pages">
         <xsl:value-of select="count(//pb)" />
      </field>
Dennis Neumann's avatar
Dennis Neumann committed
264
      <field name="fulltext">
Dennis Neumann's avatar
Dennis Neumann committed
265
         <xsl:apply-templates select="body" mode="text_only" />
Dennis Neumann's avatar
Dennis Neumann committed
266
      </field>
Dennis Neumann's avatar
Dennis Neumann committed
267
268
269
      <field name="fulltext_html">
         <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
            <div class="article">
270
271
272
273
               <xsl:variable name="context" select="." />
               <xsl:for-each-group select="descendant::node()[not(node())]" group-starting-with="pb">
                  <xsl:if test="self::pb">
                     <div class="page">
Dennis Neumann's avatar
Dennis Neumann committed
274
275
276
                        <xsl:call-template name="page-beginning-with-possible-link">
                           <xsl:with-param name="current-pb" select="." />
                        </xsl:call-template>
277
278
279
280
281
282
                        <xsl:apply-templates select="$context/*" mode="page_splitting">
                           <xsl:with-param name="restricted-to" select="current-group()/ancestor-or-self::node()" tunnel="yes" />
                        </xsl:apply-templates>
                     </div>
                  </xsl:if>
               </xsl:for-each-group>
Dennis Neumann's avatar
Dennis Neumann committed
283
284
285
            </div>
         <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
      </field>
Dennis Neumann's avatar
Dennis Neumann committed
286
      <xsl:apply-templates select=".//note[@type='com']" />
287
   </xsl:template>
Dennis Neumann's avatar
Dennis Neumann committed
288
289
   
   <xsl:template match="body | div" mode="text_only">
290
      <xsl:apply-templates mode="text_only"/>
Dennis Neumann's avatar
Dennis Neumann committed
291
292
   </xsl:template>

293
   <xsl:template match="p | salute | signed | addrLine | dateline" mode="text_only">
Dennis Neumann's avatar
Dennis Neumann committed
294
295
296
      <xsl:apply-templates mode="text_only" />
      <xsl:text> </xsl:text>
   </xsl:template>
297

Dennis Neumann's avatar
Dennis Neumann committed
298
   <xsl:template match="note[@place='end' and not(@type='com')]" mode="text_only">
299
300
301
302
      <xsl:text> </xsl:text>
      <xsl:apply-templates mode="text_only" />
   </xsl:template>

303
   <xsl:template match="lb" mode="text_only">
304
305
306
307
308
309
310
311
312
313
314
315
316
317
      <xsl:variable name="precedingText" select="preceding-sibling::text()[1]" />
      <xsl:choose>
         <xsl:when test="ends-with($precedingText, '-')">
            <!-- Cases where a word is divided between two lines -->
            <!-- no output -->
         </xsl:when>
         <xsl:when test="ends-with($precedingText, '&#0173;') and not(ends-with($precedingText, ' &#0173;'))">
            <!-- Cases where the hyphen belongs to the word (Anna-<lb/>Lena) -->
            <!-- no output -->
         </xsl:when>
         <xsl:otherwise>
            <xsl:text> </xsl:text>
         </xsl:otherwise>
      </xsl:choose>
318
   </xsl:template>
Dennis Neumann's avatar
Dennis Neumann committed
319

320
321
322
323
324
325
326
327
   <xsl:template match="pb" mode="text_only">
      <xsl:text> </xsl:text>
   </xsl:template>

   <xsl:template match="space" mode="text_only">
      <xsl:text> </xsl:text>
   </xsl:template>

328
   <xsl:template match="note[@type='com']" mode="text_only">
329
   </xsl:template>
Dennis Neumann's avatar
Dennis Neumann committed
330
   
Dennis Neumann's avatar
Dennis Neumann committed
331
332
333
334
335
336
   <xsl:template match="note[@type='com']">
      <field name="note_comment">
         <xsl:apply-templates mode="text_only" />
      </field>
   </xsl:template>
   
Dennis Neumann's avatar
Dennis Neumann committed
337
   
338
   <!-- %%%%%%%%%%%%% page splitting and HTML generating %%%%%%%%%%%%%%%%%%%%%%% -->
339

Dennis Neumann's avatar
Dennis Neumann committed
340
341
342
343
   <!-- Here we start the page splitting algorithm. 
      In general, it groups all elements between two <pb/>'s and creates one page for each such group.
      Note: We use a trick with a tunnel parameter. The templates that are run from here must check 
      if they really should execute or not using that tunnel parameter. -->
344
   <xsl:template match="text" mode="page_splitting">
Dennis Neumann's avatar
Dennis Neumann committed
345
      <!-- We keep the parent of all pages (-> super-parent). -->
346
      <xsl:variable name="context" select="." />
Dennis Neumann's avatar
Dennis Neumann committed
347
348
      <!-- We make groups of only 'small' nodes, like text and <pb/>.
         We need this granularity, because a <pb/> can separate two text nodes to different pages. -->
349
350
351
      <xsl:for-each-group select="descendant::node()[not(node())]" group-starting-with="pb">
         <xsl:if test="self::pb">
            <doc>
Dennis Neumann's avatar
Dennis Neumann committed
352
               <xsl:variable name="pageNumber" select="count(preceding::pb) + 1" />
353
               <field name="id">
Dennis Neumann's avatar
Dennis Neumann committed
354
                  <xsl:value-of select="$context/@xml:id" />
355
356
357
                  <xsl:text>_page</xsl:text>
                  <xsl:value-of select="$pageNumber" />
               </field>
Dennis Neumann's avatar
Dennis Neumann committed
358
               <field name="article_id">
Dennis Neumann's avatar
Dennis Neumann committed
359
                  <xsl:value-of select="$context/@xml:id" />
360
               </field>
361
               <field name="doctype">page</field>
362
363
364
365
366
367
               <field name="page_number">
                  <xsl:value-of select="$pageNumber" />
               </field>
               <field name="html_page">
                  <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
                  <div class="page">
Dennis Neumann's avatar
Dennis Neumann committed
368
369
370
                     <xsl:call-template name="page-beginning-with-possible-link">
                        <xsl:with-param name="current-pb" select="." />
                     </xsl:call-template>
Dennis Neumann's avatar
Dennis Neumann committed
371
                     <!-- We run the templates of all the super-parent's children... -->
372
                     <xsl:apply-templates select="$context/*" mode="page_splitting">
Dennis Neumann's avatar
Dennis Neumann committed
373
374
375
376
377
                        <!-- ..., but we use a trick with a tunnel parameter to restrict the actually executed templates 
                           to the ones relevant for the current page. 
                           We choose the grouped nodes, as well as all their ancestors.
                           We need all the ancestors to construct correctly opened and closed elements 
                           that otherwise would be cut in two by the <pb/>. -->
378
379
380
381
382
                        <xsl:with-param name="restricted-to" select="current-group()/ancestor-or-self::node()" tunnel="yes" />
                     </xsl:apply-templates>
                  </div>
                  <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
               </field>
Dennis Neumann's avatar
Dennis Neumann committed
383
384
385
386
387
               <xsl:for-each select="distinct-values(//@xml:lang)">
                  <field name="language">
                     <xsl:value-of select="." />
                  </field>
               </xsl:for-each>
388
               <xsl:if test="./@facs">
bettin5's avatar
bettin5 committed
389
                  <field name="image_id"> 
390
391
392
                     <xsl:value-of select="./@facs"/>
                  </field>
               </xsl:if>
393
394
395
396
397
            </doc>
         </xsl:if>
      </xsl:for-each-group>
   </xsl:template>

Dennis Neumann's avatar
Dennis Neumann committed
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
   <xsl:template name="page-beginning-with-possible-link">
      <xsl:param name="current-pb" />
      <div class="page-beginning">
         <xsl:variable name="facsId" select="substring($current-pb/@facs, 2, string-length($current-pb/@facs))" />
         <xsl:variable name="graphicUrl" select="id($facsId)/@url" />
         <xsl:variable name="graphicUrlWithoutJpg">
            <xsl:value-of select="if (ends-with($graphicUrl, '.jpg')) then substring($graphicUrl, 1, string-length($graphicUrl)-4) else $graphicUrl" />
         </xsl:variable>
         <xsl:choose>
            <xsl:when test="$current-pb/@n ne '' and $graphicUrlWithoutJpg">
               <a href="{concat('/', $graphicUrlWithoutJpg)}" target="_blank">
                  <xsl:value-of select="$current-pb/@n" />
               </a>
            </xsl:when>
            <xsl:when test="$current-pb/@n ne ''">
               <xsl:value-of select="$current-pb/@n" />
            </xsl:when>
            <xsl:otherwise>
               <xsl:text> </xsl:text>
            </xsl:otherwise>
         </xsl:choose>
      </div>
   </xsl:template>

422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
   <xsl:template match="pb" mode="page_splitting" />

   <xsl:template match="*" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <xsl:message>
            <xsl:text>Unknown element &lt;</xsl:text>
            <xsl:value-of select="local-name()" />
            <xsl:if test="@rendition">
               <xsl:text> rendition="</xsl:text>
               <xsl:value-of select="@rendition" />
               <xsl:text>"</xsl:text>
            </xsl:if>
            <xsl:if test="@type">
               <xsl:text> type="</xsl:text>
               <xsl:value-of select="@type" />
               <xsl:text>"</xsl:text>
            </xsl:if>
            <xsl:text>&gt; - first occurrence: </xsl:text>
         </xsl:message>
         <span class="unknown-element">
            <xsl:apply-templates mode="page_splitting" />
         </span>
      </xsl:if>
   </xsl:template>

   <xsl:template match="body | div | front" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <xsl:apply-templates mode="page_splitting" />
      </xsl:if>
   </xsl:template>

   <xsl:template match="p | opener | salute | seg | bibl | closer | signed | dateline | date 
   | label[not(@rendition)] | choice | abbr | expan | postscript" mode="page_splitting">
457
458
459
460
461
462
463
464
465
466
467
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="{local-name(.)}">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="text()" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
         <xsl:variable name="currentText" select="replace(., '\s+', ' ')" />
         <xsl:choose>
            <xsl:when test="ends-with(., '&#0173;')">
               <xsl:value-of select="replace($currentText, '&#0173;', '-')" />
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="$currentText" />
            </xsl:otherwise>
         </xsl:choose>
      </xsl:if>
   </xsl:template>

   <xsl:template match="lb" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <br />
484
485
486
      </xsl:if>
   </xsl:template>

487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
   <xsl:template match="space[@unit='lines']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <xsl:variable name="emptyLines" select="@quantity" />
         <xsl:choose>
            <xsl:when test="$emptyLines castable as xs:integer">
               <xsl:for-each select="1 to $emptyLines">
                  <br />
               </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
               <br />
            </xsl:otherwise>
         </xsl:choose>
      </xsl:if>
   </xsl:template>

   <xsl:template match="name[@type='place']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="place">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="name[@type='org']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="org">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="name[@type='person']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="person">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="name[@type='object']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="object">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="rs[@type='person']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="rs-person">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="rs[@type='place']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="rs-place">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="note[@type='com']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="note-comment">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="note[@type='footnote']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="note-footnote">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="note[not(@type)]" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="note">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="hi[@rendition='simple:underline']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="underline">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="hi[@rendition='simple:doubleunderline']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="doubleunderline">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="hi[@rendition='simple:superscript']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <sup>
            <xsl:apply-templates mode="page_splitting" />
         </sup>
      </xsl:if>
   </xsl:template>

   <xsl:template match="hi[@rendition='simple:subscript']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <sub>
            <xsl:apply-templates mode="page_splitting" />
         </sub>
      </xsl:if>
   </xsl:template>

   <xsl:template match="hi[@rendition='simple:italic']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="italic">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="hi[@rendition='simple:letterspace']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="letterspace">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="hi[@rendition='simple:right']" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <div class="right">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>

   <xsl:template match="ref[@target]" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <a href="{@target}">
            <xsl:apply-templates mode="page_splitting" />
         </a>
      </xsl:if>
   </xsl:template>

   <xsl:template match="head[@rendition] | label[@rendition]" mode="page_splitting">
      <xsl:param name="restricted-to" tunnel="yes" />
      <xsl:if test="exists(. intersect $restricted-to)">
         <xsl:variable name="classNames" select="local-name(), substring-after(@rendition, 'simple:')" />
         <div class="{$classNames}">
            <xsl:apply-templates mode="page_splitting" />
         </div>
      </xsl:if>
   </xsl:template>
666

Dennis Neumann's avatar
Dennis Neumann committed
667
</xsl:stylesheet>