Debian Codegraph @

en/stylesheets/dbv5.xsl

raw symbols SCIP
1 <?xml version="1.0"?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:set="http://exslt.org/sets"
4 xmlns:rng="http://relaxng.org/ns/structure/1.0"
5 xmlns:s="http://www.ascc.net/xml/schematron"
6 xmlns:doc="http://nwalsh.com/xmlns/schema-doc/"
7 exclude-result-prefixes="rng set s doc"
8 version="1.0">
9
10 <xsl:strip-space elements="rng:*"/>
11
12 <xsl:variable name="db5doc" select="document('build/lib/docbook-rng.xml',.)/rng:grammar"/>
13
14 <xsl:key name="defs" match="rng:define" use="@name"/>
15 <xsl:key name="elemdefs" match="rng:define[rng:element]" use="rng:element/@name"/>
16
17 <xsl:template name="rng-element">
18 <xsl:param name="element" select="'nop'"/>
19 <xsl:choose>
20 <xsl:when test="$element = '*'">
21 <xsl:apply-templates/>
22 </xsl:when>
23 <xsl:otherwise>
24 <xsl:for-each select="$db5doc//rng:define[rng:element[@name=$element]]">
25 <xsl:apply-templates select=".">
26 <xsl:with-param name="elemNum" select="position()"/>
27 </xsl:apply-templates>
28 </xsl:for-each>
29 </xsl:otherwise>
30 </xsl:choose>
31 </xsl:template>
32
33 <xsl:template match="rng:start">
34 <div class="start">
35 <h1>
36 <a name="start"/>
37 <xsl:text>Start</xsl:text>
38 </h1>
39
40 <ul>
41 <xsl:apply-templates/>
42 </ul>
43 </div>
44 </xsl:template>
45
46 <xsl:template match="rng:define[rng:element]" priority="2">
47 <xsl:param name="elemNum" select="1"/>
48
49 <div>
50 <xsl:attribute name="class">
51 <xsl:choose>
52 <xsl:when test="$elemNum = 1">define-first</xsl:when>
53 <xsl:otherwise>define-next</xsl:otherwise>
54 </xsl:choose>
55 </xsl:attribute>
56
57 <xsl:apply-templates>
58 <xsl:with-param name="elemNum" select="$elemNum"/>
59 </xsl:apply-templates>
60 </div>
61 </xsl:template>
62
63 <xsl:template match="rng:define">
64 <div class="define">
65 <xsl:value-of select="@name"/>
66
67 <ul>
68 <xsl:apply-templates/>
69 </ul>
70 </div>
71 </xsl:template>
72
73 <xsl:template match="rng:text">
74 <li><em>text</em></li>
75 </xsl:template>
76
77 <xsl:template match="rng:notAllowed">
78 <!-- nop -->
79 </xsl:template>
80
81 <xsl:template match="rng:empty">
82 <li><em>EMPTY</em></li>
83 </xsl:template>
84
85 <xsl:template match="rng:element">
86 <xsl:param name="elemNum" select="1"/>
87 <xsl:variable name="xdefs" select="key('elemdefs', @name)"/>
88
89 <div class="element">
90 <xsl:value-of select="@name"/>
91 <xsl:if test="count($xdefs) &gt; 1">
92 <xsl:text> (</xsl:text>
93 <xsl:value-of select="../@name"/>
94 <xsl:text>)</xsl:text>
95 </xsl:if>
96 <xsl:text> ::=</xsl:text>
97
98 <ul>
99 <xsl:choose>
100 <xsl:when test="doc:content-model">
101 <xsl:apply-templates select="doc:content-model/*"/>
102 </xsl:when>
103 <xsl:otherwise>
104 <xsl:apply-templates/>
105 </xsl:otherwise>
106 </xsl:choose>
107 </ul>
108
109 <xsl:apply-templates select="doc:attributes"/>
110 <xsl:apply-templates select="doc:rules"/>
111 </div>
112 </xsl:template>
113
114 <xsl:template match="doc:attributes">
115 <xsl:variable name="attributes" select=".//rng:attribute"/>
116
117 <xsl:variable name="cmnAttr"
118 select="$attributes[@name='id' and parent::rng:optional]
119 |$attributes[@name='xml:lang']
120 |$attributes[@name='xml:base']
121 |$attributes[@name='remap']
122 |$attributes[@name='xreflabel']
123 |$attributes[@name='revisionflag']
124 |$attributes[@name='arch']
125 |$attributes[@name='condition']
126 |$attributes[@name='conformance']
127 |$attributes[@name='os']
128 |$attributes[@name='revision']
129 |$attributes[@name='security']
130 |$attributes[@name='userlevel']
131 |$attributes[@name='vendor']
132 |$attributes[@name='role']
133 |$attributes[@name='version']"/>
134
135 <xsl:variable name="cmnAttrIdReq"
136 select="$attributes[@name='id' and not(parent::rng:optional)]
137 |$attributes[@name='xml:lang']
138 |$attributes[@name='xml:base']
139 |$attributes[@name='remap']
140 |$attributes[@name='xreflabel']
141 |$attributes[@name='revisionflag']
142 |$attributes[@name='arch']
143 |$attributes[@name='condition']
144 |$attributes[@name='conformance']
145 |$attributes[@name='os']
146 |$attributes[@name='revision']
147 |$attributes[@name='security']
148 |$attributes[@name='userlevel']
149 |$attributes[@name='vendor']
150 |$attributes[@name='role']
151 |$attributes[@name='version']"/>
152
153 <xsl:variable name="cmnAttrEither" select="$cmnAttr|$cmnAttrIdReq"/>
154
155 <xsl:variable name="cmnLinkAttr"
156 select="$attributes[@name='href' and $attributes[@name='linkend']]
157 |$attributes[@name='linkend' and $attributes[@name='href']]"/>
158
159 <xsl:variable name="otherAttr"
160 select="set:difference($attributes,
161 $cmnAttr|$cmnAttrIdReq|$cmnLinkAttr)"/>
162
163 <h4>DocBook NG “<xsl:value-of select="$ng-release"/>” Attributes</h4>
164
165 <xsl:choose>
166 <xsl:when test="count($cmnAttr) = 16 and $cmnLinkAttr">
167 <p>Common attributes and common linking attributes.</p>
168 </xsl:when>
169 <xsl:when test="count($cmnAttrIdReq) = 16 and $cmnLinkAttr">
170 <p>Common attributes (ID required) and common linking atttributes.</p>
171 </xsl:when>
172 <xsl:when test="count($cmnAttr) = 16">
173 <p>Common attributes.</p>
174 </xsl:when>
175 <xsl:when test="count($cmnAttrIdReq) = 16">
176 <p>Common attributes (ID required).</p>
177 </xsl:when>
178 <xsl:when test="$cmnLinkAttr">
179 <p>Common linking attributes.</p>
180 </xsl:when>
181 </xsl:choose>
182
183 <xsl:if test="count($cmnAttrEither) != 16 or count($otherAttr) &gt; 0">
184 <p>
185 <xsl:choose>
186 <xsl:when test="count($cmnAttr) = 16
187 or count($cmnAttrIdReq) = 15
188 or $cmnLinkAttr">
189 <xsl:text>Additional attributes:</xsl:text>
190 </xsl:when>
191 <xsl:otherwise>
192 <xsl:text>Attributes:</xsl:text>
193 </xsl:otherwise>
194 </xsl:choose>
195 <xsl:text> (Required attributes, if any, are </xsl:text>
196 <b>bold</b>
197 <xsl:text>)</xsl:text>
198 </p>
199
200 <ul>
201 <xsl:for-each select="rng:interleave/*|*[not(self::rng:interleave)]">
202 <xsl:sort select="descendant-or-self::rng:attribute/@name"/>
203 <!-- don't bother with common attributes -->
204 <xsl:variable name="name" select="descendant-or-self::rng:attribute/@name"/>
205 <xsl:choose>
206 <xsl:when test="$cmnAttrEither[@name=$name]|$cmnLinkAttr[@name=$name]"/>
207 <xsl:otherwise>
208 <xsl:apply-templates select="." mode="attributes"/>
209 </xsl:otherwise>
210 </xsl:choose>
211 </xsl:for-each>
212 </ul>
213 </xsl:if>
214 </xsl:template>
215
216 <xsl:template match="rng:optional" mode="attributes">
217 <xsl:apply-templates mode="attributes"/>
218 </xsl:template>
219
220 <xsl:template match="rng:choice" mode="attributes">
221 <li>
222 <xsl:choose>
223 <xsl:when test="ancestor::rng:optional">
224 <em>At most one of:</em>
225 </xsl:when>
226 <xsl:otherwise>
227 <em>Exactly one of:</em>
228 </xsl:otherwise>
229 </xsl:choose>
230 <ul>
231 <xsl:apply-templates mode="attributes"/>
232 </ul>
233 </li>
234 </xsl:template>
235
236 <xsl:template match="rng:interleave" mode="attributes">
237 <li>
238 <xsl:choose>
239 <xsl:when test="ancestor::rng:optional">
240 <em>All or none of:</em>
241 </xsl:when>
242 <xsl:otherwise>
243 <em>All of:</em>
244 </xsl:otherwise>
245 </xsl:choose>
246 <ul>
247 <xsl:apply-templates mode="attributes"/>
248 </ul>
249 </li>
250 </xsl:template>
251
252 <xsl:template match="rng:group" mode="attributes">
253 <li>
254 <em>Each of:</em>
255 <ul>
256 <xsl:apply-templates mode="attributes"/>
257 </ul>
258 </li>
259 </xsl:template>
260
261 <xsl:template match="rng:ref" mode="attributes">
262 <xsl:variable name="attrs" select="key('defs', @name)/rng:attribute"/>
263
264 <xsl:choose>
265 <xsl:when test="count($attrs) &gt; 1">
266 <li>
267 <xsl:choose>
268 <xsl:when test="ancestor::rng:optional">
269 <em>At most one of:</em>
270 </xsl:when>
271 <xsl:otherwise>
272 <em><b>Each of:</b></em>
273 </xsl:otherwise>
274 </xsl:choose>
275 <ul>
276 <xsl:apply-templates select="$attrs" mode="attributes">
277 <xsl:with-param name="optional" select="ancestor::rng:optional"/>
278 <xsl:with-param name="choice" select="ancestor::rng:choice"/>
279 </xsl:apply-templates>
280 </ul>
281 </li>
282 </xsl:when>
283 <xsl:otherwise>
284 <xsl:apply-templates select="$attrs" mode="attributes">
285 <xsl:with-param name="optional" select="ancestor::rng:optional"/>
286 <xsl:with-param name="choice" select="ancestor::rng:choice"/>
287 </xsl:apply-templates>
288 </xsl:otherwise>
289 </xsl:choose>
290 </xsl:template>
291
292 <xsl:template match="rng:attribute" mode="attributes">
293 <xsl:param name="optional" select="ancestor::rng:optional"/>
294 <xsl:param name="choice" select="ancestor::rng:choice"/>
295
296 <li>
297 <xsl:choose>
298 <xsl:when test="$optional">
299 <xsl:value-of select="@name"/>
300 </xsl:when>
301 <xsl:otherwise>
302 <b>
303 <xsl:value-of select="@name"/>
304 </b>
305 </xsl:otherwise>
306 </xsl:choose>
307
308 <xsl:choose>
309 <xsl:when test="rng:choice|rng:value">
310 <xsl:text> (enumeration)</xsl:text>
311 <ul>
312 <xsl:for-each select="rng:choice/rng:value|rng:value">
313 <li>
314 <xsl:text>“</xsl:text>
315 <xsl:value-of select="."/>
316 <xsl:text>”</xsl:text>
317 </li>
318 </xsl:for-each>
319 </ul>
320 </xsl:when>
321 <xsl:when test="rng:data">
322 <xsl:text> (</xsl:text>
323 <xsl:value-of select="rng:data/@type"/>
324 <xsl:text>)</xsl:text>
325 </xsl:when>
326 </xsl:choose>
327 </li>
328 </xsl:template>
329
330 <xsl:template match="doc:rules">
331 <h4>DocBook NG “<xsl:value-of select="$ng-release"/>” Additional Constraints</h4>
332
333 <ul>
334 <xsl:for-each select=".//s:assert">
335 <li>
336 <xsl:value-of select="."/>
337 </li>
338 </xsl:for-each>
339 </ul>
340 </xsl:template>
341
342 <xsl:template match="rng:value">
343 <xsl:if test="position() &gt; 1"> | </xsl:if>
344 <span class="{local-name()}">
345 <xsl:text>“</xsl:text>
346 <xsl:apply-templates/>
347 <xsl:text>”</xsl:text>
348 </span>
349 </xsl:template>
350
351 <xsl:template match="rng:ref">
352 <xsl:variable name="elemName" select="(key('defs', @name)/rng:element)[1]/@name"/>
353 <xsl:variable name="xdefs" select="key('elemdefs', $elemName)"/>
354
355 <li>
356 <xsl:choose>
357 <xsl:when test="$elemName">
358 <tt>
359 <a href="{$elemName}.html">
360 <xsl:value-of select="key('defs', @name)/rng:element/@name"/>
361 </a>
362 </tt>
363 <xsl:if test="parent::rng:optional">?</xsl:if>
364 </xsl:when>
365 <xsl:otherwise>
366 <xsl:value-of select="@name"/>
367 <xsl:if test="parent::rng:optional">?</xsl:if>
368 </xsl:otherwise>
369 </xsl:choose>
370
371 <xsl:if test="count($xdefs) &gt; 1">
372 <xsl:text> (</xsl:text>
373 <xsl:value-of select="@name"/>
374 <xsl:text>)</xsl:text>
375 </xsl:if>
376 </li>
377 </xsl:template>
378
379 <xsl:template match="rng:optional">
380 <xsl:apply-templates/>
381 </xsl:template>
382
383 <xsl:template match="rng:zeroOrMore">
384 <li><xsl:text>Zero or more of:</xsl:text></li>
385 <ul class="{local-name()}">
386 <xsl:apply-templates>
387 <xsl:sort select="key('defs',@name)/rng:element/@name"/>
388 <xsl:sort select="@name"/>
389 </xsl:apply-templates>
390 </ul>
391 </xsl:template>
392
393 <xsl:template match="rng:oneOrMore">
394 <li>
395 <xsl:choose>
396 <xsl:when test="parent::rng:optional">
397 <xsl:text>Optional one or more of:</xsl:text>
398 </xsl:when>
399 <xsl:otherwise>
400 <xsl:text>One or more of:</xsl:text>
401 </xsl:otherwise>
402 </xsl:choose>
403 </li>
404 <ul class="{local-name()}">
405 <xsl:apply-templates>
406 <xsl:sort select="key('defs',@name)/rng:element/@name"/>
407 <xsl:sort select="@name"/>
408 </xsl:apply-templates>
409 </ul>
410 </xsl:template>
411
412 <xsl:template match="rng:group">
413 <li>
414 <xsl:choose>
415 <xsl:when test="parent::rng:optional">
416 <xsl:text>Optional sequence of:</xsl:text>
417 </xsl:when>
418 <xsl:otherwise>
419 <xsl:text>Sequence of:</xsl:text>
420 </xsl:otherwise>
421 </xsl:choose>
422 </li>
423 <ul class="{local-name()}">
424 <xsl:apply-templates/>
425 </ul>
426 </xsl:template>
427
428 <xsl:template match="rng:interleave">
429 <li>
430 <xsl:choose>
431 <xsl:when test="parent::rng:optional">
432 <xsl:text>Optional interleave of:</xsl:text>
433 </xsl:when>
434 <xsl:otherwise>
435 <xsl:text>Interleave of:</xsl:text>
436 </xsl:otherwise>
437 </xsl:choose>
438 </li>
439 <ul class="{local-name()}">
440 <xsl:apply-templates/>
441 </ul>
442 </xsl:template>
443
444 <xsl:template match="rng:choice">
445 <li>
446 <xsl:choose>
447 <xsl:when test="parent::rng:optional">
448 <xsl:text>Optionally one of: </xsl:text>
449 </xsl:when>
450 <xsl:otherwise>
451 <xsl:text>One of: </xsl:text>
452 </xsl:otherwise>
453 </xsl:choose>
454 </li>
455 <ul class="{local-name()}">
456 <xsl:apply-templates>
457 <xsl:sort select="key('defs',@name)/rng:element/@name"/>
458 <xsl:sort select="@name"/>
459 </xsl:apply-templates>
460 </ul>
461 </xsl:template>
462
463 </xsl:stylesheet>