forked from projectmallard/projectmallard.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.xsl
342 lines (317 loc) · 14.3 KB
/
checks.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
<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
<!--
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this program; see the file COPYING.LGPL. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
-->
<!--
xsltproc checks.xsl __pintail__/tools/pintail.cache
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:mal="http://projectmallard.org/1.0/"
xmlns:cache="http://projectmallard.org/cache/1.0/"
xmlns:site="http://projectmallard.org/site/1.0/"
xmlns:xi="http://www.w3.org/2001/XInclude"
exclude-result-prefixes="str mal cache xi"
version="1.0">
<xsl:output method="text"/>
<xsl:param name="prefix" select="''"/>
<xsl:template match="/cache:cache">
<xsl:for-each select="mal:page">
<xsl:variable name="cache_node" select="."/>
<xsl:if test="starts-with(@id, $prefix)">
<!-- We want the real source pages, not Pintail's staged sources,
because we want to do pre-XInclude checks. -->
<!-- FIXME: EXCEPT DUCKTYPE -->
<xsl:variable name="uri">
<xsl:value-of select="substring-before(@cache:href, '/__pintail__/stage/')"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring-after(@cache:href, '/__pintail__/stage/')"/>
</xsl:variable>
<xsl:apply-templates select="document($uri)/mal:page">
<xsl:with-param name="cache_node" select="$cache_node"/>
</xsl:apply-templates>
</xsl:if>
<!-- Make sure every site:dir has an index.page -->
<xsl:if test="not(preceding-sibling::mal:page[@site:dir=$cache_node/@site:dir])">
<xsl:variable name="dirs" select="str:split(@site:dir, '/')"/>
<xsl:for-each select="$dirs">
<xsl:variable name="pos" select="position()"/>
<xsl:variable name="pardir">
<xsl:text>/</xsl:text>
<xsl:for-each select="$dirs[position() <= $pos]">
<xsl:value-of select="."/>
<xsl:text>/</xsl:text>
</xsl:for-each>
</xsl:variable>
<xsl:if test="not($cache_node/../mal:page[@id=concat($pardir, 'index')])">
<xsl:value-of select="$pardir"/>
<xsl:text>
Missing index.page

