This repository has been archived by the owner on Aug 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
oddbyexampleORIGINAL.xsl
782 lines (735 loc) · 30.9 KB
/
oddbyexampleORIGINAL.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
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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright TEI Consortium.
Dual-licensed under CC-by and BSD2 licences
See the file COPYING.txt for details
$Date$
$Id$
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:n="www.example.com"
xmlns:rng="http://relaxng.org/ns/structure/1.0" xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns="http://www.tei-c.org/ns/1.0" exclude-result-prefixes="rng tei n"
xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="2.0">
<!--
This software is dual-licensed:
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
Unported License http://creativecommons.org/licenses/by-sa/3.0/
2. http://www.opensource.org/licenses/BSD-2-Clause
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
This software is provided by the copyright holders and contributors
"as is" and any express or implied warranties, including, but not
limited to, the implied warranties of merchantability and fitness for
a particular purpose are disclaimed. In no event shall the copyright
holder or contributors be liable for any direct, indirect, incidental,
special, exemplary, or consequential damages (including, but not
limited to, procurement of substitute goods or services; loss of use,
data, or profits; or business interruption) however caused and on any
theory of liability, whether in contract, strict liability, or tort
(including negligence or otherwise) arising in any way out of the use
of this software, even if advised of the possibility of such damage.
$Id$
2008, TEI Consortium
-->
<!-- typical usage:
saxon -it:main -o:myodd /usr/share/xml/tei/stylesheet/tools/oddbyexample.xsl corpus=`pwd`/
-->
<!--
Read a corpus of TEI P5 documents and construct
an ODD customization file which expresses the subset
of the TEI you need to validate that corpus
-->
<!-- How does this work?
1) start a variable and copy in all of the TEI
2) read the corpus and get a list of all the elements and their
attributes that it uses, put that in the same variable
3) process the variable and read the TEI section. if an element or
attribute is not present in the corpus section, put out a delete
customization;
if the attributes of an attribute class are never used
that class may be deleted only if it doesn't claim membership in any other class
or, if it does, none of the attributes from that other class is used too
4) for every attribute which is of type "enumerated", construct a
valList
-->
<xsl:output indent="yes"/>
<!-- name of odd -->
<xsl:param name="schema">oddbyexample</xsl:param>
<!-- whether to do all the global attributes -->
<xsl:param name="keepGlobals">false</xsl:param>
<!-- the document corpus -->
<xsl:param name="corpus">./</xsl:param>
<!-- files starting with what prefix? -->
<xsl:param name="prefix"/>
<!-- the source of the TEI (just needs *Spec)-->
<xsl:param name="defaultSource">http://www.tei-c.org/Vault/P5/current/xml/tei/odd/p5subset.xml</xsl:param>
<!-- should we make valList for @rend and @rendition -->
<xsl:param name="enumerateRend">false</xsl:param>
<!-- should we make valList for @type -->
<xsl:param name="enumerateType">false</xsl:param>
<!-- should we deal with non-TEI namespaces -->
<xsl:param name="processNonTEI">false</xsl:param>
<!-- which attributes should be make valLists for, regardless -->
<xsl:param name="attributeList"/>
<!-- do you want moduleRef generated with @include or @except? -->
<xsl:param name="method">include</xsl:param>
<!-- turn on debug messages -->
<xsl:param name="debug">false</xsl:param>
<!-- turn on messages -->
<xsl:param name="verbose">false</xsl:param>
<!-- which files to look at? provide suffix -->
<xsl:param name="suffix">xml</xsl:param>
<!-- provide specific list of files -->
<xsl:param name="corpusList"/>
<!-- should P4 files be considered? -->
<xsl:param name="processP4">false</xsl:param>
<!-- should P5 files be considered? -->
<xsl:param name="processP5">true</xsl:param>
<xsl:key name="Atts" match="@*" use="local-name(parent::*)"/>
<xsl:key name="attVals" match="@*" use="concat(local-name(parent::*),local-name())"/>
<xsl:key name="ELEMENTS" use="1" match="elementSpec"/>
<xsl:key name="CLASSES" use="1" match="classSpec[@type='atts']"/>
<xsl:key name="IDENTS" use="@ident" match="*[@ident]"/>
<xsl:key name="MEMBERS" use="@key" match="elementSpec/classes/memberOf"/>
<xsl:key name="CLASSMEMBERS" use="@key" match="classSpec/classes/memberOf"/>
<xsl:key name="Used" use="@ident" match="docs/elementSpec"/>
<xsl:key name="UsedAtt" use="concat(../@ident,@ident)" match="docs/elementSpec/attDef"/>
<xsl:key name="All" match="*" use="1"/>
<xsl:key name="AllTEI" match="tei:*" use="1"/>
<xsl:key name="E" match="*" use="local-name()"/>
<xsl:key name="EbyM" match="elementSpec" use="@module"/>
<xsl:key name="deletedE" match="elementSpec[@mode='delete']" use="@ident"/>
<xsl:key name="changedE" match="elementSpec[@mode='change']" use="@ident"/>
<xsl:key name="changedE" match="elementSpec[@mode='replace']" use="@ident"/>
<xsl:template name="main">
<xsl:variable name="pathlist">
<xsl:choose>
<xsl:when test="$corpusList=''">
<xsl:value-of
select="concat($corpus,'?select=',$prefix, '*.',$suffix,';recurse=yes;on-error=warning')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$corpusList"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$debug='true'">
<xsl:message>Process <xsl:value-of select="$pathlist"/></xsl:message>
</xsl:if>
<xsl:variable name="docs" select="collection($pathlist)"/>
<xsl:variable name="all">
<n:ROOT>
<xsl:if test="$processP4='true'">
<xsl:for-each select="$docs/TEI.2">
<xsl:if test="$verbose='true'">
<xsl:message>processing <xsl:value-of select="base-uri(.)"/>
</xsl:message>
</xsl:if>
<TEI.2 xn="{base-uri(.)}">
<xsl:apply-templates select="*|@*" mode="copy"/>
</TEI.2>
</xsl:for-each>
</xsl:if>
<xsl:if test="$processP5='true'">
<xsl:for-each select="$docs/tei:*">
<xsl:if test="$verbose='true'">
<xsl:message>processing <xsl:value-of select="base-uri(.)"/>
</xsl:message>
</xsl:if>
<tei:TEI xn="{base-uri(.)}">
<xsl:apply-templates select="*|@*" mode="copy"/>
</tei:TEI>
</xsl:for-each>
<xsl:for-each select="$docs/tei:teiCorpus">
<xsl:if test="$verbose='true'">
<xsl:message>processing <xsl:value-of select="base-uri(.)"/>
</xsl:message>
</xsl:if>
<tei:teiCorpus xn="{base-uri(.)}">
<xsl:copy-of select="@*|*"/>
</tei:teiCorpus>
</xsl:for-each>
</xsl:if>
</n:ROOT>
</xsl:variable>
<xsl:variable name="stage3">
<xsl:for-each select="$all/*">
<xsl:call-template name="processAll"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="stage4">
<xsl:apply-templates select="$stage3" mode="stage3"/>
</xsl:variable>
<xsl:apply-templates select="$stage4" mode="stage4"/>
<!-- debug
<xsl:result-document href="/tmp/stage3.xml">
<xsl:copy-of select="$stage3"/>
</xsl:result-document>
<xsl:result-document href="/tmp/stage4.xml">
<xsl:copy-of select="$stage4"/>
</xsl:result-document>
-->
</xsl:template>
<xsl:template match="text()" mode="copy"/>
<xsl:template match="@*" mode="copy">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="*" mode="copy">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()" mode="copy"/>
</xsl:copy>
</xsl:template>
<xsl:template name="processAll">
<xsl:variable name="count">
<xsl:value-of select="count(/n:ROOT/*)"/>
</xsl:variable>
<!-- assemble together all the TEI elements and attributes,
followed by all the
elements and attributes used in the corpus -->
<xsl:variable name="stage1">
<stage1>
<tei>
<xsl:for-each select="document($defaultSource)">
<xsl:for-each select="key('CLASSES',1)">
<classSpec>
<xsl:copy-of select="@ident"/>
<xsl:copy-of select="@module"/>
<xsl:copy-of select="classes/memberOf"/>
<xsl:for-each select=".//attDef">
<attDef>
<xsl:copy-of select="@ident"/>
<xsl:call-template name="checktype"/>
</attDef>
</xsl:for-each>
<xsl:call-template name="classatts"/>
<xsl:for-each select="classes/memberOf">
<classmember ident="{@key}"/>
</xsl:for-each>
<xsl:call-template name="classmembers"/>
</classSpec>
</xsl:for-each>
<xsl:for-each select="key('ELEMENTS',1)">
<elementSpec>
<xsl:copy-of select="@ident"/>
<xsl:copy-of select="@module"/>
<xsl:for-each select=".//tei:attDef">
<attDef>
<xsl:copy-of select="@ident"/>
<xsl:call-template name="checktype"/>
</attDef>
</xsl:for-each>
<xsl:call-template name="classatts"/>
</elementSpec>
</xsl:for-each>
</xsl:for-each>
</tei>
<docs>
<xsl:for-each-group select="key('AllTEI',1)" group-by="local-name()">
<xsl:sort select="current-grouping-key()"/>
<xsl:variable name="ident" select="current-grouping-key()"/>
<elementSpec>
<xsl:attribute name="ident">
<xsl:copy-of select="current-grouping-key()"/>
</xsl:attribute>
<xsl:for-each-group select="key('Atts',$ident)" group-by="local-name()">
<attDef ident="{name()}">
<valList type="closed">
<xsl:for-each-group select="key('attVals',concat($ident,local-name()))"
group-by=".">
<xsl:sort select="."/>
<xsl:for-each select="tokenize(current-grouping-key(),' ')">
<valItem ident="{.}"/>
</xsl:for-each>
</xsl:for-each-group>
</valList>
</attDef>
</xsl:for-each-group>
</elementSpec>
</xsl:for-each-group>
</docs>
</stage1>
</xsl:variable>
<xsl:variable name="stage2">
<stage2>
<!-- for every attribute class, see if its members should be
deleted, by seeing if they are used anywhere-->
<xsl:for-each select="$stage1/stage1/tei/classSpec">
<xsl:variable name="classatts">
<xsl:for-each select="attDef">
<xsl:variable name="this" select="@ident"/>
<xsl:variable name="used">
<xsl:for-each select="../member">
<xsl:if test="key('UsedAtt',concat(@ident,$this))">
<xsl:text>true</xsl:text>
</xsl:if>
<!-- tutaj dodac test, czy nie jest to aby member innej klasy,
bo jesli tak, trzeba sprawdzic czy ktorys z jej atrybutow nie jest used -->
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="$keepGlobals='true' and $this='n'">
<keep/>
</xsl:when>
<xsl:when test="$keepGlobals='true' and $this='rendition'">
<keep/>
</xsl:when>
<xsl:when test="$keepGlobals='true' and $this='xml:id'">
<keep/>
</xsl:when>
<xsl:when test="$keepGlobals='true' and $this='xml:base'">
<keep/>
</xsl:when>
<xsl:when test="$keepGlobals='true' and $this='xml:space'">
<keep/>
</xsl:when>
<xsl:when test="$keepGlobals='true' and $this='xml:lang'">
<keep/>
</xsl:when>
<xsl:when test="$keepGlobals='true' and $this='rend'">
<keep/>
</xsl:when>
<xsl:when test="$used=''">
<attDef ident="{$this}" mode="delete"/>
</xsl:when>
<xsl:otherwise>
<keep/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="$classatts/attDef[@mode='delete'] and not($classatts/keep)">
<classSpec ident="{@ident}" module="{@module}" type="atts" mode="delete">
<xsl:copy-of select="classmember"/>
<attList>
<xsl:copy-of select="$classatts/attDef"/>
</attList>
</classSpec>
</xsl:when>
<xsl:when test="$classatts/attDef[@mode='delete'] and $classatts/keep">
<classSpec ident="{@ident}" module="{@module}" type="atts" mode="change">
<attList>
<xsl:copy-of select="$classatts/attDef"/>
</attList>
</classSpec>
</xsl:when>
<xsl:when test="$classatts/keep">
<classSpec ident="{@ident}" module="{@module}" type="atts" mode="keep"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<!-- for every TEI element, say if it is actually used or is to be deleted -->
<xsl:for-each select="$stage1/stage1/tei/elementSpec">
<xsl:choose>
<xsl:when test="key('Used',@ident)">
<elementSpec ident="{@ident}" module="{@module}" mode="keep">
<xsl:copy-of select="attDef"/>
</elementSpec>
</xsl:when>
<xsl:otherwise>
<elementSpec ident="{@ident}" module="{@module}" mode="delete"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:if test="$processNonTEI='true'">
<xsl:for-each-group select="key('All',1)" group-by="local-name()">
<xsl:sort/>
<xsl:choose>
<xsl:when test="self::n:ROOT"/>
<xsl:when test="namespace-uri()='http://www.tei-c.org/ns/1.0'"/>
<xsl:otherwise>
<!-- build new 'add' elementSpec -->
<elementSpec ident="{current-grouping-key()}" mode="add" ns="{namespace-uri()}">
<xsl:text> </xsl:text>
<xsl:comment>add an <equiv/> to point to an named template
in an XSLT file which will transform this to pure TEI</xsl:comment>
<xsl:text> </xsl:text>
<equiv filter="somefile.xsl" mimeType="text/xsl" name="{current-grouping-key()}"/>
<desc>
<xsl:text> </xsl:text>
<xsl:comment> Describe the <xsl:value-of select="current-grouping-key()"/> element here</xsl:comment>
<xsl:text> </xsl:text>
</desc>
<classes>
<xsl:text> </xsl:text>
<xsl:comment> Add a memberOf key="model.className"' stanza for whatever classes it belongs to here</xsl:comment>
<xsl:text> </xsl:text>
</classes>
<content>
<xsl:text> </xsl:text>
<xsl:comment>Add RNG content model here</xsl:comment>
<xsl:text> </xsl:text>
</content>
<xsl:if test="key('Atts',local-name())">
<attList>
<xsl:comment>Add attDefs:</xsl:comment>
<xsl:text> </xsl:text>
<xsl:for-each-group select="key('Atts',local-name())" group-by="local-name()">
<xsl:sort/>
<attDef ident="{local-name()}" mode="add"/>
</xsl:for-each-group>
</attList>
</xsl:if>
</elementSpec>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:if>
</stage2>
</xsl:variable>
<!-- start writing the final ODD document -->
<TEI xml:lang="en">
<teiHeader>
<fileDesc>
<titleStmt>
<title>ODD by Example customization</title>
</titleStmt>
<editionStmt>
<edition>generated on <date><xsl:value-of
select="format-dateTime(current-dateTime(),'[Y]-[M02]-[D02]T[H02]:[m02]:[s02]Z')"
/></date>
</edition>
</editionStmt>
<publicationStmt>
<p> </p>
</publicationStmt>
<sourceDesc>
<p>generated by oddbyexample.xsl, based on analyzing <xsl:value-of select="$count"/> files from <xsl:value-of select="$corpus"/>
</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<schemaSpec ident="{$schema}">
<xsl:attribute name="start">
<xsl:if test="$stage2/stage2/elementSpec[@mode='keep' and @ident='TEI']">TEI</xsl:if>
<xsl:text> </xsl:text>
<xsl:if test="$stage2/stage2/elementSpec[@mode='keep' and @ident='teiCorpus']"
>teiCorpus</xsl:if>
</xsl:attribute>
<!--
We need to list only modules from which elements or
classes have been used, but we always need tei module
-->
<moduleRef key="tei"/>
<xsl:for-each-group select="$stage2/stage2/*[@mode='keep']" group-by="@module">
<xsl:sort select="current-grouping-key()"/>
<xsl:choose>
<xsl:when test="@module='tei'"/>
<xsl:otherwise>
<moduleRef key="{@module}"/>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="current-group()[self::elementSpec]">
<xsl:variable name="e" select="@ident"/>
<!-- for every attribute, if its a class attribute, see if
its already deleted. if its a local attribute, see if its used. -->
<xsl:variable name="a">
<attList>
<xsl:for-each select="attDef">
<xsl:variable name="class" select="@class"/>
<xsl:variable name="ident" select="@ident"/>
<xsl:variable name="enumerated" select="@enumerated"/>
<xsl:for-each select="$stage1">
<xsl:choose>
<xsl:when
test="not($class='') and
$stage2/stage2/classSpec[@ident=$class]/attList/attDef[@ident=$ident
and @mode='delete']"> </xsl:when>
<xsl:when test="$keepGlobals='true' and $ident='xml:id'"/>
<xsl:when test="$keepGlobals='true' and $ident='xml:base'"/>
<xsl:when test="$keepGlobals='true' and $ident='xml:space'"/>
<xsl:when test="$keepGlobals='true' and $ident='xml:lang'"/>
<xsl:when test="$keepGlobals='true' and $ident='n'"/>
<xsl:when test="$keepGlobals='true' and $ident='rendition'"/>
<xsl:when test="$keepGlobals='true' and $ident='rend'"/>
<xsl:when test="not(key('UsedAtt',concat($e,$ident)))">
<attDef ident="{$ident}" mode="delete"/>
</xsl:when>
<xsl:when test="$enumerated='true'">
<attDef ident="{$ident}" mode="change">
<xsl:apply-templates select="key('UsedAtt',concat($e,$ident))/valList"
/>
</attDef>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</attList>
</xsl:variable>
<xsl:for-each select="$a">
<xsl:if test="attList/attDef">
<elementSpec ident="{$e}" mode="change">
<xsl:copy-of select="attList"/>
</elementSpec>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
<xsl:copy-of
select="$stage2/stage2/elementSpec[@mode='delete' and @module=current-grouping-key()]"/>
<xsl:apply-templates select="$stage2/stage2/classSpec[@module=current-grouping-key()]"
/>
</xsl:for-each-group>
<xsl:for-each select="$stage2/stage2/elementSpec[@mode='add']">
<xsl:text>
</xsl:text>
<xsl:comment>You've added an element '<xsl:value-of select="@ident"/>'
which does not seem to be a proper TEI element. This will make your TEI
documents non-conformant, but if you really want to do this you should
add an elementSpec for it if you want your document to validate. It
would be better to use a separate namespace. </xsl:comment>
<xsl:text>
</xsl:text>
<xsl:copy-of select="."/>
</xsl:for-each>
</schemaSpec>
</body>
</text>
</TEI>
</xsl:template>
<xsl:template name="classmembers">
<xsl:choose>
<xsl:when test="@ident='att.global'">
<xsl:for-each select="key('ELEMENTS',1)">
<xsl:sort select="@ident"/>
<member ident="{@ident}"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="key('MEMBERS',@ident)">
<member ident="{ancestor::elementSpec/@ident}"/>
</xsl:for-each>
<xsl:for-each select="key('CLASSMEMBERS',@ident)/ancestor::classSpec">
<xsl:call-template name="classmembers"/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="classatts">
<xsl:for-each select="classes/memberOf">
<xsl:for-each select="key('IDENTS',@key)">
<xsl:for-each select=".//tei:attDef">
<attDef class="{ancestor::classSpec/@ident}">
<xsl:copy-of select="@ident"/>
<xsl:call-template name="checktype"/>
</attDef>
</xsl:for-each>
<xsl:call-template name="classatts"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template name="checktype">
<xsl:attribute name="enumerated">
<xsl:choose>
<xsl:when test="@ident = ($attributeList)">true</xsl:when>
<xsl:when test="@ident='n'">false</xsl:when>
<xsl:when test="@ident='rend' and $enumerateRend='true'">true</xsl:when>
<xsl:when test="@ident='rendition' and $enumerateRend='true'">true</xsl:when>
<xsl:when test="@ident='type' and $enumerateType='true'">true</xsl:when>
<xsl:when test="valList[@type='closed']">true</xsl:when>
<xsl:when test="datatype/rng:ref[@name='data.enumerated']">true</xsl:when>
<!--
<xsl:when
test="datatype/rng:ref[@name='data.word']">true</xsl:when>
-->
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
<xsl:template match="valList">
<valList mode="add" type="closed">
<xsl:for-each-group select="valItem" group-by="@ident">
<xsl:sort select="@ident"/>
<valItem ident="{current-grouping-key()}"/>
</xsl:for-each-group>
</valList>
</xsl:template>
<xsl:template match="classSpec">
<xsl:choose>
<xsl:when test="@mode='delete'">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="classmember"/>
<xsl:copy-of select="attList"/>
</xsl:copy>
</xsl:when>
<xsl:when test="attList/attDef">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="attList"/>
</xsl:copy>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- odd 2 nuodd -->
<xsl:template match="@*|text()|comment()|processing-instruction()" mode="stage3">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="@*|text()|comment()|processing-instruction()" mode="stage4">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="*" mode="stage3">
<xsl:copy>
<xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="stage3"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*" mode="stage4">
<xsl:copy>
<xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="stage4"/>
</xsl:copy>
</xsl:template>
<!-- ignore elementSpec @mode='delete' -->
<xsl:template match="elementSpec[@mode='delete']" mode="stage3"/>
<xsl:template match="classSpec[@mode='delete']" mode="stage3">
<xsl:copy>
<xsl:copy-of select="@ident"/>
<xsl:copy-of select="@module"/>
<xsl:copy-of select="@type"/>
<xsl:choose>
<xsl:when test="../classSpec[@ident=current()/classmember/@ident]">
<xsl:attribute name="mode">change</xsl:attribute>
<xsl:copy-of select="attList"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="mode">delete</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="moduleRef/@include" mode="stage3"/>
<xsl:template match="moduleRef/@except" mode="stage3"/>
<!-- for any moduleRef, look up all the members of it in P5;
if they are not deleted by this odd, add them to a list to be
included -->
<xsl:template match="moduleRef[@key]" mode="stage3">
<xsl:variable name="orig" select="/"/>
<xsl:variable name="here" select="."/>
<xsl:copy>
<xsl:apply-templates select="@*" mode="stage3"/>
<xsl:variable name="module" select="@key"/>
<xsl:choose>
<xsl:when test="$method='include' and @include">
<xsl:copy-of select="@include"/>
</xsl:when>
<xsl:when test="$method='except' and @except">
<xsl:copy-of select="@except"/>
</xsl:when>
<xsl:when test="$method='include' and @except">
<xsl:variable name="not">
<xsl:for-each select="tokenize($here/@except,' ')">
<not ident="{.}"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="includelist">
<xsl:for-each select="document($defaultSource)">
<xsl:for-each select="key('EbyM',$module)">
<xsl:sort select="@ident"/>
<xsl:variable name="e" select="@ident"/>
<xsl:if test="not($not/not[@ident=$e])">
<xsl:value-of select="$e"/>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:if test="not($includelist='')">
<xsl:attribute name="include" select="normalize-space($includelist)"/>
</xsl:if>
</xsl:when>
<xsl:when test="$method='include'">
<xsl:variable name="includelist">
<xsl:for-each select="document($defaultSource)">
<xsl:for-each select="key('EbyM',$module)">
<xsl:sort select="@ident"/>
<xsl:variable name="e" select="@ident"/>
<xsl:for-each select="$orig">
<xsl:choose>
<xsl:when test="key('deletedE',$e)"/>
<xsl:otherwise>
<xsl:value-of select="$e"/>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:if test="not($includelist='')">
<xsl:attribute name="include" select="normalize-space($includelist)"/>
</xsl:if>
</xsl:when>
<xsl:when test="$method='except' and @include">
<xsl:variable name="yes">
<xsl:for-each select="tokenize($here/@include,' ')">
<yes ident="{.}"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="exceptlist">
<xsl:for-each select="document($defaultSource)">
<xsl:for-each select="key('EbyM',$module)">
<xsl:sort select="@ident"/>
<xsl:variable name="e" select="@ident"/>
<xsl:for-each select="$orig">
<xsl:if test="not($yes/yes[@ident=$e])">
<xsl:value-of select="$e"/>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:if test="not($exceptlist='')">
<xsl:attribute name="except" select="normalize-space($exceptlist)"/>
</xsl:if>
</xsl:when>
<xsl:when test="$method='except'">
<xsl:variable name="exceptlist">
<xsl:for-each select="document($defaultSource)">
<xsl:for-each select="key('EbyM',$module)">
<xsl:sort select="@ident"/>
<xsl:variable name="e" select="@ident"/>
<xsl:for-each select="$orig">
<xsl:if test="key('deletedE',$e)">
<xsl:value-of select="$e"/>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:if test="not($exceptlist='')">
<xsl:attribute name="except" select="normalize-space($exceptlist)"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">Method <xsl:value-of select="$method"/> not
supported</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template mode="stage4" match="specGrp[not(*)]"/>
<xsl:template mode="stage4" match="specGrpRef">
<xsl:choose>
<xsl:when test="starts-with(@target,'#')">
<xsl:for-each select="id(substring(@target,2))">
<xsl:if test="*">
<specGrpRef target="#{@xml:id}"/>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:function name="tei:shallWeKeep"/>
</xsl:stylesheet>