-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsDecl-to-ODD.xsl
285 lines (278 loc) · 15.1 KB
/
fsDecl-to-ODD.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
<?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" xmlns:sch="http://purl.oclc.org/dsdl/schematron"
xmlns="http://www.tei-c.org/ns/1.0" xpath-default-namespace="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="xs" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="boundary">', '</xsl:variable>
<xsl:template match="/">
<xsl:result-document href="methal_personography.odd">
<TEI xml:lang="en" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<teiHeader>
<fileDesc>
<titleStmt>
<title>Title of the project</title>
<author>Author</author>
</titleStmt>
<publicationStmt>
<publisher></publisher>
<publisher></publisher>
<availability status="free">
<licence target="http://creativecommons.org/licenses/by-nc/4.0/"
>Creative Commons BY-NC</licence>
</availability>
</publicationStmt>
<notesStmt>
<note type="ns">www.url.com</note>
</notesStmt>
<sourceDesc>
<p>Written from scratch.</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<head>TEI for X</head>
<schemaSpec ident="fs-customization">
<moduleRef n="01" key="tei"/>
<moduleRef n="02" key="header"/>
<moduleRef n="03" key="core"/>
<moduleRef n="04" key="textstructure"/>
<moduleRef n="17" key="analysis"/>
<moduleRef n="10" key="msdescription"/>
<moduleRef n="11" key="transcr"/>
<moduleRef n="13" key="namesdates"/>
<moduleRef n="16" key="linking"/>
<moduleRef n="18" key="iso-fs"/>
<moduleRef n="21" key="certainty"/>
<moduleRef n="22" key="tagdocs"/>
<elementSpec ident="fs" module="iso-fs" mode="change">
<constraintSpec scheme="schematron" ident="fs_constraints">
<desc>Schematron constraints created from processing the Feature
System declaration</desc>
<constraint>
<xsl:apply-templates select="//fsDecl"/>
</constraint>
</constraintSpec>
</elementSpec>
<elementSpec ident="f" module="iso-fs" mode="change">
<constraintSpec scheme="schematron" ident="f_constraints">
<desc>Schematron constraints created from processing the Feature
System declaration</desc>
<constraint>
<xsl:apply-templates select="//fDecl"/>
</constraint>
</constraintSpec>
</elementSpec>
</schemaSpec>
</body>
</text>
</TEI>
</xsl:result-document>
</xsl:template>
<xsl:template match="fsDecl">
<xsl:variable name="names-obl">
<xsl:value-of select="string-join(fDecl[@optional eq 'false']/@name, ', ')"/>
</xsl:variable>
<xsl:variable name="f-values-obl">
<xsl:value-of select="replace($names-obl, ', ', $boundary)"/>
</xsl:variable>
<xsl:variable name="names-op">
<xsl:value-of
select="string-join(fDecl[@optional eq 'true' or not(@optional)]/@name, ', ')"/>
</xsl:variable>
<xsl:variable name="f-values-op">
<xsl:value-of select="replace($names-op, ', ', $boundary)"/>
</xsl:variable>
<xsl:variable name="context"
select="'tei:text/descendant::tei:fs[@type eq ' || $apos || current()/@type || $apos || ']'"/>
<xsl:if test="fsConstraints">
<xsl:for-each select="fsConstraints/cond">
<xsl:variable name="condition" select="fs[following-sibling::then]/f"/>
<xsl:variable name="then" select="fs[preceding-sibling::then]/f"/>
<sch:rule>
<xsl:choose>
<xsl:when test="$condition[not(child::*)]">
<xsl:attribute name="context"
select="$context || '[tei:f[@name eq ' || $apos || $condition/@name || $apos || ']]'"
/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="context" select="
$context || '[tei:f[@name eq ' || $apos || $condition/@name || $apos ||
'][tei:' || $condition/*/name() || '[@' || $condition/*/name(@*) || ' eq ' || $apos || $condition/*/@* || $apos || ']]]'"
/>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="$then">
<xsl:variable name="test"
select="'tei:f[@name eq ' || $apos || current()/@name || $apos || ']'"/>
<sch:assert>
<xsl:attribute name="test" select="$test"/>Missing <xsl:value-of
select="$test"/>
</sch:assert>
<xsl:if test="current()/vAlt">
<xsl:variable name="controlled_values" select="
for $x in vAlt/symbol/@value
return
$apos || $x || $apos"/>
<sch:assert>
<xsl:attribute name="test"
select="$test || '/tei:symbol/@value = (' || string-join($controlled_values, ','), ')'"
/>Possible values of <xsl:value-of select="$test"/> are
<xsl:value-of select="$controlled_values"/>
</sch:assert>
</xsl:if>
</xsl:for-each>
</sch:rule>
</xsl:for-each>
</xsl:if>
<sch:rule>
<xsl:attribute name="context" select="$context"/>
<xsl:if test="fDecl/@optional = 'false'">
<xsl:for-each select="$names-obl">
<sch:assert>
<xsl:attribute name="test"
select="'tei:f/@name = ' || $apos || current() || $apos"/> The feature
<xsl:value-of select="current()"/> is mandatory </sch:assert>
</xsl:for-each>
</xsl:if>
<xsl:if
test="fDecl[(@optional = 'true') or not(@optional)] and not(fDecl/@optional = 'false')">
<sch:report>
<xsl:attribute name="test">
<xsl:value-of
select="concat('tei:f[not(@name = (', $apos, $f-values-op, $apos, '))]')"
/>
</xsl:attribute> Possible features: <xsl:value-of
select="concat($apos, $names-op, $apos)"/>
</sch:report>
</xsl:if>
<xsl:if
test="fDecl[(@optional = 'true') or not(@optional)] and fDecl/@optional = 'false'">
<sch:assert>
<xsl:variable name="count-ob" select="count(fDecl[@optional = 'false'])"/>
<xsl:attribute name="test">
<xsl:value-of
select="concat('if (count(tei:f) gt ' || $count-ob || ') then tei:f[@name = (', $apos, $f-values-op, $apos, ')] else true()')"
/>
</xsl:attribute> Possible features: <xsl:value-of
select="concat($apos, $names-op, $apos)"/>
</sch:assert>
</xsl:if>
</sch:rule>
</xsl:template>
<xsl:template match="fDecl">
<sch:rule>
<xsl:attribute name="context">
<xsl:value-of
select="concat('tei:text/descendant::tei:f[@name eq ', $apos, current()/@name, $apos, ']', '[parent::tei:fs[@type eq ', $apos, current()/parent::fsDecl/@type, $apos, ']]')"
/>
</xsl:attribute>
<xsl:if test="not(vDefault) and (vRange/binary or vRange/string)">
<sch:assert>
<xsl:attribute name="test"><xsl:value-of select="'tei:' || vRange/*/name()"
/></xsl:attribute> Element <xsl:value-of select="vRange/*/name()"/> is
mandatory </sch:assert>
</xsl:if>
<xsl:if test="vDefault and (vRange/binary or vRange/string)">
<sch:assert>
<xsl:attribute name="test"><xsl:value-of
select="'tei:default or tei:' || vRange/*/name()"/></xsl:attribute>
Element <xsl:value-of select="vRange/*/name()"/> or element default is mandatory
</sch:assert>
</xsl:if>
<xsl:if test="vRange/vNot">
<sch:assert>
<xsl:attribute name="test">tei:string/text()</xsl:attribute>
<xsl:text>This cannot be an empty element</xsl:text>
</sch:assert>
</xsl:if>
<xsl:if test="vRange/vAlt/count(distinct-values(*/name())) = 1">
<xsl:choose>
<xsl:when test="vRange/vAlt/binary">
<sch:assert>
<xsl:attribute name="test">tei:binary</xsl:attribute>
<xsl:text>Mandatory binary feature</xsl:text>
</sch:assert>
</xsl:when>
<xsl:otherwise>
<sch:report>
<xsl:attribute name="test">
<xsl:variable name="symbols">
<xsl:value-of
select="replace(string-join(./vRange/vAlt/symbol/@value, ','), ',', $boundary)"
/>
</xsl:variable>
<xsl:value-of
select="concat('tei:symbol[not(@value = (', $apos, $symbols, $apos, '))]')"
/>
</xsl:attribute> Incorrect value of @value. Possible values are:
<xsl:value-of
select="concat($apos, string-join(./vRange/vAlt/symbol/@value, ', '), $apos)"
/>
</sch:report>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="vRange/vAlt/count(distinct-values(*/name())) = 2">
<xsl:variable name="elements" select="vRange/vAlt/distinct-values(*/name())"/>
<sch:assert>
<xsl:attribute name="test">
<xsl:value-of select="'tei:' || string-join($elements, ' or tei:')"/>
</xsl:attribute> This feature must have one of the following elements:
<xsl:value-of select="string-join($elements, ', ')"/>
</sch:assert>
<xsl:if test="vRange/vAlt/symbol">
<sch:report>
<xsl:variable name="symbols">
<xsl:value-of
select="replace(string-join(./vRange/vAlt/symbol/@value, ','), ',', $boundary)"
/></xsl:variable>
<xsl:attribute name="test">
<xsl:value-of
select="concat('tei:symbol[not(@value = (', $apos, $symbols, $apos, '))]')"
/>
</xsl:attribute> Incorrect value of symbol. Possible values are:
<xsl:value-of
select="concat($apos, string-join(./vRange/vAlt/symbol/@value, ', '), $apos)"
/></sch:report>
</xsl:if>
</xsl:if>
<xsl:if test="vRange/vColl/symbol">
<xsl:variable name="symbolValues"
select="string-join(vRange/vColl/symbol/@value, $boundary)"/>
<sch:report>
<xsl:attribute name="test"><xsl:value-of
select="'if (tei:symbol) then tei:symbol[not(@value = (' || $apos || $symbolValues || $apos || '))] else false()'"
/></xsl:attribute> Possible values of symbol/@value are: <xsl:value-of
select="$apos || $symbolValues || $apos"/>
</sch:report>
<sch:report>
<xsl:attribute name="test"><xsl:value-of
select="'if (tei:vColl/tei:symbol) then tei:vColl/tei:symbol[not(@value = (' || $apos || $symbolValues || $apos || '))] else false()'"
/></xsl:attribute> Possible values of symbol/@value are: <xsl:value-of
select="$apos || $symbolValues || $apos"/>
</sch:report>
</xsl:if>
<xsl:if test="vRange/vColl/fs">
<xsl:variable name="fsNames" select="string-join(vRange/vColl/fs/@type, $boundary)"/>
<sch:report>
<xsl:attribute name="test"><xsl:value-of
select="'if (tei:vColl/tei:fs) then tei:vColl/tei:fs[not(@type = (' || $apos || $fsNames || $apos || '))] else false()'"
/></xsl:attribute> Possible values of fs/@type are: <xsl:value-of
select="$apos || $fsNames || $apos"/>
</sch:report>
</xsl:if>
<xsl:if test="vRange/fs">
<sch:report>
<xsl:attribute name="test"><xsl:value-of
select="'tei:fs[not(@type = (' || $apos || vRange/fs/@type || $apos || '))]'"
/></xsl:attribute> Mandatory fs of @type <xsl:value-of
select="vRange/fs/@type"/>
</sch:report>
</xsl:if>
</sch:rule>
</xsl:template>
</xsl:stylesheet>