forked from TEIC/Stylesheets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassatts.xsl
387 lines (376 loc) · 15.9 KB
/
classatts.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
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sch="http://purl.oclc.org/dsdl/schematron"
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
xmlns:rng="http://relaxng.org/ns/structure/1.0"
xpath-default-namespace="http://www.tei-c.org/ns/1.0" xmlns="http://www.tei-c.org/ns/1.0"
xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:teix="http://www.tei-c.org/ns/Examples"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" exclude-result-prefixes="#all">
<doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
<desc>
<p> TEI stylesheet for processing overriding of class attributes in ODD</p>
<p>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 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. </p>
<p>Author: See AUTHORS</p>
<p>Id: $Id: odd2odd.xsl 10667 2012-07-19 09:04:45Z rahtz $</p>
<p>Copyright: 2013, TEI Consortium</p>
</desc>
</doc>
<xsl:output encoding="utf-8" indent="no"/>
<xsl:param name="verbose"/>
<xsl:param name="stripped">false</xsl:param>
<xsl:variable name="All" select="/"/>
<xsl:key name="ATTCLASSES" match="classSpec[@type = 'atts']" use="@ident"/>
<doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
<desc>Elements which have an attribute child with a mode attribute. Process their attList and
class list separately, to identify attributes overriding those inherited from a class.</desc>
</doc>
<xsl:template match="elementSpec" mode="classatts">
<xsl:variable name="E" select="."/>
<xsl:copy>
<xsl:apply-templates select="@*[not(name() = 'mode')]" mode="classatts"/>
<xsl:apply-templates select="
*[not(self::classes or
self::attList)]"
mode="classatts"/>
<xsl:variable name="results">
<xsl:sequence select="tei:attclasses(.)"/>
</xsl:variable>
<classes>
<xsl:copy-of select="$results//memberOf"/>
</classes>
<attList>
<xsl:copy-of select="$results//attRef"/>
<xsl:copy-of select="$results//attDef"/>
<xsl:for-each select="$E/attList/*">
<xsl:call-template name="process-attList-children">
<xsl:with-param name="results" tunnel="yes" select="$results"/>
</xsl:call-template>
</xsl:for-each>
</attList>
</xsl:copy>
</xsl:template>
<doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
<desc>Explicitly process (nested) attList within elementSpec/attList.</desc>
</doc>
<xsl:template match="attList" mode="classatts">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each select="*">
<xsl:call-template name="process-attList-children"/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
<desc>Helper template for the "elementSpec" template. The code has been moved here to make
it accesible for the "attList" template.</desc>
</doc>
<xsl:template name="process-attList-children" as="node()*">
<xsl:param name="results" tunnel="yes" as="node()*"/>
<xsl:choose>
<xsl:when
test="
@mode = 'replace' and
not($results/encounter[@ident = current()/@ident])">
<xsl:apply-templates select="." mode="classatts"/>
</xsl:when>
<xsl:when test="@mode and not(@mode = 'add')"/>
<xsl:otherwise>
<xsl:apply-templates select="." mode="classatts"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
<desc>Walk over each class membership; visit that class; see if it has attributes; check each of
these against an override in original element. If so, merge the two together and make a local
copy. If a class has triggered this behaviour, return pointers to untouched class attributes,
and a set of attDefs. Otherwise, return a memberOf. A note is made of any class attribute
(encounter element), so that we can distinguish overridding attributes as to whether or not
they are from a class.</desc>
</doc>
<xsl:function name="tei:attclasses" as="node()+">
<xsl:param name="here" as="element()"/>
<!--
On entry, we are sitting on an <elementSpec>
and seeing if we have overrides on class attributes.
-->
<xsl:variable name="E" select="$here"/>
<null/>
<xsl:if test="$autoGlobal = 'true'">
<attRef rend="none" class="att.global"/>
</xsl:if>
<xsl:choose>
<xsl:when test="not($E//attDef)">
<xsl:for-each select="$here/classes/memberOf">
<memberOf>
<xsl:copy-of select="@*"/>
</memberOf>
<xsl:if test="key('ATTCLASSES', @key) and not($parameterize = 'true')">
<attRef rend="none" class="{@key}"/>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$here/classes/memberOf">
<xsl:choose>
<xsl:when test="not(key('ATTCLASSES', @key))">
<memberOf>
<xsl:copy-of select="@*"/>
</memberOf>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="overrides">
<xsl:call-template name="classAttributes">
<xsl:with-param name="E" select="$E"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="not($overrides/override)">
<memberOf>
<xsl:copy-of select="@*"/>
</memberOf>
<xsl:if test="not($parameterize = 'true')">
<attRef rend="none" class="{@key}"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$overrides/encounter"/>
<xsl:copy-of select="$overrides/attRef"/>
<xsl:copy-of select="$overrides/attDef"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:template name="classAttributes">
<xsl:param name="E" as="element()">
<x/>
</xsl:param>
<xsl:variable name="k" select="current()/@key"/>
<xsl:for-each select="key('ATTCLASSES', $k)">
<xsl:for-each select=".//attDef">
<encounter ident="{@ident}"/>
<xsl:variable name="A" select="."/>
<xsl:choose>
<xsl:when test="$E//attDef[@ident = current()/@ident]">
<override/>
<xsl:for-each select="$E//attDef[@ident = current()/@ident]">
<xsl:choose>
<xsl:when test="@mode = 'delete'"/>
<xsl:when test="not(@mode) or @mode = 'replace'">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="mergeClassAttribute">
<xsl:with-param name="Old" select="$A"/>
<xsl:with-param name="New" select="."/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<attRef class="{ancestor::classSpec/@ident}" name="{@ident}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="classes/memberOf">
<xsl:call-template name="classAttributes">
<xsl:with-param name="E" select="$E"/>
</xsl:call-template>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
<desc>Go over each component of an original attribute, and a change spec, and get the best
combination of old and new.</desc>
</doc>
<xsl:template name="mergeClassAttribute">
<xsl:param name="New"/>
<xsl:param name="Old"/>
<attDef corresp="#{$Old/ancestor::classSpec/@ident}">
<xsl:attribute name="ident" select="$Old/@ident"/>
<xsl:attribute name="usage">
<xsl:choose>
<xsl:when test="$New/@usage">
<xsl:value-of select="$New/@usage"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$Old/@usage"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="$New/altIdent">
<xsl:apply-templates mode="classatts" select="$New/altIdent"/>
</xsl:if>
<!-- equiv, gloss, desc trio -->
<xsl:choose>
<xsl:when test="$New/equiv">
<xsl:apply-templates mode="classatts" select="$New/equiv"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="classatts" select="$Old/equiv"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$New/gloss">
<xsl:apply-templates mode="classatts" select="$New/gloss"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="classatts" select="$Old/gloss"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$New/desc">
<xsl:apply-templates mode="classatts" select="$New/desc"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="classatts" select="$Old/desc"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$New/constraintSpec">
<xsl:apply-templates mode="classatts" select="$New/constraintSpec"/>
</xsl:when>
<xsl:when test="$Old/constraintSpec">
<xsl:copy-of select="$Old/constraintSpec"/>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$New/datatype">
<xsl:apply-templates mode="classatts" select="$New/datatype"/>
</xsl:when>
<xsl:when test="$Old/datatype">
<xsl:copy-of select="$Old/datatype"/>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$New/defaultVal">
<xsl:apply-templates mode="classatts" select="$New/defaultVal"/>
</xsl:when>
<xsl:when test="$Old/defaultVal">
<xsl:copy-of select="$Old/defaultVal"/>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$New/valDesc">
<xsl:apply-templates mode="classatts" select="$New/valDesc"/>
</xsl:when>
<xsl:when test="$Old/valDesc">
<xsl:copy-of select="$Old/valDesc"/>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$New/valList[@mode = 'delete']"/>
<xsl:when test="$New/valList[@mode = 'add' or @mode = 'replace']">
<xsl:for-each select="$New/valList[1]">
<xsl:copy>
<xsl:copy-of select="@type"/>
<xsl:copy-of select="@repeatable"/>
<xsl:copy-of select="*"/>
</xsl:copy>
</xsl:for-each>
</xsl:when>
<xsl:when
test="
$New/valList[@mode = 'change'] and
not($Old/valList)">
<xsl:for-each select="$New/valList[1]">
<xsl:copy>
<xsl:copy-of select="@type"/>
<xsl:copy-of select="@repeatable"/>
<xsl:copy-of select="*"/>
</xsl:copy>
</xsl:for-each>
</xsl:when>
<xsl:when test="$New/valList[@mode = 'change']">
<xsl:for-each select="$New/valList[1]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each select="$Old/valList/valItem">
<xsl:variable name="thisme" select="@ident"/>
<xsl:if
test="not($New/valList[1]/valItem[@ident = $thisme and (@mode = 'delete' or @mode = 'replace')])">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each select="$New/valList[1]/valItem[@ident = $thisme]">
<xsl:choose>
<xsl:when test="equiv">
<xsl:apply-templates mode="classatts" select="equiv"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$Old/valList/valItem[@ident = $thisme]">
<xsl:apply-templates mode="classatts" select="equiv"/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="gloss">
<xsl:apply-templates mode="classatts" select="gloss"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$Old/valList/valItem[@ident = $thisme]">
<xsl:apply-templates mode="classatts" select="gloss"/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="desc">
<xsl:apply-templates mode="classatts" select="desc"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$Old/valList/valItem[@ident = $thisme]">
<xsl:apply-templates mode="classatts" select="desc"/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:if>
</xsl:for-each>
<xsl:apply-templates mode="classatts" select="valItem[@mode = 'add']"/>
<xsl:apply-templates mode="classatts" select="valItem[@mode = 'replace']"/>
</xsl:copy>
</xsl:for-each>
</xsl:when>
<xsl:when test="$Old/valList">
<xsl:copy-of select="$Old/valList"/>
</xsl:when>
</xsl:choose>
<xsl:if test="$New/exemplum">
<xsl:apply-templates mode="classatts" select="$New/exemplum"/>
</xsl:if>
<xsl:if test="$New/remarks">
<xsl:apply-templates mode="classatts" select="$New/remarks"/>
</xsl:if>
</attDef>
</xsl:template>
<xsl:template match="*" mode="classatts">
<xsl:copy>
<xsl:apply-templates select="* | @* | comment() | processing-instruction() | text()"
mode="classatts"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | text() | comment() | processing-instruction()" mode="classatts">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>