]> git.saurik.com Git - bison.git/blob - data/xslt/xml2xhtml.xsl
* src/gram.c: Remove comments that duplicate comments in gram.h.
[bison.git] / data / xslt / xml2xhtml.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!--
4 xml2html.xsl - transform Bison XML Report into XHTML.
5 $Id$
6
7 Copyright (C) 2007 Free Software Foundation, Inc.
8
9 This file is part of Bison, the GNU Compiler Compiler.
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23
24 Written by Wojciech Polak <polak@gnu.org>.
25 -->
26
27 <xsl:stylesheet version="1.0"
28 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
29 xmlns="http://www.w3.org/1999/xhtml"
30 xmlns:bison="http://www.gnu.org/software/bison/">
31
32 <xsl:import href="bison.xsl"/>
33
34 <xsl:output method="xml" encoding="UTF-8"
35 doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
36 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
37 indent="yes"/>
38
39 <xsl:template match="/">
40 <html>
41 <head>
42 <title>GNU Bison XML Automaton Report</title>
43 <style type="text/css"><![CDATA[
44 body {
45 font-family: "Nimbus Sans L", Arial, sans-serif;
46 font-size: 9pt;
47 }
48 a:link {
49 color: #1f00ff;
50 text-decoration: none;
51 }
52 a:visited {
53 color: #1f00ff;
54 text-decoration: none;
55 }
56 a:hover {
57 color: red;
58 }
59 #menu a {
60 text-decoration: underline;
61 }
62 .i {
63 font-style: italic;
64 }
65 .pre {
66 font-family: monospace;
67 white-space: pre;
68 }
69 ol.decimal {
70 list-style-type: decimal;
71 }
72 ol.lower-alpha {
73 list-style-type: lower-alpha;
74 }
75 .point {
76 color: #cc0000;
77 }
78 #footer {
79 margin-top: 3.5em;
80 font-size: 7pt;
81 }
82 ]]></style>
83 </head>
84 <body>
85 <xsl:apply-templates select="bison-xml-report"/>
86 <xsl:text>&#10;&#10;</xsl:text>
87 <div id="footer"><hr />
88 <a href="http://www.gnu.org/software/bison/" title="GNU Bison">
89 GNU Bison <xsl:value-of select="/bison-xml-report/@version"/></a>
90 XML Automaton Report, written by
91 <a href="http://www.gnu.org.ua/~polak/" title="Wojciech Polak">Wojciech Polak</a>.
92 Copyright (C) 2007 Free Software Foundation, Inc.<br />
93 Verbatim copying and distribution of this entire page is permitted
94 in any medium, provided this notice is preserved.</div>
95 </body>
96 </html>
97 </xsl:template>
98
99 <xsl:template match="bison-xml-report">
100 <h1>GNU Bison XML Automaton Report</h1>
101 <p>
102 input grammar: <span class="i"><xsl:value-of select="filename"/></span>
103 </p>
104
105 <xsl:text>&#10;&#10;</xsl:text>
106 <h3>Table of Contents</h3>
107 <ul id="menu">
108 <li>
109 <a href="#reductions">Reductions</a>
110 <ul class="lower-alpha">
111 <li><a href="#nonterminals_useless_in_grammar">Nonterminals useless in grammar</a></li>
112 <li><a href="#unused_terminals">Unused terminals</a></li>
113 <li><a href="#rules_useless_in_grammar">Rules useless in grammar</a></li>
114 <xsl:if test="rules-useless-in-parser/rule">
115 <li><a href="#rules_useless_in_parser">Rules useless in parser due to conflicts</a></li>
116 </xsl:if>
117 </ul>
118 </li>
119 <li><a href="#conflicts">Conflicts</a></li>
120 <li>
121 <a href="#grammar">Grammar</a>
122 <ul class="lower-alpha">
123 <li><a href="#grammar">Itemset</a></li>
124 <li><a href="#terminals">Terminal symbols</a></li>
125 <li><a href="#nonterminals">Nonterminal symbols</a></li>
126 </ul>
127 </li>
128 <li><a href="#automaton">Automaton</a></li>
129 </ul>
130 <xsl:apply-templates select="reductions"/>
131 <xsl:apply-templates select="rules-useless-in-parser"/>
132 <xsl:apply-templates select="automaton" mode="conflicts"/>
133 <xsl:apply-templates select="grammar"/>
134 <xsl:apply-templates select="automaton"/>
135 </xsl:template>
136
137 <xsl:template match="rules-useless-in-parser">
138 <xsl:if test="rule">
139 <h2>
140 <a name="rules_useless_in_parser"/>
141 <xsl:text> Rules useless in parser due to conflicts</xsl:text>
142 </h2>
143 <xsl:text>&#10;</xsl:text>
144 <p class="pre">
145 <xsl:apply-templates select="rule">
146 <xsl:with-param name="pad" select="'3'"/>
147 </xsl:apply-templates>
148 </p>
149 <xsl:text>&#10;&#10;</xsl:text>
150 </xsl:if>
151 </xsl:template>
152
153 <xsl:template match="reductions">
154 <h2>
155 <a name="reductions"/>
156 <xsl:text> Reductions</xsl:text>
157 </h2>
158 <xsl:apply-templates select="useless-in-grammar/nonterminals"/>
159 <xsl:apply-templates select="unused/terminals"/>
160 <xsl:apply-templates select="useless-in-grammar/rules"/>
161 </xsl:template>
162
163 <xsl:template match="useless-in-grammar/nonterminals">
164 <h3>
165 <a name="nonterminals_useless_in_grammar"/>
166 <xsl:text> Nonterminals useless in grammar</xsl:text>
167 </h3>
168 <xsl:text>&#10;&#10;</xsl:text>
169 <xsl:if test="nonterminal">
170 <p class="pre">
171 <xsl:for-each select="nonterminal">
172 <xsl:text> </xsl:text>
173 <xsl:value-of select="."/>
174 <xsl:text>&#10;</xsl:text>
175 </xsl:for-each>
176 <xsl:text>&#10;&#10;</xsl:text>
177 </p>
178 </xsl:if>
179 </xsl:template>
180
181 <xsl:template match="useless-in-grammar/rules">
182 <h3>
183 <a name="rules_useless_in_grammar"/>
184 <xsl:text> Rules useless in grammar</xsl:text>
185 </h3>
186 <xsl:text>&#10;</xsl:text>
187 <xsl:if test="rule">
188 <p class="pre">
189 <xsl:apply-templates select="rule">
190 <xsl:with-param name="pad" select="'3'"/>
191 </xsl:apply-templates>
192 <xsl:text>&#10;&#10;</xsl:text>
193 </p>
194 </xsl:if>
195 </xsl:template>
196
197 <xsl:template match="unused/terminals">
198 <h3>
199 <a name="unused_terminals"/>
200 <xsl:text> Terminals which are not used</xsl:text>
201 </h3>
202 <xsl:text>&#10;&#10;</xsl:text>
203 <xsl:if test="terminal">
204 <p class="pre">
205 <xsl:for-each select="terminal">
206 <xsl:text> </xsl:text>
207 <xsl:value-of select="."/>
208 <xsl:text>&#10;</xsl:text>
209 </xsl:for-each>
210 <xsl:text>&#10;&#10;</xsl:text>
211 </p>
212 </xsl:if>
213 </xsl:template>
214
215 <xsl:template match="automaton" mode="conflicts">
216 <h2>
217 <a name="conflicts"/>
218 <xsl:text> Conflicts</xsl:text>
219 </h2>
220 <xsl:text>&#10;&#10;</xsl:text>
221 <xsl:variable name="conflict-report">
222 <xsl:apply-templates select="state" mode="conflicts"/>
223 </xsl:variable>
224 <xsl:if test="string-length($conflict-report) != 0">
225 <p class="pre">
226 <xsl:copy-of select="$conflict-report"/>
227 <xsl:text>&#10;&#10;</xsl:text>
228 </p>
229 </xsl:if>
230 </xsl:template>
231
232 <xsl:template match="state" mode="conflicts">
233 <xsl:variable name="conflict-counts">
234 <xsl:apply-templates select="." mode="bison:count-conflicts" />
235 </xsl:variable>
236 <xsl:variable
237 name="sr-count" select="substring-before($conflict-counts, ',')"
238 />
239 <xsl:variable
240 name="rr-count" select="substring-after($conflict-counts, ',')"
241 />
242 <xsl:if test="$sr-count > 0 or $rr-count > 0">
243 <a>
244 <xsl:attribute name="href">
245 <xsl:value-of select="concat('#state_', @number)"/>
246 </xsl:attribute>
247 <xsl:value-of select="concat('State ', @number)"/>
248 </a>
249 <xsl:text> conflicts:</xsl:text>
250 <xsl:if test="$sr-count > 0">
251 <xsl:value-of select="concat(' ', $sr-count, ' shift/reduce')"/>
252 <xsl:if test="$rr-count > 0">
253 <xsl:value-of select="(',')"/>
254 </xsl:if>
255 </xsl:if>
256 <xsl:if test="$rr-count > 0">
257 <xsl:value-of select="concat(' ', $rr-count, ' reduce/reduce')"/>
258 </xsl:if>
259 <xsl:value-of select="'&#10;'"/>
260 </xsl:if>
261 </xsl:template>
262
263 <xsl:template match="grammar">
264 <h2>
265 <a name="grammar"/>
266 <xsl:text> Grammar</xsl:text>
267 </h2>
268 <xsl:text>&#10;</xsl:text>
269 <p class="pre">
270 <xsl:apply-templates select="rules/rule">
271 <xsl:with-param name="pad" select="'3'"/>
272 </xsl:apply-templates>
273 </p>
274 <xsl:text>&#10;&#10;</xsl:text>
275 <xsl:apply-templates select="terminals"/>
276 <xsl:apply-templates select="nonterminals"/>
277 </xsl:template>
278
279 <xsl:template match="grammar/terminals">
280 <h3>
281 <a name="terminals"/>
282 <xsl:text> Terminals, with rules where they appear</xsl:text>
283 </h3>
284 <xsl:text>&#10;&#10;</xsl:text>
285 <p class="pre">
286 <xsl:apply-templates select="terminal"/>
287 </p>
288 <xsl:text>&#10;&#10;</xsl:text>
289 </xsl:template>
290
291 <xsl:template match="grammar/nonterminals">
292 <h3>
293 <a name="nonterminals"/>
294 <xsl:text> Nonterminals, with rules where they appear</xsl:text>
295 </h3>
296 <xsl:text>&#10;&#10;</xsl:text>
297 <p class="pre">
298 <xsl:apply-templates select="nonterminal"/>
299 </p>
300 </xsl:template>
301
302 <xsl:template match="terminal">
303 <b><xsl:value-of select="@name"/></b>
304 <xsl:value-of select="concat(' (', @token-number, ')')"/>
305 <xsl:apply-templates select="rule"/>
306 <xsl:text>&#10;</xsl:text>
307 </xsl:template>
308
309 <xsl:template match="terminal/rule">
310 <xsl:text> </xsl:text>
311 <a>
312 <xsl:attribute name="href">
313 <xsl:value-of select="concat('#rule_', .)"/>
314 </xsl:attribute>
315 <xsl:value-of select="."/>
316 </a>
317 </xsl:template>
318
319 <xsl:template match="nonterminal">
320 <b><xsl:value-of select="@name"/></b>
321 <xsl:value-of select="concat(' (', @symbol-number, ')')"/>
322 <xsl:text>&#10; </xsl:text>
323 <xsl:if test="left/rule">
324 <xsl:text>on left:</xsl:text>
325 </xsl:if>
326 <xsl:apply-templates select="left/rule"/>
327 <xsl:if test="left/rule and right/rule">
328 <xsl:text>&#10; </xsl:text>
329 </xsl:if>
330 <xsl:if test="right/rule">
331 <xsl:text>on right:</xsl:text>
332 </xsl:if>
333 <xsl:apply-templates select="right/rule"/>
334 <xsl:text>&#10;</xsl:text>
335 </xsl:template>
336
337 <xsl:template match="nonterminal/left/rule|nonterminal/right/rule">
338 <xsl:text> </xsl:text>
339 <a>
340 <xsl:attribute name="href">
341 <xsl:value-of select="concat('#rule_', .)"/>
342 </xsl:attribute>
343 <xsl:value-of select="."/>
344 </a>
345 </xsl:template>
346
347 <xsl:template match="automaton">
348 <h2>
349 <a name="automaton"/>
350 <xsl:text> Automaton</xsl:text>
351 </h2>
352 <xsl:apply-templates select="state">
353 <xsl:with-param name="pad" select="'3'"/>
354 </xsl:apply-templates>
355 </xsl:template>
356
357 <xsl:template match="automaton/state">
358 <xsl:param name="pad"/>
359 <xsl:text>&#10;&#10;</xsl:text>
360 <h3>
361 <a>
362 <xsl:attribute name="name">
363 <xsl:value-of select="concat('state_', @number)"/>
364 </xsl:attribute>
365 </a>
366 <xsl:text>state </xsl:text>
367 <xsl:value-of select="@number"/>
368 </h3>
369 <xsl:text>&#10;&#10;</xsl:text>
370 <p class="pre">
371 <xsl:apply-templates select="itemset/item">
372 <xsl:with-param name="pad" select="$pad"/>
373 </xsl:apply-templates>
374 <xsl:apply-templates select="actions/transitions">
375 <xsl:with-param name="type" select="'shift'"/>
376 </xsl:apply-templates>
377 <xsl:apply-templates select="actions/errors"/>
378 <xsl:apply-templates select="actions/reductions"/>
379 <xsl:apply-templates select="actions/transitions">
380 <xsl:with-param name="type" select="'goto'"/>
381 </xsl:apply-templates>
382 <xsl:apply-templates select="solved-conflicts"/>
383 </p>
384 </xsl:template>
385
386 <xsl:template match="actions/transitions">
387 <xsl:param name="type"/>
388 <xsl:if test="transition[@type = $type]">
389 <xsl:text>&#10;</xsl:text>
390 <xsl:apply-templates select="transition[@type = $type]">
391 <xsl:with-param name="pad">
392 <xsl:call-template name="max-width-symbol">
393 <xsl:with-param name="node" select="transition[@type = $type]"/>
394 </xsl:call-template>
395 </xsl:with-param>
396 </xsl:apply-templates>
397 </xsl:if>
398 </xsl:template>
399
400 <xsl:template match="actions/errors">
401 <xsl:if test="error">
402 <xsl:text>&#10;</xsl:text>
403 <xsl:apply-templates select="error">
404 <xsl:with-param name="pad">
405 <xsl:call-template name="max-width-symbol">
406 <xsl:with-param name="node" select="error"/>
407 </xsl:call-template>
408 </xsl:with-param>
409 </xsl:apply-templates>
410 </xsl:if>
411 </xsl:template>
412
413 <xsl:template match="actions/reductions">
414 <xsl:if test="reduction">
415 <xsl:text>&#10;</xsl:text>
416 <xsl:apply-templates select="reduction">
417 <xsl:with-param name="pad">
418 <xsl:call-template name="max-width-symbol">
419 <xsl:with-param name="node" select="reduction"/>
420 </xsl:call-template>
421 </xsl:with-param>
422 </xsl:apply-templates>
423 </xsl:if>
424 </xsl:template>
425
426 <xsl:template match="item">
427 <xsl:param name="pad"/>
428 <xsl:param name="prev-rule-number"
429 select="preceding-sibling::item[1]/@rule-number"/>
430 <xsl:apply-templates select="key('bison:ruleNumber', current()/@rule-number)">
431 <xsl:with-param name="itemset" select="'true'"/>
432 <xsl:with-param name="pad" select="$pad"/>
433 <xsl:with-param name="prev-lhs"
434 select="key('bison:ruleNumber', $prev-rule-number)/lhs[text()]"/>
435 <xsl:with-param name="point" select="@point"/>
436 <xsl:with-param name="lookaheads">
437 <xsl:apply-templates select="lookaheads"/>
438 </xsl:with-param>
439 </xsl:apply-templates>
440 </xsl:template>
441
442 <xsl:template match="rule">
443 <xsl:param name="itemset"/>
444 <xsl:param name="pad"/>
445 <xsl:param name="prev-lhs"/>
446 <xsl:param name="point"/>
447 <xsl:param name="lookaheads"/>
448
449 <xsl:if test="$itemset != 'true'
450 and not(preceding-sibling::rule[1]/lhs[text()] = lhs[text()])">
451 <xsl:text>&#10;</xsl:text>
452 </xsl:if>
453
454 <xsl:if test="$itemset != 'true'">
455 <a>
456 <xsl:attribute name="name">
457 <xsl:value-of select="concat('rule_', @number)"/>
458 </xsl:attribute>
459 </a>
460 </xsl:if>
461 <xsl:text> </xsl:text>
462
463 <xsl:choose>
464 <xsl:when test="$itemset = 'true'">
465 <a>
466 <xsl:attribute name="href">
467 <xsl:value-of select="concat('#rule_', @number)"/>
468 </xsl:attribute>
469 <xsl:call-template name="lpad">
470 <xsl:with-param name="str" select="string(@number)"/>
471 <xsl:with-param name="pad" select="number($pad)"/>
472 </xsl:call-template>
473 </a>
474 </xsl:when>
475 <xsl:otherwise>
476 <xsl:call-template name="lpad">
477 <xsl:with-param name="str" select="string(@number)"/>
478 <xsl:with-param name="pad" select="number($pad)"/>
479 </xsl:call-template>
480 </xsl:otherwise>
481 </xsl:choose>
482 <xsl:text> </xsl:text>
483
484 <!-- LHS -->
485 <xsl:choose>
486 <xsl:when test="$itemset != 'true'
487 and preceding-sibling::rule[1]/lhs[text()] = lhs[text()]">
488 <xsl:call-template name="lpad">
489 <xsl:with-param name="str" select="'|'"/>
490 <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
491 </xsl:call-template>
492 </xsl:when>
493 <xsl:when test="$itemset = 'true' and $prev-lhs = lhs[text()]">
494 <xsl:call-template name="lpad">
495 <xsl:with-param name="str" select="'|'"/>
496 <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
497 </xsl:call-template>
498 </xsl:when>
499 <xsl:otherwise>
500 <span class="i">
501 <xsl:value-of select="lhs"/>
502 </span>
503 <xsl:text> &#8594;</xsl:text>
504 </xsl:otherwise>
505 </xsl:choose>
506
507 <!-- RHS -->
508 <xsl:for-each select="rhs/*">
509 <xsl:if test="position() = $point + 1">
510 <xsl:text> </xsl:text>
511 <span class="point">.</span>
512 </xsl:if>
513 <xsl:if test="$itemset = 'true' and name(.) != 'empty'">
514 <xsl:apply-templates select="."/>
515 </xsl:if>
516 <xsl:if test="$itemset != 'true'">
517 <xsl:apply-templates select="."/>
518 </xsl:if>
519 <xsl:if test="position() = last() and position() = $point">
520 <xsl:text> </xsl:text>
521 <span class="point">.</span>
522 </xsl:if>
523 </xsl:for-each>
524 <xsl:if test="$lookaheads">
525 <xsl:value-of select="$lookaheads"/>
526 </xsl:if>
527
528 <xsl:text>&#10;</xsl:text>
529 </xsl:template>
530
531 <xsl:template match="symbol">
532 <xsl:text> </xsl:text>
533 <xsl:choose>
534 <xsl:when test="@class = 'nonterminal'">
535 <span class="i"><xsl:value-of select="."/></span>
536 </xsl:when>
537 <xsl:otherwise>
538 <b><xsl:value-of select="."/></b>
539 </xsl:otherwise>
540 </xsl:choose>
541 </xsl:template>
542
543 <xsl:template match="empty">
544 <xsl:text> &#949;</xsl:text>
545 </xsl:template>
546
547 <xsl:template match="lookaheads">
548 <xsl:text> [</xsl:text>
549 <xsl:apply-templates select="symbol"/>
550 <xsl:text>]</xsl:text>
551 </xsl:template>
552
553 <xsl:template match="lookaheads/symbol">
554 <xsl:value-of select="."/>
555 <xsl:if test="position() != last()">
556 <xsl:text>, </xsl:text>
557 </xsl:if>
558 </xsl:template>
559
560 <xsl:template match="transition">
561 <xsl:param name="pad"/>
562 <xsl:text> </xsl:text>
563 <xsl:call-template name="rpad">
564 <xsl:with-param name="str" select="string(@symbol)"/>
565 <xsl:with-param name="pad" select="number($pad) + 2"/>
566 </xsl:call-template>
567 <xsl:choose>
568 <xsl:when test="@type = 'shift'">
569 <a>
570 <xsl:attribute name="href">
571 <xsl:value-of select="concat('#state_', @state)"/>
572 </xsl:attribute>
573 <xsl:value-of select="concat('shift, and go to state ', @state)"/>
574 </a>
575 </xsl:when>
576 <xsl:when test="@type = 'goto'">
577 <a>
578 <xsl:attribute name="href">
579 <xsl:value-of select="concat('#state_', @state)"/>
580 </xsl:attribute>
581 <xsl:value-of select="concat('go to state ', @state)"/>
582 </a>
583 </xsl:when>
584 </xsl:choose>
585 <xsl:text>&#10;</xsl:text>
586 </xsl:template>
587
588 <xsl:template match="error">
589 <xsl:param name="pad"/>
590 <xsl:text> </xsl:text>
591 <xsl:call-template name="rpad">
592 <xsl:with-param name="str" select="string(@symbol)"/>
593 <xsl:with-param name="pad" select="number($pad) + 2"/>
594 </xsl:call-template>
595 <xsl:text>error</xsl:text>
596 <xsl:text> (</xsl:text>
597 <xsl:value-of select="text()"/>
598 <xsl:text>)</xsl:text>
599 <xsl:text>&#10;</xsl:text>
600 </xsl:template>
601
602 <xsl:template match="reduction">
603 <xsl:param name="pad"/>
604 <xsl:text> </xsl:text>
605 <xsl:call-template name="rpad">
606 <xsl:with-param name="str" select="string(@symbol)"/>
607 <xsl:with-param name="pad" select="number($pad) + 2"/>
608 </xsl:call-template>
609 <xsl:if test="@enabled = 'false'">
610 <xsl:text>[</xsl:text>
611 </xsl:if>
612 <xsl:choose>
613 <xsl:when test="@rule = 'accept'">
614 <xsl:text>accept</xsl:text>
615 </xsl:when>
616 <xsl:otherwise>
617 <a>
618 <xsl:attribute name="href">
619 <xsl:value-of select="concat('#rule_', @rule)"/>
620 </xsl:attribute>
621 <xsl:value-of select="concat('reduce using rule ', @rule)"/>
622 </a>
623 <xsl:text> (</xsl:text>
624 <xsl:value-of
625 select="key('bison:ruleNumber', current()/@rule)/lhs[text()]"/>
626 <xsl:text>)</xsl:text>
627 </xsl:otherwise>
628 </xsl:choose>
629 <xsl:if test="@enabled = 'false'">
630 <xsl:text>]</xsl:text>
631 </xsl:if>
632 <xsl:text>&#10;</xsl:text>
633 </xsl:template>
634
635 <xsl:template match="solved-conflicts">
636 <xsl:if test="resolution">
637 <xsl:text>&#10;</xsl:text>
638 <xsl:apply-templates select="resolution"/>
639 </xsl:if>
640 </xsl:template>
641
642 <xsl:template match="resolution">
643 <xsl:text> Conflict between </xsl:text>
644 <a>
645 <xsl:attribute name="href">
646 <xsl:value-of select="concat('#rule_', @rule)"/>
647 </xsl:attribute>
648 <xsl:value-of select="concat('rule ',@rule)"/>
649 </a>
650 <xsl:text> and token </xsl:text>
651 <xsl:value-of select="@symbol"/>
652 <xsl:text> resolved as </xsl:text>
653 <xsl:if test="@type = 'error'">
654 <xsl:text>an </xsl:text>
655 </xsl:if>
656 <xsl:value-of select="@type"/>
657 <xsl:text> (</xsl:text>
658 <xsl:value-of select="."/>
659 <xsl:text>).&#10;</xsl:text>
660 </xsl:template>
661
662 <xsl:template name="max-width-symbol">
663 <xsl:param name="node"/>
664 <xsl:variable name="longest">
665 <xsl:for-each select="$node">
666 <xsl:sort data-type="number" select="string-length(@symbol)"
667 order="descending"/>
668 <xsl:if test="position() = 1">
669 <xsl:value-of select="string-length(@symbol)"/>
670 </xsl:if>
671 </xsl:for-each>
672 </xsl:variable>
673 <xsl:value-of select="$longest"/>
674 </xsl:template>
675
676 <xsl:template name="lpad">
677 <xsl:param name="str" select="''"/>
678 <xsl:param name="pad" select="0"/>
679 <xsl:variable name="diff" select="$pad - string-length($str)" />
680 <xsl:choose>
681 <xsl:when test="$diff &lt; 0">
682 <xsl:value-of select="$str"/>
683 </xsl:when>
684 <xsl:otherwise>
685 <xsl:call-template name="space">
686 <xsl:with-param name="repeat" select="$diff"/>
687 </xsl:call-template>
688 <xsl:value-of select="$str"/>
689 </xsl:otherwise>
690 </xsl:choose>
691 </xsl:template>
692
693 <xsl:template name="rpad">
694 <xsl:param name="str" select="''"/>
695 <xsl:param name="pad" select="0"/>
696 <xsl:variable name="diff" select="$pad - string-length($str)"/>
697 <xsl:choose>
698 <xsl:when test="$diff &lt; 0">
699 <xsl:value-of select="$str"/>
700 </xsl:when>
701 <xsl:otherwise>
702 <xsl:value-of select="$str"/>
703 <xsl:call-template name="space">
704 <xsl:with-param name="repeat" select="$diff"/>
705 </xsl:call-template>
706 </xsl:otherwise>
707 </xsl:choose>
708 </xsl:template>
709
710 <xsl:template name="space">
711 <xsl:param name="repeat">0</xsl:param>
712 <xsl:param name="fill" select="' '"/>
713 <xsl:if test="number($repeat) &gt;= 1">
714 <xsl:call-template name="space">
715 <xsl:with-param name="repeat" select="$repeat - 1"/>
716 <xsl:with-param name="fill" select="$fill"/>
717 </xsl:call-template>
718 <xsl:value-of select="$fill"/>
719 </xsl:if>
720 </xsl:template>
721
722 </xsl:stylesheet>