</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="/mal:page">
<xsl:param name="cache_node"/>
<xsl:variable name="style" select="concat(' ', @style, ' ')"/>
<xsl:variable name="isspec" select="contains($style, ' spec ') or
contains($style, ' spec-details ') or
contains($style, ' spec-guide ')"/>
<xsl:variable name="errors">
<!-- Check for page style -->
<xsl:if test="not($isspec or
contains($style, ' mep ') or
contains($style, ' tutorial ') or
contains($style, ' pmo-about ') or
contains($style, ' pmo-guide ') or
contains($style, ' pmo-source ') or
contains($style, ' pmo-splash ')
)">
<xsl:text>Bad style attribute
</xsl:text>
</xsl:if>
<!-- Check for credits -->
<xsl:if test="not(mal:info/mal:credit)">
<xsl:text>Missing credits
</xsl:text>
</xsl:if>
<xsl:if test="not(mal:info/mal:credit[contains(concat(' ', @type, ' '), ' author ')])">
<xsl:text>Missing author credits
</xsl:text>
</xsl:if>
<xsl:if test="not(mal:info/mal:credit[contains(concat(' ', @type, ' '), ' copyright ')])">
<xsl:text>Missing copyright credits
</xsl:text>
</xsl:if>
<xsl:if test="not(mal:info/mal:credit/mal:years)">
<xsl:text>Missing copyright years
</xsl:text>
</xsl:if>
<!-- Check for the license -->
<xsl:if test="not(mal:info/xi:include[contains(@href, 'cc-by-sa-3-0.xml')])">
<xsl:text>Missing XInclude for license
</xsl:text>
</xsl:if>
<!-- Check for desc elements on non-index pages -->
<xsl:if test="string(@id) != 'index' and not(mal:info/mal:desc)">
<xsl:text>Missing desc element
</xsl:text>
</xsl:if>
<!-- Check for revision elements -->
<xsl:if test="$isspec">
<xsl:if test="not(mal:info/mal:revision[@date][@docversion][@status])">
<xsl:text>Missing revision element
</xsl:text>
</xsl:if>
</xsl:if>
<!-- Checks only for spec pages -->
<xsl:if test="contains($style, ' spec ')">
<!-- Check for common sections -->
<!--
Notes
Examples
**
Processing Expectations | Specification
Feature Token ?
Comparison to Other Formats ? spec-no-comparison
Schema ? spec-no-schema
-->
<xsl:variable name="sects" select="mal:section"/>
<xsl:if test="not($sects[1][@id='notes'][mal:title='Notes'])">
<xsl:text>Missing Notes section
</xsl:text>
</xsl:if>
<xsl:if test="not($sects[2][@id='examples'][mal:title='Examples'])">
<xsl:text>Missing Examples section
</xsl:text>
</xsl:if>
<xsl:variable name="no_comparison" select="contains($style, ' spec-no-comparison ')"/>
<xsl:variable name="no_schema" select="contains($style, ' spec-no-schema ')"/>
<xsl:variable name="token" select="$sects[count($sects) - (not($no_comparison) + not($no_schema))]
[@id='token'][mal:title='Feature Token']"/>
<xsl:if test="not($sects[count($sects) - (not($no_comparison) + not($no_schema) + count($token))]
[@id='processing'][mal:title='Processing Expectations']
or
$sects[count($sects) - (not($no_comparison) + not($no_schema) + count($token))]
[@id='spec'][mal:title='Specification']
)">
<xsl:text>Missing Processing or Specification section
</xsl:text>
</xsl:if>
<xsl:if test="not($no_comparison) and
not($sects[count($sects)-1][@id='comparison'][mal:title='Comparison to Other Formats'])">
<xsl:text>Missing Comparison section
</xsl:text>
</xsl:if>
<xsl:if test="not($no_schema) and
not($sects[count($sects)][@id='schema'][mal:title='Schema'])">
<xsl:text>Missing Schema section
</xsl:text>
</xsl:if>
<!-- Check for comparisons -->
<xsl:for-each select="$sects[@id='comparison']">
<xsl:if test="not(processing-instruction('no-docbook')) and
not(.//mal:link[@xref='docbook'][string(.) = 'DocBook'])">
<xsl:text>Comparison missing DocBook
</xsl:text>
</xsl:if>
<xsl:if test="not(processing-instruction('no-dita')) and
not(.//mal:link[@xref='dita'][string(.) = 'DITA'])">
<xsl:text>Comparison missing DITA
</xsl:text>
</xsl:if>
</xsl:for-each>
<!-- Check for an actual RNG schema -->
<xsl:for-each select="$sects[@id='schema']">
<xsl:if test="not(mal:synopsis/mal:code[@mime='application/relax-ng-compact-syntax'])">
<xsl:text>Schema missing RNG
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:if>
<!-- Check for MEP structure -->
<xsl:if test="contains($style, ' mep ')">
<!-- Check for common sections -->
<!--
Background
Proposal
Addendums ?
Examples
Accessibility ?
Internationalization ?
Alternatives ?
Compatibility and Fallback
Comparison to Other Formats
-->
<xsl:variable name="sects" select="mal:section"/>
<xsl:if test="not(mal:p[1][@style='lead'])">
<xsl:text>Missing lead paragraph
</xsl:text>
</xsl:if>
<xsl:if test="not($sects[1][@id='background'][mal:title='Background'])">
<xsl:text>Missing Background section
</xsl:text>
</xsl:if>
<xsl:if test="not($sects[2][@id='proposal'][mal:title='Proposal'])">
<xsl:text>Missing Proposal section
</xsl:text>
</xsl:if>
<xsl:if test="$sects[3][@id='addendums']">
<xsl:if test="not($sects[3][mal:title='Addendums'])">
<xsl:text>Missing Addendums section
</xsl:text>
</xsl:if>
</xsl:if>
<xsl:variable name="posex" select="3 + count($sects[3][@id='addendums'])"/>
<xsl:if test="not($sects[$posex][@id='examples'][mal:title='Examples'])">
<xsl:text>Missing Examples section
</xsl:text>
</xsl:if>
<xsl:variable name="posac" select="$posex + 1"/>
<xsl:if test="$sects[$posac][@id='a11y']">
<xsl:if test="not($sects[$posac][mal:title='Accessibility'])">
<xsl:text>Missing Accessibility section
</xsl:text>
</xsl:if>
</xsl:if>
<xsl:variable name="posin" select="$posac + count($sects[$posac][@id='a11y'])"/>
<xsl:if test="$sects[$posin][@id='i18n']">
<xsl:if test="not($sects[$posin][mal:title='Internationalization'])">
<xsl:text>Missing Internationalization section
</xsl:text>
</xsl:if>
</xsl:if>
<xsl:variable name="posalt" select="$posin + count($sects[$posin][@id='i18n'])"/>
<xsl:if test="$sects[$posalt][@id='alternatives']">
<xsl:if test="not($sects[$posalt][mal:title='Alternatives'])">
<xsl:text>Missing Alternatives section
</xsl:text>
</xsl:if>
</xsl:if>
<xsl:variable name="poscom" select="$posalt + count($sects[$posalt][@id='alternatives'])"/>
<xsl:if test="not($sects[$poscom][@id='compatibility'][mal:title='Compatibility and Fallback'])">
<xsl:text>Missing Compatibility and Fallback section
</xsl:text>
</xsl:if>
<xsl:variable name="poscmp" select="$poscom + 1"/>
<xsl:if test="not($sects[$poscmp][@id='comparison'][mal:title='Comparison to Other Formats'])">
<xsl:text>Missing Comparison section
</xsl:text>
</xsl:if>
<!-- MEP titles -->
<xsl:if test="not(mal:info/mal:title[@type='text'])">
<xsl:text>Missing text title
</xsl:text>
</xsl:if>
<xsl:if test="not(mal:info/mal:title[@type='link'])">
<xsl:text>Missing link title
</xsl:text>
</xsl:if>
<xsl:if test="not(mal:subtitle)">
<xsl:text>Missing subtitle
</xsl:text>
</xsl:if>
<xsl:if test="string(mal:info/mal:title[@type='text']) != string(mal:subtitle)">
<xsl:text>Mismatched text title and subtitle
</xsl:text>
</xsl:if>
<xsl:if test="concat(mal:title, ': ', mal:subtitle) !=
string(mal:info/mal:title[@type='link'])">
<xsl:text>Mismatched link title and title/subtitle
</xsl:text>
</xsl:if>
<!-- MEP status checks -->
<xsl:variable name="status">
<xsl:for-each select="mal:info/mal:revision">
<xsl:sort select="@date"/>
<xsl:if test="position() = last()">
<xsl:value-of select="@status"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:if test="not(contains(
' incomplete proposed revised implemented final rejected replaced withdrawn ',
concat(' ', $status, ' ') ))">
<xsl:text>Unknown MEP status </xsl:text>
<xsl:value-of select="$status"/>
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:variable name="docversion">
<xsl:for-each select="mal:info/mal:revision">
<xsl:sort select="@date"/>
<xsl:if test="position() = last()">
<xsl:value-of select="@docversion"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:if test="$docversion != mal:info/mal:link[@type='guide' and @xref='index']/@group">
<xsl:text>Mismatched docversion and link group
</xsl:text>
</xsl:if>
<!-- MEP links -->
<xsl:if test="not(mal:info/mal:link[@type='mep:issue'][starts-with(@href, 'https://github.com/projectmallard/projectmallard.org/issues/')])">
<xsl:text>Missing GitHub issue link
</xsl:text>
</xsl:if>
</xsl:if>
<xsl:apply-templates mode="block.checks" select="*"/>
</xsl:variable>
<xsl:if test="$errors != ''">
<xsl:value-of select="$cache_node/@id"/>
<xsl:text>
</xsl:text>
<xsl:value-of select="$errors"/>
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template mode="block.checks" match="mal:p | mal:screen | mal:title |
mal:subtitle | mal:desc | mal:cite | mal:name"/>
<xsl:template mode="block.checks" match="*">
<xsl:apply-templates mode="block.checks" select="*"/>
</xsl:template>
<xsl:template mode="block.checks" match="mal:tree//mal:item">
<xsl:apply-templates mode="block.checks" select="mal:item"/>
</xsl:template>
<xsl:template mode="block.checks" match="mal:code">
<xsl:choose>
<xsl:when test="not(@type) and not(@mime)">
<xsl:if test="not(contains(concat(' ', @style, ' '), ' no-mime '))">
<xsl:text>Missing type or mime attribute on code
</xsl:text>
</xsl:if>
</xsl:when>
<xsl:when test="@type = 'cpp'"/>
<xsl:when test="@type = 'xml'"/>
<xsl:when test="@mime = 'application/xml'"/>
<xsl:when test="@mime = 'application/relax-ng-compact-syntax'"/>
<xsl:when test="@mime = 'text/x-c++src'"/>
<xsl:when test="@mime = 'text/x-ducktype'"/>
<xsl:when test="@type">
<xsl:text>Incorrect type attribute: </xsl:text>
<xsl:value-of select="@type"/>
<xsl:text>
</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>Incorrect mime attribute: </xsl:text>
<xsl:value-of select="@mime"/>
<xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>