-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckUp.xsl
554 lines (503 loc) · 20.6 KB
/
checkUp.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xpath-default-namespace="http://www.tei-c.org/ns/1.0" xmlns:e="http://distantreading.net/eltec/ns" exclude-result-prefixes="xs e" version="2.0">
<!--
- check author and title syntax in titleStmt
- remove empty front or back
- check syntax for @target values on ref
- rewrite any existing publicationStmt to provide zenodo info
- check for wrongly nested divs; turn divs into milestones if necessary
- add a change element to revisionDesc
- remove any note elements not in div type note
and a few more things...
-->
<xsl:param name="fileName">UnknownFile</xsl:param>
<xsl:param name="publish">https://doi.org/10.5281/zenodo.3462435</xsl:param>
<xsl:param name="ERNfile">../ELTeC/listERN.1.1.xml</xsl:param>
<xsl:param name="verbose"/>
<!-- iff true, witter on -->
<xsl:variable name="today">
<xsl:value-of select="format-date(current-date(), '[Y0001]-[M01]-[D01]')"/>
</xsl:variable>
<xsl:variable name="textId">
<xsl:value-of select="TEI/@xml:id"/>
</xsl:variable>
<xsl:variable name="textLang">
<xsl:choose>
<xsl:when test="contains(TEI/@xml:lang,'-')">
<xsl:value-of select="substring-before(TEI/@xml:lang,'-')"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="TEI/@xml:lang"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="repoName">
<xsl:choose>
<xsl:when test="$textLang eq 'cz'">cze</xsl:when>
<xsl:when test="$textLang eq 'de'">deu</xsl:when>
<xsl:when test="$textLang eq 'en'">eng</xsl:when>
<xsl:when test="$textLang eq 'fr'">fra</xsl:when>
<xsl:when test="$textLang eq 'hu'">hun</xsl:when>
<xsl:when test="$textLang eq 'no'">nor</xsl:when>
<xsl:when test="$textLang eq 'nb'">nor</xsl:when>
<xsl:when test="$textLang eq 'pl'">pol</xsl:when>
<xsl:when test="$textLang eq 'pt'">por</xsl:when>
<xsl:when test="$textLang eq 'ro'">rom</xsl:when>
<xsl:when test="$textLang eq 'sl'">slv</xsl:when>
<xsl:when test="$textLang eq 'sp'">spa</xsl:when>
<xsl:when test="$textLang eq 'sr'">srp</xsl:when>
<xsl:when test="$textLang eq 'sw'">swe</xsl:when>
<xsl:when test="$textLang eq 'uk'">ukr</xsl:when>
<xsl:otherwise> <xsl:message>ERROR : Unanticipated text language <xsl:value-of select="$textLang"/> </xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="editionWord">
<xsl:choose>
<xsl:when test="$textLang eq 'cs'">vydání ELTeC</xsl:when>
<xsl:when test="$textLang eq 'de'">ELTeC ausgabe</xsl:when>
<xsl:when test="$textLang eq 'en'">ELTeC edition</xsl:when>
<xsl:when test="$textLang eq 'fr'">édition ELTeC</xsl:when>
<xsl:when test="$textLang eq 'hu'">ELTeC kiadás</xsl:when>
<xsl:when test="$textLang eq 'it'">edizione ELTeC</xsl:when>
<xsl:when test="$textLang eq 'lv'">ELTeC izdevums</xsl:when>
<xsl:when test="$textLang eq 'no'">ELTeC-utgave</xsl:when>
<xsl:when test="$textLang eq 'po'">edycja ELTeC</xsl:when>
<xsl:when test="$textLang eq 'pt'">edição para o ELTeC</xsl:when>
<xsl:when test="$textLang eq 'ro'">ediție ELTeC</xsl:when>
<xsl:when test="$textLang eq 'sl'">Izdaja ELTeC</xsl:when>
<xsl:when test="$textLang eq 'sp'">edición ELTeC</xsl:when>
<xsl:when test="$textLang eq 'sr'">ELTeC издање</xsl:when>
<xsl:otherwise>ELTeC edition</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- <xsl:variable name="respWord">
<xsl:choose>
<xsl:when test="$textLang eq 'cs'">vydání ELTeC</xsl:when>
<xsl:when test="$textLang eq 'de'">ELTeC ausgabe</xsl:when>
<xsl:when test="$textLang eq 'en'">ELTeC encoding</xsl:when>
<xsl:when test="$textLang eq 'fr'">édition ELTeC</xsl:when>
<xsl:when test="$textLang eq 'hu'">ELTeC kiadás</xsl:when>
<xsl:when test="$textLang eq 'it'">edizione ELTeC</xsl:when>
<xsl:when test="$textLang eq 'lv'">ELTeC izdevums</xsl:when>
<xsl:when test="$textLang eq 'no'">ELTeC-utgave</xsl:when>
<xsl:when test="$textLang eq 'po'">edycja ELTeC</xsl:when>
<xsl:when test="$textLang eq 'pt'">codificação segundo as normas do ELTeC</xsl:when>
<xsl:when test="$textLang eq 'ro'">ediție ELTeC</xsl:when>
<xsl:when test="$textLang eq 'sl'">Izdaja ELTeC</xsl:when>
<xsl:when test="$textLang eq 'sp'">edición ELTeC</xsl:when>
<xsl:when test="$textLang eq 'sr'">ELTeC издање</xsl:when>
<xsl:otherwise>ELTeC edition</xsl:otherwise>
</xsl:choose></xsl:variable>
-->
<!-- Basically, an identity transform -->
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- start by throwing away any existing xmlmodel PI and putting in our own -->
<xsl:template match="processing-instruction('xml-model')"/>
<xsl:template match="TEI">
<xsl:text>
</xsl:text>
<xsl:processing-instruction name="xml-model">
href="../../Schemas/eltec-1.rng" type="application/xml"
schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction>
<xsl:text>
</xsl:text>
<xsl:processing-instruction name="xml-model">
href="../../Schemas/eltec-1.rng" type="application/xml"
schematypens="http://purl.oclc.org/dsdl/schematron"</xsl:processing-instruction>
<xsl:text>
</xsl:text>
<!-- <xsl:message>
<xsl:text>*** File </xsl:text>
<xsl:value-of select="$fileName"/>
<xsl:text> on </xsl:text>
<xsl:value-of select="$today"/>
<xsl:text> (</xsl:text>
<xsl:value-of select="teiHeader/fileDesc/titleStmt/title[1]"/>
<xsl:text>) ***
</xsl:text>
</xsl:message>
-->
<!-- test the xml:id -->
<xsl:if test="not(matches($textId, '[A-Z]+[0-9]+'))">
<xsl:message>Weird xml_id : <xsl:value-of select="$textId"/></xsl:message>
</xsl:if>
<xsl:if test="not(starts-with(substring-after($fileName, '/'), $textId))">
<xsl:message>ERROR : xml_id <xsl:value-of select="$textId"/> disagrees with filename <xsl:value-of select="$fileName"/></xsl:message>
</xsl:if>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
<xsl:value-of select="e:warning(count(text//div[not(@type)]), 'untyped divs found')"/>
<!-- missing @type is permitted by schema but if @type is supplied, its values are constrained -->
</xsl:template>
<!-- now some specific checks on ... titleStmt -->
<xsl:template match="titleStmt/title[1]">
<xsl:copy>
<xsl:apply-templates select="./@*"/>
<xsl:value-of select="."/>
<xsl:if test="not(contains(., 'ELTeC'))">
<xsl:text> : </xsl:text>
<xsl:value-of select="$editionWord"/>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template match="titleStmt/author/@xml:id"/>
<xsl:template match="titleStmt/author">
<xsl:copy>
<xsl:if test="@xml:id">
<xsl:attribute name="n">
<xsl:value-of select="@xml:id"/>
</xsl:attribute>
<xsl:message>WARNING: <xsl:value-of select="$textId"/> @xml:id on author changed to @n</xsl:message>
</xsl:if>
<xsl:variable select="normalize-space(.)" name="theString"/>
<xsl:variable select="substring-before($theString, '(')" name="theAuthor"/>
<xsl:variable select="substring-before(substring-after($theString, '('), ')')" name="theDates"/>
<xsl:choose>
<xsl:when test="string-length($theAuthor) < 1">
<xsl:message>WARNING: <xsl:value-of select="$textId"/>
<xsl:text> : </xsl:text>
<xsl:value-of select="$theString"/>
<xsl:text> has no dates</xsl:text></xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:if test="not(matches($theAuthor, '\[?[\p{L} \-]+,'))">
<xsl:if test="not($textLang eq 'hu')">
<xsl:message>ERROR: <xsl:value-of select="$textLang"/> text <xsl:value-of select="$textId"/> <xsl:value-of select="$theAuthor"/>
<xsl:text> has no comma </xsl:text></xsl:message>
</xsl:if></xsl:if>
<xsl:if test="not(matches($theDates, '(1[789]\d\d)|\?\s*\-\s*(1[89]\d\d)|\?'))">
<xsl:message>ERROR: <xsl:value-of select="$textId"/> <xsl:value-of select="$theString"/>
<xsl:text> implausible author dates (</xsl:text><xsl:value-of select="$theDates"/>)! </xsl:message>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<!-- deal with sourceDesc : note that bibl/@type is now handled by schema -->
<xsl:template match="sourceDesc">
<xsl:copy>
<xsl:apply-templates select="bibl"/>
</xsl:copy>
</xsl:template>
<xsl:template match="respStmt[not(resp)]">
<xsl:message>ERROR : <xsl:value-of select="$textId"/> respStmt missing resp : de-tagged</xsl:message>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="bibl//editor">
<xsl:message>ERROR: <xsl:value-of select="$textId"/> Editor tag not allowed: converting to respStmt</xsl:message>
<respStmt xmlns="http://www.tei-c.org/ns/1.0">
<resp>editor</resp>
<name>
<xsl:apply-templates/>
</name>
</respStmt>
</xsl:template>
<xsl:template match="div//bibl">
<xsl:message>WARNING: <xsl:value-of select="$textId"/> Misplaced bibl changed to label</xsl:message>
<label xmlns="http://www.tei-c.org/ns/1.0">
<xsl:apply-templates/>
</label>
</xsl:template>
<!-- deal with publicationStmt
<publicationStmt>
<publisher ref="https://distant-reading.net">COST Action
"Distant Reading for European Literary History" (CA16204)</publisher>
<distributor
ref="https://zenodo.org/communities/eltec/">Zenodo.org</distributor>
<date when="{listERN/date[1]}" />
<availability>
<licence target="https://creativecommons.org/licenses/by/4.0/" />
</availability>
<ref type="doi" target="https://doi.org/10.5281/zenodo.{listERN/@zid}">
ELTeC</ref>
<ref type="doi" target="https://doi.org/10.5281/zenodo.{listERN/ern[@xml:id=$lang]/@cZid}">ELTeC-$lang</ref>
<ref type="doi" target="https://doi.org/10.5281/zenodo.{listERN/ern[@xml:id=$lang]/@rZid}">
ELTeC-$lang release listERN/ern[@xml:id=$lang]/@n}
</ref>
</publicationStmt>-->
<xsl:template match="publicationStmt">
<xsl:variable name="zPrefix" select="document($ERNfile)//e:listERN/@zPrefix"/>
<xsl:variable name="zLink" select="concat($zPrefix, document($ERNfile)//e:listERN/@zId )"/>
<xsl:variable name="zRelease" select="document($ERNfile)//e:listERN/@n"/>
<xsl:variable name="cZidLink" select="concat($zPrefix, document($ERNfile)//e:listERN/e:ern[@xml:id = $textLang]/@cZid)"/>
<xsl:variable name="rZidLink" select="concat($zPrefix, document($ERNfile)//e:listERN/e:ern[@xml:id = $textLang]/@rZid)"/>
<xsl:variable name="release" select="document($ERNfile)//e:listERN/e:ern[@xml:id = $textLang]/@n"/>
<xsl:variable name="repoName">
<xsl:choose>
<xsl:when test="$textLang eq 'de'">deu</xsl:when>
<xsl:when test="$textLang eq 'en'">eng</xsl:when>
<xsl:when test="$textLang eq 'fr'">fra</xsl:when>
<xsl:when test="$textLang eq 'hu'">hun</xsl:when>
<xsl:when test="$textLang eq 'no'">nor</xsl:when>
<xsl:when test="$textLang eq 'pt'">por</xsl:when>
<xsl:when test="$textLang eq 'ro'">rom</xsl:when>
<xsl:when test="$textLang eq 'sl'">slv</xsl:when>
<xsl:when test="$textLang eq 'sp'">spa</xsl:when>
<xsl:when test="$textLang eq 'sr'">srp</xsl:when>
<xsl:when test="$textLang eq 'sw'">swe</xsl:when>
<xsl:otherwise>$textLang</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<publicationStmt xmlns="http://www.tei-c.org/ns/1.0">
<xsl:text>
</xsl:text><publisher ref="https://distant-reading.net">COST Action "Distant Reading for European Literary History" (CA16204)</publisher>
<xsl:text>
</xsl:text><distributor ref="https://zenodo.org/communities/eltec/">Zenodo.org</distributor>
<date when="{$today}"/>
<xsl:text>
</xsl:text><availability>
<licence target="https://creativecommons.org/licenses/by/4.0/"/>
</availability>
<xsl:text>
</xsl:text><ref type="doi" target="https://doi.org/10.5281/zenodo.3462435">ELTeC</ref><xsl:text>
</xsl:text>
<ref type="doi" target="{$zLink}">
<xsl:value-of select="concat('ELTeC release ', $zRelease)"/>
</ref><xsl:text>
</xsl:text>
<ref type="doi" target="{$cZidLink}">
<xsl:value-of select="concat('ELTeC-', $repoName)"/>
</ref><xsl:text>
</xsl:text>
<ref type="doi" target="{$rZidLink}">
<xsl:value-of select="concat('ELTeC-', $repoName, ' release ', $release)"/>
</ref><xsl:text>
</xsl:text>
<xsl:if test="p">
<xsl:comment>
<xsl:value-of select="p"/>
</xsl:comment>
</xsl:if>
</publicationStmt>
</xsl:template>
<!-- deal with canonicity -->
<xsl:template match="*:canonicity">
<reprintCount xmlns="http://distantreading.net/eltec/ns">
<xsl:attribute name="key">
<xsl:choose>
<xsl:when test="@key = 'medium'">unspecified</xsl:when>
<xsl:when test="@key = 'unmarked'">unspecified</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@key"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</reprintCount>
</xsl:template>
<xsl:template match="revisionDesc">
<xsl:copy>
<xsl:text>
</xsl:text>
<change xmlns="http://www.tei-c.org/ns/1.0" when="{$today}">Converted by checkUp script for new release</change>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="name">
<xsl:choose>
<xsl:when test="parent::change">
<xsl:value-of select="."/>
</xsl:when>
<xsl:when test="parent::respStmt">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:message> WARNING: <xsl:value-of select="$textId"/> Unexpected name tag found: suppressed </xsl:message>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="milestone[not(@unit)]">
<xsl:message>WARNING: <xsl:value-of select="$textId"/> Milestone unit unspecified</xsl:message>
<milestone xmlns="http://www.tei-c.org/ns/1.0" unit="unspecified"/>
</xsl:template>
<!-- look at untyped divs (which are still permitted by schema) -->
<xsl:template match="body//div[not(@type)]">
<xsl:choose>
<xsl:when test="parent::div[@type = 'chapter']">
<xsl:message>ERROR : <xsl:value-of select="$textId"/> div not permitted within chapter: replaced with milestone</xsl:message>
<milestone xmlns="http://www.tei-c.org/ns/1.0" unit="unspecified"/>
<xsl:apply-templates/>
</xsl:when>
<xsl:when test="p and not(child::div)">
<xsl:if test="$verbose">
<xsl:message>WARNING: <xsl:value-of select="$textId"/> untyped div containing p but not div: marking as chapter</xsl:message>
</xsl:if>
<div type="chapter" xmlns="http://www.tei-c.org/ns/1.0">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:when test="div">
<xsl:if test="$verbose">
<xsl:message>WARNING: <xsl:value-of select="$textId"/> untyped div containing div : marking as group</xsl:message>
</xsl:if>
<div type="group" xmlns="http://www.tei-c.org/ns/1.0">
<xsl:apply-templates/>
</div>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- check typed divs -->
<xsl:template match="body//div[@type]">
<xsl:choose>
<xsl:when test="parent::div[@type = 'chapter']">
<xsl:message>ERROR : <xsl:value-of select="$textId"/> div not permitted within chapter: replaced with milestone</xsl:message>
<milestone xmlns="http://www.tei-c.org/ns/1.0" unit="{@type}"/>
<xsl:apply-templates/>
</xsl:when>
<xsl:when test="@type = 'titlepage'">
<xsl:message>WARNING: <xsl:value-of select="$textId"/> title page found in body : shouldn't it be in front or back?</xsl:message>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="front/div[not(@type)]">
<xsl:if test="$verbose">
<xsl:message>WARNING: <xsl:value-of select="$textId"/> Untyped div found in front ... assuming liminal</xsl:message>
</xsl:if>
<div type="liminal" xmlns="http://www.tei-c.org/ns/1.0">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="back/div[not(@type)]">
<xsl:if test="$verbose">
<xsl:message>Warning <xsl:value-of select="$textId"/> Untyped div found in back ... assuming liminal</xsl:message>
</xsl:if>
<div type="liminal" xmlns="http://www.tei-c.org/ns/1.0">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="back/div[@type]">
<xsl:choose>
<xsl:when test="@type = 'liminal' or @type = 'notes'">
<div xmlns="http://www.tei-c.org/ns/1.0" type="{@type}">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:message>
<xsl:text>WARNING: </xsl:text>
<xsl:value-of select="$textId"/>
<xsl:text> unanticipated div/@type (</xsl:text>
<xsl:value-of select="@type"/>
<xsl:text>) in back : changed to liminal</xsl:text>
</xsl:message>
<div type="liminal" xmlns="http://www.tei-c.org/ns/1.0">
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- remove <note> elements inside the body-->
<xsl:template match="body//note">
<xsl:message>ERROR : <xsl:value-of select="$textId"/> note inside body removed</xsl:message>
</xsl:template>
<!-- remove empty front or back and vacuous ref -->
<xsl:template match="front[not(*)]">
<xsl:message>WARNING: <xsl:value-of select="$textId"/> Empty front removed</xsl:message>
</xsl:template>
<xsl:template match="back[not(*)]">
<xsl:message>WARNING: <xsl:value-of select="$textId"/> Empty back removed</xsl:message>
</xsl:template>
<!-- special tweaks for romanian -->
<xsl:template match="div[@type = 'chapter']/div/head">
<p xmlns="http://www.tei-c.org/ns/1.0">
<label>
<xsl:value-of select="."/>
</label>
</p>
</xsl:template>
<!-- kill some strange milestones -->
<xsl:template match="milestone[@unit = 'header']"/>
<xsl:template match="milestone[@unit = 'end']"/>
<xsl:template match="milestone[@unit = 'middle']">
<milestone xmlns="http://www.tei-c.org/ns/1.0" rend="dots" unit="subchapter"/>
</xsl:template>
<xsl:template match="milestone[@unit = 'absent']">
<milestone xmlns="http://www.tei-c.org/ns/1.0" rend="space" unit="subchapter"/>
</xsl:template>
<!-- remove invalidly targetted refs from body-->
<xsl:template match="text//ref[@target[string-length(.) gt 1]]">
<xsl:choose>
<!-- <xsl:when test="parent::head">
<xsl:apply-templates/>
<xsl:message>WARNING: <xsl:value-of select="$textId"/> ref in head removed</xsl:message>
</xsl:when>-->
<xsl:when test="starts-with(@target, 'http')">
<xsl:copy-of select="."/>
</xsl:when>
<!-- <xsl:when test="starts-with(@target, 'gut:')">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:when test="starts-with(@target, 'ia:')">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:when test="starts-with(@target, 'bod:')">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:when test="starts-with(@target, 'textgrid:')">
<xsl:copy-of select="."/>
</xsl:when>
-->
<xsl:when test="starts-with(@target, '#')">
<xsl:variable name="noteId">
<xsl:value-of select="substring-after(@target, '#')"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="//note[@xml:id = $noteId]">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:message>ERROR: <xsl:value-of select="$textId"/> ref to nonexistent note with id <xsl:value-of select="$noteId"/> removed</xsl:message>
</xsl:otherwise>
</xsl:choose>
<!-- <xsl:copy-of select="."/>
--> </xsl:when>
<xsl:otherwise>
<xsl:message>WARNING: <xsl:value-of select="$textId"/> invalid ref targetting <xsl:value-of select="@target"/> removed</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="ref[@target = '#']">
<xsl:message>WARNING: <xsl:value-of select="$textId"/> Suppressed vapid ref</xsl:message>
</xsl:template>
<xsl:template match="measure[@unit = 'pages' and . = '0']">
<xsl:message>WARNING: <xsl:value-of select="$textId"/> Suppressed zero page count</xsl:message>
</xsl:template>
<xsl:template match="bibl[not(matches(., '[\w]+'))]">
<xsl:message>WARNING: <xsl:value-of select="$textId"/> Suppressed vapid bibl</xsl:message>
</xsl:template>
<xsl:function name="e:warning">
<xsl:param name="count" as="xs:integer"/>
<xsl:param name="msg"/>
<xsl:if test="$count > 0">
<xsl:message>
<xsl:text>WARNING : </xsl:text>
<xsl:value-of select="$textId"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$count"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$msg"/>
</xsl:message>
</xsl:if>
</xsl:function>
</xsl:stylesheet>