Add rule regarding safekeeping of special objects in Kai Monastery. Harmonise translation
[project-aon.git] / common / xsl / epub-xhtml.xsl
1 <?xml version="1.0"?>
2 <!DOCTYPE xsl:transform [
3  <!ENTITY % xhtml.characters SYSTEM "../../en/xml/htmlchar.mod">
4  %xhtml.characters;
5 ]>
6
7 <!--
8
9 Todo:
10
11 * Add blank whitespace handling to the paragraphed list template
12
13 -->
14
15 <xsl:transform version="1.0"
16   xmlns="http://www.w3.org/1999/xhtml"
17   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
18   xmlns:redirect="org.apache.xalan.lib.Redirect"
19   extension-element-prefixes="redirect">
20
21  <xsl:output method="xml"
22              encoding="UTF-8"
23              omit-xml-declaration="yes"
24              doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
25              doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
26
27  <xsl:strip-space elements="section data ol ul dl li dd footnotes footnote" />
28  <xsl:preserve-space elements="p choice puzzle deadend" />
29
30  <!-- ====================== parameters ========================== -->
31
32  <xsl:param name="use-illustrators" />
33  <xsl:param name="language"><xsl:text>en</xsl:text></xsl:param>
34  <xsl:param name="xhtml-ext"><xsl:text>.html</xsl:text></xsl:param>
35
36  <!-- ======================== Templates ========================= -->
37
38  <!-- ================= hierarchical sections ==================== -->
39
40  <xsl:template match="meta" />
41  <xsl:template match="section" />
42
43  <!-- ::::::::::::::::::: top-level section :::::::::::::::::::::: -->
44
45  <xsl:template match="/gamebook/section[@id='title']">
46   <xsl:call-template name="xhtml-wrapper">
47    <xsl:with-param name="document-type">top-level</xsl:with-param>
48    <xsl:with-param name="filename">title</xsl:with-param>
49   </xsl:call-template>
50
51   <xsl:apply-templates />
52  </xsl:template>
53
54  <xsl:template match="/gamebook/section[@id='toc']">
55   <xsl:call-template name="xhtml-wrapper">
56    <xsl:with-param name="document-type">toc</xsl:with-param>
57    <xsl:with-param name="filename">toc</xsl:with-param>
58   </xsl:call-template>
59
60   <xsl:apply-templates />
61  </xsl:template>
62
63  <!-- ::::::::::: second-level frontmatter sections :::::::::::::: -->
64
65  <xsl:template match="/gamebook/section/data/section[@class='frontmatter']">
66   <xsl:call-template name="xhtml-wrapper">
67    <xsl:with-param name="document-type">second-level-frontmatter</xsl:with-param>
68    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
69   </xsl:call-template>
70  </xsl:template>
71
72  <!-- :::::::::::: third-level front matter sections ::::::::::::: -->
73
74  <xsl:template match="/gamebook/section/data/section/data/section[@class='frontmatter']">
75   <h3><xsl:apply-templates select="meta/title[1]" /></h3>
76
77   <xsl:apply-templates />
78  </xsl:template>
79
80  <xsl:template match="/gamebook/section/data/section/data/section[@class='frontmatter-separate']">
81   <xsl:call-template name="xhtml-wrapper">
82    <xsl:with-param name="document-type">third-level-frontmatter-separate</xsl:with-param>
83    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
84   </xsl:call-template>
85  </xsl:template>
86
87  <!-- :::::::::::: fourth-level front matter sections :::::::::::: -->
88
89  <xsl:template match="/gamebook/section/data/section/data/section/data/section[@class='frontmatter']">
90   <h4><xsl:apply-templates select="meta/title[1]" /></h4>
91
92   <xsl:apply-templates />
93  </xsl:template>
94
95  <!-- ::::::::::::: fifth-level front matter sections :::::::::::: -->
96
97  <xsl:template match="/gamebook/section/data/section/data/section/data/section/data/section[@class='frontmatter']">
98   <h5><xsl:apply-templates select="meta/title[1]" /></h5>
99
100   <xsl:apply-templates />
101  </xsl:template>
102
103  <!-- ::::::::::: second-level main matter sections :::::::::::::: -->
104
105  <xsl:template match="/gamebook/section/data/section[@class='mainmatter']">
106   <xsl:call-template name="xhtml-wrapper">
107    <xsl:with-param name="document-type">second-level-mainmatter</xsl:with-param>
108    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
109   </xsl:call-template>
110  </xsl:template>
111
112  <!-- :::::::::::: third-level main matter sections ::::::::::::: -->
113
114  <xsl:template match="/gamebook/section/data/section/data/section[@class='mainmatter']">
115   <h3><xsl:apply-templates select="meta/title[1]" /></h3>
116
117   <xsl:apply-templates />
118  </xsl:template>
119
120  <xsl:template match="/gamebook/section/data/section/data/section[@class='mainmatter-separate']">
121   <xsl:call-template name="xhtml-wrapper">
122    <xsl:with-param name="document-type">third-level-mainmatter-separate</xsl:with-param>
123    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
124   </xsl:call-template>
125  </xsl:template>
126
127  <!-- :::::::::::: fourth-level main matter sections :::::::::::: -->
128
129  <xsl:template match="/gamebook/section/data/section/data/section/data/section[@class='mainmatter']">
130   <h4><xsl:apply-templates select="meta/title[1]" /></h4>
131
132   <xsl:apply-templates />
133  </xsl:template>
134
135  <!-- ::::::::::::: fifth-level main matter sections :::::::::::: -->
136
137  <xsl:template match="/gamebook/section/data/section/data/section/data/section/data/section[@class='mainmatter']">
138   <h5><xsl:apply-templates select="meta/title[1]" /></h5>
139
140   <xsl:apply-templates />
141  </xsl:template>
142
143  <!-- :::::::::::: second-level glossary sections ::::::::::::: -->
144
145  <xsl:template match="/gamebook/section/data/section[@class='glossary']">
146   <xsl:call-template name="xhtml-wrapper">
147    <xsl:with-param name="document-type">second-level-glossary</xsl:with-param>
148    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
149    <xsl:with-param name="glossary-id-prefix">topics</xsl:with-param>
150   </xsl:call-template>
151  </xsl:template>
152
153  <!-- :::::::::::: third-level glossary sections ::::::::::::: -->
154  <!-- glossary sections should be enclosed in a second level glossary section -->
155
156  <xsl:template match="/gamebook/section/data/section/data/section[@class='glossary']">
157   <h3><xsl:apply-templates select="meta/title[1]" /></h3>
158
159   <xsl:apply-templates />
160  </xsl:template>
161
162  <xsl:template match="/gamebook/section/data/section/data/section[@class='glossary-separate']">
163   <xsl:call-template name="xhtml-wrapper">
164    <xsl:with-param name="document-type">third-level-glossary-separate</xsl:with-param>
165    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
166    <xsl:with-param name="glossary-id-prefix">topics</xsl:with-param>
167   </xsl:call-template>
168  </xsl:template>
169
170  <!-- :::::::::::::::::: numbered sections ::::::::::::::::::::::: -->
171
172  <xsl:template match="/gamebook/section/data/section[@class='numbered']">
173   <xsl:call-template name="xhtml-wrapper">
174    <xsl:with-param name="document-type">second-level-numbered</xsl:with-param>
175    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
176   </xsl:call-template>
177
178   <xsl:apply-templates />
179  </xsl:template>
180
181  <xsl:template match="/gamebook/section/data/section/data/section[@class='numbered']">
182   <xsl:call-template name="xhtml-wrapper">
183    <xsl:with-param name="document-type">third-level-numbered</xsl:with-param>
184    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
185   </xsl:call-template>
186  </xsl:template>
187
188  <!-- :::::::::::: second-level backmatter sections :::::::::::::: -->
189
190  <xsl:template match="/gamebook/section/data/section[@class='backmatter']">
191   <xsl:call-template name="xhtml-wrapper">
192    <xsl:with-param name="document-type">second-level-backmatter</xsl:with-param>
193    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
194   </xsl:call-template>
195  </xsl:template>
196
197  <!-- ::::::::::::: third-level back matter sections ::::::::::::: -->
198
199  <xsl:template match="/gamebook/section/data/section/data/section[@class='backmatter']">
200   <h3><xsl:apply-templates select="meta/title[1]" /></h3>
201
202   <xsl:apply-templates />
203  </xsl:template>
204
205  <!-- ::::::::::::: fourth-level back matter sections ::::::::::::: -->
206
207  <xsl:template match="/gamebook/section/data/section/data/section/data/section[@class='backmatter']">
208   <h4><xsl:apply-templates select="meta/title[1]" /></h4>
209
210   <xsl:apply-templates />
211  </xsl:template>
212
213  <!-- ::::::::::::::::::::: map template ::::::::::::::::::::::::: -->
214
215  <xsl:template match="id( 'map' )">
216   <xsl:call-template name="xhtml-wrapper">
217    <xsl:with-param name="document-type">map</xsl:with-param>
218    <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
219   </xsl:call-template>
220  </xsl:template>
221
222  <!-- ::::::::::::::::::::: footnotes template ::::::::::::::::::::::::: -->
223
224  <xsl:template match="id( 'footnotz' )">
225   <xsl:choose>
226    <!-- Backwards compatibility measure - if there is data content, use that, otherwise generate footnotes list -->
227    <xsl:when test="count( data/p ) = 0">
228     <xsl:call-template name="xhtml-wrapper">
229      <xsl:with-param name="document-type">footnotz</xsl:with-param>
230      <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
231     </xsl:call-template>
232    </xsl:when>
233    <xsl:otherwise>
234     <xsl:call-template name="xhtml-wrapper">
235      <xsl:with-param name="document-type">second-level-backmatter</xsl:with-param>
236      <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
237     </xsl:call-template>
238    </xsl:otherwise>
239   </xsl:choose>
240   <xsl:apply-templates />
241  </xsl:template>
242
243  <!-- ==================== block elements ======================== -->
244
245  <xsl:template match="p">
246   <p><xsl:apply-templates /></p>
247
248  </xsl:template>
249
250  <xsl:template match="p[@class='dedication']">
251   <p class="dedication"><xsl:apply-templates /></p>
252
253  </xsl:template>
254
255  <xsl:template match="dl[@class='paragraphed']/dd/node() | ol[@class='paragraphed']/li/node() | ul[@class='paragraphed']/li/node()">
256   <xsl:choose>
257    <xsl:when test="self::p">
258     <xsl:apply-templates /><br /><br />
259    </xsl:when>
260    <xsl:when test="self::dl">
261     <dl>
262      <xsl:apply-templates />
263     </dl><br /><br />
264    </xsl:when>
265    <xsl:when test="self::ol">
266     <ol>
267      <xsl:apply-templates />
268     </ol><br /><br />
269    </xsl:when>
270    <xsl:when test="self::ul">
271     <ul>
272      <xsl:if test="self::*[@class='unbulleted']"><xsl:attribute name="class"><xsl:text>unbulleted</xsl:text></xsl:attribute></xsl:if>
273
274      <xsl:apply-templates />
275     </ul><br /><br />
276    </xsl:when>
277    <xsl:when test="self::blockquote">
278     <blockquote>
279      <xsl:apply-templates />
280     </blockquote>
281    </xsl:when>
282    <xsl:when test="self::poetry">
283     <blockquote class="poetry"><p>
284      <xsl:apply-templates />
285     </p></blockquote>
286    </xsl:when>
287    <xsl:when test="self::illustration">
288     <!-- Backwards compatibility code -->
289     <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
290     <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
291     <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
292
293     <xsl:if test="instance[@class='html'] and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )">
294      <div class="illustration">
295
296       <xsl:call-template name="illustration-noframe">
297        <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width" /></xsl:with-param>
298        <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height" /></xsl:with-param>
299        <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
300       </xsl:call-template>
301      </div>
302     </xsl:if>
303    </xsl:when>
304    <xsl:when test="self::illref">
305     <xsl:if test="@class='html'">
306      <xsl:for-each select="id( @idref )">
307       <xsl:apply-templates select="." />
308      </xsl:for-each>
309     </xsl:if>
310    </xsl:when>
311    <xsl:otherwise>
312     <xsl:text>[error: paragraphed list template]</xsl:text>
313     <xsl:message><xsl:text>error: paragraphed list template</xsl:text></xsl:message>
314    </xsl:otherwise>
315   </xsl:choose>
316  </xsl:template>
317
318  <xsl:template match="ol">
319   <ol>
320    <xsl:if test="@start">
321     <xsl:call-template name="ol-start-for-loop">
322      <xsl:with-param name="count" select="@start"/>
323     </xsl:call-template>
324    </xsl:if>
325
326    <xsl:apply-templates />
327   </ol>
328  </xsl:template>
329
330  <xsl:template name="ol-start-for-loop">
331   <xsl:param name="i" select="0"/>
332   <xsl:param name="count"/>
333
334   <xsl:if test="number($i) &lt; number($count)">
335    <li style="visibility:hidden;height:0">&nbsp;</li>
336    <xsl:call-template name="ol-start-for-loop">
337     <xsl:with-param name="i" select="number($i) + 1"/>
338     <xsl:with-param name="count" select="$count"/>
339    </xsl:call-template>
340   </xsl:if>
341  </xsl:template>
342
343  <xsl:template match="ul">
344   <ul>
345    <xsl:if test="self::*[@class='unbulleted']"><xsl:attribute name="class"><xsl:text>unbulleted</xsl:text></xsl:attribute></xsl:if>
346
347    <xsl:apply-templates />
348   </ul>
349  </xsl:template>
350
351  <xsl:template match="dl">
352   <dl>
353    <xsl:apply-templates />
354   </dl>
355  </xsl:template>
356
357  <xsl:template match="dt">
358   <dt><xsl:apply-templates /></dt>
359
360  </xsl:template>
361
362  <xsl:template match="dd">
363   <dd><xsl:apply-templates /></dd>
364
365  </xsl:template>
366
367  <xsl:template match="li">
368   <li>
369    <xsl:if test="@value"><xsl:attribute name="value"><xsl:value-of select="@value" /></xsl:attribute></xsl:if>
370    <xsl:apply-templates />
371   </li>
372
373  </xsl:template>
374
375  <xsl:template match="table">
376   <table align="center" border="1" cellspacing="0" cellpadding="2">
377    <xsl:if test="@summary"><xsl:attribute name="summary"><xsl:value-of select="@summary" /></xsl:attribute></xsl:if>
378    <xsl:apply-templates />
379   </table>
380
381  </xsl:template>
382
383  <xsl:template match="caption">
384   <caption>
385    <xsl:apply-templates />
386   </caption>
387  </xsl:template>
388
389  <xsl:template match="colgroup[@scope]">
390   <colgroup>
391    <xsl:attribute name="scope"><xsl:value-of select="@scope" /></xsl:attribute>
392   </colgroup>
393  </xsl:template>
394
395  <xsl:template match="thead">
396   <thead>
397    <xsl:apply-templates />
398   </thead>
399  </xsl:template>
400
401  <xsl:template match="tfoot">
402   <tfoot>
403    <xsl:apply-templates />
404   </tfoot>
405  </xsl:template>
406
407  <xsl:template match="tbody">
408   <tbody>
409    <xsl:apply-templates />
410   </tbody>
411  </xsl:template>
412
413  <xsl:template match="tr">
414   <tr>
415    <xsl:apply-templates />
416   </tr>
417  </xsl:template>
418
419  <xsl:template match="th">
420   <th>
421    <xsl:if test="@align"><xsl:attribute name="align"><xsl:value-of select="@align" /></xsl:attribute></xsl:if>
422    <xsl:if test="@valign"><xsl:attribute name="valign"><xsl:value-of select="@valign" /></xsl:attribute></xsl:if>
423    <xsl:if test="@char"><xsl:attribute name="char"><xsl:value-of select="@char" /></xsl:attribute></xsl:if>
424    <xsl:if test="@rowspan"><xsl:attribute name="rowspan"><xsl:value-of select="@rowspan" /></xsl:attribute></xsl:if>
425    <xsl:if test="@colspan"><xsl:attribute name="colspan"><xsl:value-of select="@colspan" /></xsl:attribute></xsl:if>
426    <xsl:if test="@axis"><xsl:attribute name="axis"><xsl:value-of select="@axis" /></xsl:attribute></xsl:if>
427    <xsl:if test="@scope"><xsl:attribute name="scope"><xsl:value-of select="@scope" /></xsl:attribute></xsl:if>
428    <xsl:apply-templates />
429   </th>
430  </xsl:template>
431
432  <xsl:template match="td">
433   <td>
434    <xsl:if test="@align"><xsl:attribute name="align"><xsl:value-of select="@align" /></xsl:attribute></xsl:if>
435    <xsl:if test="@valign"><xsl:attribute name="valign"><xsl:value-of select="@valign" /></xsl:attribute></xsl:if>
436    <xsl:if test="@char"><xsl:attribute name="char"><xsl:value-of select="@char" /></xsl:attribute></xsl:if>
437    <xsl:if test="@rowspan"><xsl:attribute name="rowspan"><xsl:value-of select="@rowspan" /></xsl:attribute></xsl:if>
438    <xsl:if test="@colspan"><xsl:attribute name="colspan"><xsl:value-of select="@colspan" /></xsl:attribute></xsl:if>
439    <xsl:if test="@axis"><xsl:attribute name="axis"><xsl:value-of select="@axis" /></xsl:attribute></xsl:if>
440    <xsl:if test="@scope"><xsl:attribute name="scope"><xsl:value-of select="@scope" /></xsl:attribute></xsl:if>
441    <xsl:apply-templates />
442   </td>
443  </xsl:template>
444
445  <xsl:template match="combat">
446   <p class="combat">
447    <xsl:apply-templates select="enemy" />
448    <xsl:text>: </xsl:text>
449    <xsl:choose>
450     <xsl:when test="enemy-attribute[@class='combatskill']">
451      <span class="smallcaps">
452       <xsl:choose>
453        <xsl:when test="$language='es'">
454         <xsl:text>DESTREZA&nbsp;EN&nbsp;EL&nbsp;COMBATE</xsl:text>
455        </xsl:when>
456        <xsl:otherwise>
457         <xsl:text>COMBAT&nbsp;SKILL</xsl:text>
458        </xsl:otherwise>
459       </xsl:choose>
460      </span>
461      <xsl:text>&nbsp;</xsl:text>
462      <xsl:value-of select="enemy-attribute[@class='combatskill']" />
463     </xsl:when>
464     <xsl:when test="enemy-attribute[@class='closecombatskill']">
465      <span class="smallcaps">
466       <xsl:choose>
467        <xsl:when test="$language='es'">
468         <xsl:text>CLOSE&nbsp;COMBAT&nbsp;SKILL</xsl:text>
469        </xsl:when>
470        <xsl:otherwise>
471         <xsl:text>CLOSE&nbsp;COMBAT&nbsp;SKILL</xsl:text>
472        </xsl:otherwise>
473       </xsl:choose>
474      </span>
475      <xsl:text>&nbsp;</xsl:text>
476      <xsl:value-of select="enemy-attribute[@class='closecombatskill']" />
477     </xsl:when>
478    </xsl:choose>
479    <xsl:text> &nbsp;&nbsp;</xsl:text>
480    <span class="smallcaps">
481      <xsl:choose>
482       <xsl:when test="$language='es'">
483        <xsl:text>RESISTENCIA</xsl:text>
484       </xsl:when>
485       <xsl:otherwise>
486        <xsl:text>ENDURANCE</xsl:text>
487      </xsl:otherwise>
488     </xsl:choose>
489    </span>
490    <xsl:choose>
491     <xsl:when test="enemy-attribute[@class='target']">
492      <xsl:choose>
493       <xsl:when test="$language='es'">
494        <xsl:text> (o </xsl:text><span class="smallcaps">BLANCOS</span><xsl:text>)</xsl:text>
495       </xsl:when>
496       <xsl:otherwise>
497        <xsl:text> (</xsl:text><span class="smallcaps">TARGET</span><xsl:text> points)</xsl:text>
498       </xsl:otherwise>
499      </xsl:choose>
500      <xsl:text>&nbsp;</xsl:text>
501      <xsl:value-of select="enemy-attribute[@class='target']" />
502     </xsl:when>
503     <xsl:when test="enemy-attribute[@class='resistance']">
504      <xsl:choose>
505       <xsl:when test="$language='es'"></xsl:when>
506       <xsl:otherwise>
507        <xsl:text> (</xsl:text><span class="smallcaps">RESISTANCE</span><xsl:text> points)</xsl:text>
508       </xsl:otherwise>
509      </xsl:choose>
510      <xsl:text>&nbsp;</xsl:text>
511      <xsl:value-of select="enemy-attribute[@class='resistance']" />
512     </xsl:when>
513     <xsl:otherwise>
514      <xsl:text>&nbsp;</xsl:text>
515      <xsl:value-of select="enemy-attribute[@class='endurance']" />
516     </xsl:otherwise>
517    </xsl:choose>
518   </p>
519
520  </xsl:template>
521
522  <xsl:template match="choice">
523   <xsl:variable name="link">
524    <xsl:value-of select="@idref" />
525   </xsl:variable>
526
527   <p class="choice">
528    <xsl:for-each select="* | text()">
529     <xsl:choose>
530      <xsl:when test="self::link-text">
531       <a href="{$link}{$xhtml-ext}">
532        <xsl:apply-templates />
533       </a>
534      </xsl:when>
535      <xsl:otherwise>
536       <xsl:apply-templates select="." />
537      </xsl:otherwise>
538     </xsl:choose>
539    </xsl:for-each>
540   </p>
541
542  </xsl:template>
543
544  <xsl:template match="puzzle">
545   <p class="puzzle">
546    <xsl:apply-templates />
547   </p>
548  </xsl:template>
549  
550  <xsl:template match="deadend">
551   <p class="deadend">
552    <xsl:apply-templates />
553   </p>
554  </xsl:template>
555
556  <xsl:template match="data/signpost">
557   <div class="signpost">
558    <xsl:apply-templates />
559   </div>
560  </xsl:template>
561
562  <xsl:template match="signpost">
563   <span class="signpost"><xsl:apply-templates /></span>
564  </xsl:template>
565
566  <xsl:template match="blockquote">
567   <blockquote>
568    <xsl:apply-templates />
569   </blockquote>
570  </xsl:template>
571
572  <xsl:template match="poetry">
573   <blockquote class="poetry">
574    <xsl:apply-templates />
575   </blockquote>
576  </xsl:template>
577
578  <xsl:template match="illref">
579   <!-- It is important that the class is not checked right in the template - that would make this template match with higher priority, which will turn a few things upside down --> 
580   <xsl:if test="@class='html'">
581    <xsl:for-each select="id( @idref )">
582     <!-- When backwards compatibility can be dropped, most of (all?) the <illustration> processing can happen here -->
583     <xsl:apply-templates select="." />
584    </xsl:for-each>
585   </xsl:if>
586  </xsl:template>
587
588  <xsl:template match="illustrations">
589   <ul class="unbulleted">
590    <xsl:for-each select="illustration[contains( $use-illustrators, concat( ':', meta/creator, ':' ) )] | illgroup">
591     <xsl:choose>
592      <xsl:when test="self::illustration and @class='float'">
593       <!-- List item with illustration name -->
594       <li>
595        <xsl:choose>
596         <xsl:when test="$language='es'">
597          <xsl:text>Ilustraci&oacute;n </xsl:text>
598         </xsl:when>
599         <xsl:otherwise>
600          <xsl:text>Illustration </xsl:text>
601         </xsl:otherwise>
602        </xsl:choose>
603        <xsl:number count="illustration[@class='float' and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )]" from="/" level="any" format="I" />
604        <!-- List the sections that the illustration appears in -->
605        <xsl:text> (</xsl:text>
606        <xsl:for-each select="//illref[@class='html' and @idref=current()/@id]">
607         <xsl:call-template name="section-title-link" />
608         <xsl:if test="position()!=last()">
609          <xsl:text>, </xsl:text>        
610         </xsl:if>
611        </xsl:for-each>
612        <xsl:text>)</xsl:text>
613       </li>
614      </xsl:when>
615
616      <xsl:when test="self::illustration"> <!-- inline and map -->
617       <!-- List the sections that the illustration appears in -->     
618       <li>
619        <!-- TODO: fix this so that sections that do not represent separate XHTML files are not linked to? -->
620        <xsl:for-each select="//illref[@class='html' and @idref=current()/@id]">
621         <xsl:call-template name="section-title-link" />
622         <xsl:if test="position()!=last()">
623          <xsl:text>, </xsl:text>     
624         </xsl:if>
625        </xsl:for-each>
626       </li>
627      </xsl:when>
628
629      <xsl:when test="self::illgroup and @class!='hidden'">
630       <!-- Check if the group contains any illustrations being used, before creating the list item -->
631        <xsl:if test="count( illustration[contains( $use-illustrators, concat( ':', meta/creator, ':' ) )] ) != 0">
632         <li>
633          <a>
634           <xsl:attribute name="href"><xsl:value-of select="@idref" /><xsl:value-of select="$xhtml-ext"/></xsl:attribute>
635           <xsl:value-of select="id(@idref)/meta/title[1]" />
636          </a>
637         </li>
638        </xsl:if>
639      </xsl:when>
640     </xsl:choose>
641    </xsl:for-each>
642   </ul>
643  </xsl:template>
644
645  <xsl:template match="illustration">
646   <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
647   <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
648   <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
649
650   <xsl:if test="instance[@class='html'] and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )">
651    <xsl:choose>
652     <xsl:when test="@class='float'">
653      <div class="illustration">
654       <xsl:call-template name="illustration-noframe">
655        <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width" /></xsl:with-param>
656        <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height" /></xsl:with-param>
657        <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
658        <xsl:with-param name="illustration-href">
659         <xsl:text>ill</xsl:text><xsl:number count="illustration[@class='float' and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )]" from="/" level="any" format="1" /><xsl:value-of select="$xhtml-ext"/>
660        </xsl:with-param>
661       </xsl:call-template>
662      </div>
663     </xsl:when>
664
665     <xsl:when test="@class='accent'" />
666
667     <xsl:otherwise>
668      <div class="illustration">
669       <xsl:call-template name="illustration-noframe">
670        <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width" /></xsl:with-param>
671        <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height" /></xsl:with-param>
672        <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
673       </xsl:call-template>
674      </div>
675     </xsl:otherwise>
676    </xsl:choose>
677   </xsl:if>
678  </xsl:template>
679
680  <xsl:template match="instance" />
681
682  <xsl:template match="footnotes" />
683
684  <xsl:template match="footnote" />
685
686  <xsl:template match="hr">
687   <hr />
688
689  </xsl:template>
690
691  <xsl:template match="choose">
692   <xsl:choose>
693    <xsl:when test="@test='has-numbered-section-list'">
694     <xsl:choose>
695      <xsl:when test="when[@value='true']">
696       <xsl:apply-templates select="when[@value='true'][1]/node()" />
697      </xsl:when>
698      <xsl:when test="otherwise">
699       <!-- this should only be applied when there is no option for "true" -->
700       <xsl:apply-templates select="otherwise/node()" />
701      </xsl:when>
702     </xsl:choose>
703    </xsl:when>
704    <xsl:otherwise>
705     <xsl:message>
706      <xsl:text>choose: unrecognized test "</xsl:text>
707      <xsl:value-of select="@test" />
708      <xsl:text>" - element ignored.</xsl:text>
709     </xsl:message>
710    </xsl:otherwise>
711   </xsl:choose>
712  </xsl:template>
713
714  <!-- ==================== inline elements ======================= -->
715
716  <xsl:template match="a">
717   <xsl:choose>
718    <xsl:when test="@href">
719     <a>
720      <xsl:attribute name="href"><xsl:value-of select="@href" /></xsl:attribute>
721      <xsl:apply-templates />
722     </a>
723    </xsl:when>
724    <xsl:otherwise>
725     <a>
726      <xsl:if test="@idref">
727       <xsl:variable name="my-idref" select="@idref" />
728       <xsl:attribute name="href">
729        <xsl:choose>
730         <!-- The order of these tests is deliberate. They are ordered roughly from most to least specific. -->
731         <xsl:when test="/gamebook/section[@id=$my-idref] | /gamebook/section/data/section[@id=$my-idref]">
732          <xsl:value-of select="$my-idref" /><xsl:value-of select="$xhtml-ext"/>
733         </xsl:when>
734         <xsl:when test="/gamebook/section/data/section/data/section[@class='frontmatter-separate' and @id=$my-idref]">
735          <xsl:value-of select="$my-idref" /><xsl:value-of select="$xhtml-ext"/>
736         </xsl:when>
737         <xsl:when test="/gamebook/section/data/section/data/section[@class='mainmatter-separate' and @id=$my-idref]">
738          <xsl:value-of select="$my-idref" /><xsl:value-of select="$xhtml-ext"/>
739         </xsl:when>
740         <xsl:when test="/gamebook/section/data/section/data/section[@class='numbered' and @id=$my-idref]">
741          <xsl:value-of select="$my-idref" /><xsl:value-of select="$xhtml-ext"/>
742         </xsl:when>
743         <xsl:when test="/gamebook/section/data/section/data/section[@class='glossary-separate' and @id=$my-idref]">
744          <xsl:value-of select="$my-idref" /><xsl:value-of select="$xhtml-ext"/>
745         </xsl:when>
746         <xsl:when test="/gamebook/section/data/section/data/section[@class='frontmatter-separate' and descendant::*[@id=$my-idref]]">
747          <xsl:value-of select="/gamebook/section/data/section/data/section[@class='frontmatter-separate' and descendant::*[@id=$my-idref]]/@id" /><xsl:value-of select="$xhtml-ext"/>
748         </xsl:when>
749         <xsl:when test="/gamebook/section/data/section/data/section[@class='mainmatter-separate' and descendant::*[@id=$my-idref]]">
750          <xsl:value-of select="/gamebook/section/data/section/data/section[@class='mainmatter-separate' and descendant::*[@id=$my-idref]]/@id" /><xsl:value-of select="$xhtml-ext"/>
751         </xsl:when>
752         <xsl:when test="/gamebook/section/data/section/data/section[@class='glossary-separate' and descendant::*[@id=$my-idref]]">
753          <xsl:value-of select="/gamebook/section/data/section/data/section[@class='glossary-separate' and descendant::*[@id=$my-idref]]/@id" /><xsl:value-of select="$xhtml-ext"/>
754         </xsl:when>
755         <xsl:when test="/gamebook/section/data/section[descendant::*[@id=$my-idref]]">
756          <xsl:value-of select="/gamebook/section/data/section[descendant::*[@id=$my-idref]]/@id" /><xsl:value-of select="$xhtml-ext"/>
757         </xsl:when>
758         <xsl:otherwise>
759          <xsl:text>[error: a template]</xsl:text>
760          <xsl:message><xsl:text>error: a template</xsl:text></xsl:message>
761         </xsl:otherwise>
762        </xsl:choose>
763       </xsl:attribute>
764      </xsl:if>
765      <xsl:apply-templates />
766     </a>
767    </xsl:otherwise>
768   </xsl:choose>
769  </xsl:template>
770
771  <!-- This template is obsolete, the "footref" element should be used instead -->
772  <xsl:template match="a[@class='footnote']">
773   <!-- <xsl:message><xsl:text>WARNING: Obsolete &lt;a idref='...' class='footnote' /&gt; usage</xsl:text></xsl:message> -->
774   <xsl:apply-templates />
775   <sup>
776    <xsl:number count="a[@class='footnote']" from="/" level="any" format="1" />
777   </sup>
778  </xsl:template>
779
780  <!-- TODO: can this be made more uniform with illrefs? -->
781  <xsl:template match="a[@class='accent-illustration']">
782   <xsl:for-each select="id( @idref )">
783    <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
784    <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
785    <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
786    <xsl:if test="instance[@class='html'] and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )">
787     <img src="{$illustration-src}" class="accent" width="{$illustration-width}" height="{$illustration-height}" alt="" />
788    </xsl:if>
789   </xsl:for-each>
790  </xsl:template>
791
792  <!-- TODO: references to external books will not work in Ebooks -->
793  <!--       should they be skipped or modified to point to the online book? -->
794  <xsl:template match="bookref">
795  <!-- <a> -->
796  <!--  <xsl:attribute name="href"> -->
797  <!--   <xsl:variable name="my-section"> -->
798  <!--    <xsl:choose> -->
799  <!--     <xsl:when test="@section"> -->
800  <!--      <xsl:value-of select="@section" /> -->
801  <!--     </xsl:when> -->
802  <!--     <xsl:otherwise> -->
803  <!--      <xsl:text>title</xsl:text> -->
804  <!--     </xsl:otherwise> -->
805  <!--    </xsl:choose> -->
806  <!--   </xsl:variable> -->
807  <!--   <xsl:variable name="my-series"> -->
808      <!-- If series is specified, go one directory back and then to series. Otherwise, add nothing. -->
809  <!--    <xsl:choose> -->
810  <!--     <xsl:when test="@series"> -->
811  <!--      <xsl:text>/../</xsl:text><xsl:value-of select="@series" /> -->
812  <!--     </xsl:when> -->
813  <!--     <xsl:otherwise> -->
814  <!--      <xsl:text></xsl:text> -->
815  <!--     </xsl:otherwise> -->
816  <!--    </xsl:choose> -->
817  <!--   </xsl:variable> -->
818  <!--   <xsl:text>..</xsl:text><xsl:value-of select="$my-series" /><xsl:text>/</xsl:text><xsl:value-of select="@book" /><xsl:text>/</xsl:text><xsl:value-of select="$my-section" /><xsl:value-of select="$xhtml-ext"/> -->
819  <!--  </xsl:attribute> -->
820  <!--  <xsl:if test="@id"><xsl:attribute name="name"><xsl:value-of select="@id" /></xsl:attribute></xsl:if> -->
821    <xsl:apply-templates />
822  <!-- </a> -->
823  </xsl:template>
824
825  <xsl:template match="footref">
826   <xsl:apply-templates />
827   <sup>
828    <xsl:number count="footref" from="/" level="any" format="1" />
829   </sup>
830  </xsl:template>
831
832  <xsl:template match="em">
833   <em><xsl:apply-templates /></em>
834  </xsl:template>
835
836  <xsl:template match="strong">
837   <strong><xsl:apply-templates /></strong>
838  </xsl:template>
839
840  <xsl:template match="thought">
841   <span class="thought"><xsl:apply-templates /></span>
842  </xsl:template>
843
844  <xsl:template match="onomatopoeia">
845   <span class="onomatopoeia"><xsl:apply-templates /></span>
846  </xsl:template>
847
848  <xsl:template match="spell">
849   <span class="spell"><xsl:apply-templates /></span>
850  </xsl:template>
851
852  <xsl:template match="item">
853   <xsl:apply-templates />
854  </xsl:template>
855
856  <xsl:template match="foreign">
857   <span class="foreign">
858    <xsl:attribute name="xml:lang">
859     <xsl:value-of select="@xml:lang"/>
860    </xsl:attribute>
861    <xsl:apply-templates />
862   </span>
863  </xsl:template>
864
865  <xsl:template match="quote">
866   <xsl:text>&#8216;</xsl:text>
867    <xsl:apply-templates />
868   <xsl:if test="not(self::*[@class='open-ended'])"><xsl:text>&#8217;</xsl:text></xsl:if>
869  </xsl:template>
870
871  <xsl:template match="quote//quote">
872   <xsl:text>&#8220;</xsl:text>
873    <xsl:apply-templates />
874   <xsl:if test="not(self::*[@class='open-ended'])"><xsl:text>&#8221;</xsl:text></xsl:if>
875  </xsl:template>
876
877  <xsl:template match="cite">
878   <cite><xsl:apply-templates /></cite>
879  </xsl:template>
880
881  <xsl:template match="code">
882   <tt><xsl:apply-templates /></tt>
883  </xsl:template>
884
885  <xsl:template match="line">
886   <xsl:apply-templates />
887   <xsl:if test="position( ) != last( )"><br /></xsl:if>
888  </xsl:template>
889
890  <xsl:template match="br">
891   <br />
892  </xsl:template>
893
894  <xsl:template match="typ[@class='attribute']">
895   <span class="smallcaps"><xsl:apply-templates /></span>
896  </xsl:template>
897
898  <!-- ==================== character elements ==================== -->
899  <!--
900
901 These templates define the mapping between the character elements used in
902 the Project Aon instances of Gamebook XML and the Unicode characters.
903
904 Portions Copyright International Organization for Standardization 1986 
905 Permission to copy in any form is granted for use with conforming SGML 
906 systems and applications as defined in ISO 8879, provided this notice 
907 is included in all copies.
908
909 -->
910
911  <xsl:template match="ch.apos"><xsl:text>&#39;</xsl:text></xsl:template><!-- apostrophe = single quotation mark -->
912  <xsl:template match="ch.nbsp"><xsl:text>&#160;</xsl:text></xsl:template><!-- no-break space = non-breaking space, U+00A0 ISOnum -->
913  <xsl:template match="ch.iexcl"><xsl:text>&#161;</xsl:text></xsl:template><!-- inverted exclamation mark, U+00A1 ISOnum -->
914  <xsl:template match="ch.cent"><xsl:text>&#162;</xsl:text></xsl:template><!-- cent sign, U+00A2 ISOnum -->
915  <xsl:template match="ch.pound"><xsl:text>&#163;</xsl:text></xsl:template><!-- pound sign, U+00A3 ISOnum -->
916  <xsl:template match="ch.curren"><xsl:text>&#164;</xsl:text></xsl:template><!-- currency sign, U+00A4 ISOnum -->
917  <xsl:template match="ch.yen"><xsl:text>&#165;</xsl:text></xsl:template><!-- yen sign = yuan sign, U+00A5 ISOnum -->
918  <xsl:template match="ch.brvbar"><xsl:text>&#166;</xsl:text></xsl:template><!-- broken bar = broken vertical bar, U+00A6 ISOnum -->
919  <xsl:template match="ch.sect"><xsl:text>&#167;</xsl:text></xsl:template><!-- section sign, U+00A7 ISOnum -->
920  <xsl:template match="ch.uml"><xsl:text>&#168;</xsl:text></xsl:template><!-- diaeresis = spacing diaeresis, U+00A8 ISOdia -->
921  <xsl:template match="ch.copy"><xsl:text>&#169;</xsl:text></xsl:template><!-- copyright sign, U+00A9 ISOnum -->
922  <xsl:template match="ch.ordf"><xsl:text>&#170;</xsl:text></xsl:template><!-- feminine ordinal indicator, U+00AA ISOnum -->
923  <xsl:template match="ch.laquo"><xsl:text>&#171;</xsl:text></xsl:template><!-- left-pointing double angle quotation mark = left pointing guillemet, U+00AB ISOnum -->
924  <xsl:template match="ch.not"><xsl:text>&#172;</xsl:text></xsl:template><!-- not sign, U+00AC ISOnum -->
925  <xsl:template match="ch.shy"><xsl:text>&#173;</xsl:text></xsl:template><!-- soft hyphen = discretionary hyphen, U+00AD ISOnum -->
926  <xsl:template match="ch.reg"><xsl:text>&#174;</xsl:text></xsl:template><!-- registered sign = registered trade mark sign, U+00AE ISOnum -->
927  <xsl:template match="ch.macr"><xsl:text>&#175;</xsl:text></xsl:template><!-- macron = spacing macron = overline = APL overbar, U+00AF ISOdia -->
928  <xsl:template match="ch.deg"><xsl:text>&#176;</xsl:text></xsl:template><!-- degree sign, U+00B0 ISOnum -->
929  <xsl:template match="ch.plusmn"><xsl:text>&#177;</xsl:text></xsl:template><!-- plus-minus sign = plus-or-minus sign, U+00B1 ISOnum -->
930  <xsl:template match="ch.sup2"><xsl:text>&#178;</xsl:text></xsl:template><!-- superscript two = superscript digit two = squared, U+00B2 ISOnum -->
931  <xsl:template match="ch.sup3"><xsl:text>&#179;</xsl:text></xsl:template><!-- superscript three = superscript digit three = cubed, U+00B3 ISOnum -->
932  <xsl:template match="ch.acute"><xsl:text>&#180;</xsl:text></xsl:template><!-- acute accent = spacing acute, U+00B4 ISOdia -->
933  <xsl:template match="ch.micro"><xsl:text>&#181;</xsl:text></xsl:template><!-- micro sign, U+00B5 ISOnum -->
934  <xsl:template match="ch.para"><xsl:text>&#182;</xsl:text></xsl:template><!-- pilcrow sign  = paragraph sign, U+00B6 ISOnum -->
935  <xsl:template match="ch.middot"><xsl:text>&#183;</xsl:text></xsl:template><!-- middle dot = Georgian comma = Greek middle dot, U+00B7 ISOnum -->
936  <xsl:template match="ch.cedil"><xsl:text>&#184;</xsl:text></xsl:template><!-- cedilla = spacing cedilla, U+00B8 ISOdia -->
937  <xsl:template match="ch.sup1"><xsl:text>&#185;</xsl:text></xsl:template><!-- superscript one = superscript digit one, U+00B9 ISOnum -->
938  <xsl:template match="ch.ordm"><xsl:text>&#186;</xsl:text></xsl:template><!-- masculine ordinal indicator, U+00BA ISOnum -->
939  <xsl:template match="ch.raquo"><xsl:text>&#187;</xsl:text></xsl:template><!-- right-pointing double angle quotation mark = right pointing guillemet, U+00BB ISOnum -->
940  <xsl:template match="ch.frac14"><xsl:text>&#188;</xsl:text></xsl:template><!-- vulgar fraction one quarter = fraction one quarter, U+00BC ISOnum -->
941  <xsl:template match="ch.frac12"><xsl:text>&#189;</xsl:text></xsl:template><!-- vulgar fraction one half = fraction one half, U+00BD ISOnum -->
942  <xsl:template match="ch.frac34"><xsl:text>&#190;</xsl:text></xsl:template><!-- vulgar fraction three quarters = fraction three quarters, U+00BE ISOnum -->
943  <xsl:template match="ch.iquest"><xsl:text>&#191;</xsl:text></xsl:template><!-- inverted question mark = turned question mark, U+00BF ISOnum -->
944  <xsl:template match="ch.Agrave"><xsl:text>&#192;</xsl:text></xsl:template><!-- latin capital letter A with grave = latin capital letter A grave, U+00C0 ISOlat1 -->
945  <xsl:template match="ch.Aacute"><xsl:text>&#193;</xsl:text></xsl:template><!-- latin capital letter A with acute, U+00C1 ISOlat1 -->
946  <xsl:template match="ch.Acirc"><xsl:text>&#194;</xsl:text></xsl:template><!-- latin capital letter A with circumflex, U+00C2 ISOlat1 -->
947  <xsl:template match="ch.Atilde"><xsl:text>&#195;</xsl:text></xsl:template><!-- latin capital letter A with tilde, U+00C3 ISOlat1 -->
948  <xsl:template match="ch.Auml"><xsl:text>&#196;</xsl:text></xsl:template><!-- latin capital letter A with diaeresis, U+00C4 ISOlat1 -->
949  <xsl:template match="ch.Aring"><xsl:text>&#197;</xsl:text></xsl:template><!-- latin capital letter A with ring above = latin capital letter A ring, U+00C5 ISOlat1 -->
950  <xsl:template match="ch.AElig"><xsl:text>&#198;</xsl:text></xsl:template><!-- latin capital letter AE = latin capital ligature AE, U+00C6 ISOlat1 -->
951  <xsl:template match="ch.Ccedil"><xsl:text>&#199;</xsl:text></xsl:template><!-- latin capital letter C with cedilla, U+00C7 ISOlat1 -->
952  <xsl:template match="ch.Egrave"><xsl:text>&#200;</xsl:text></xsl:template><!-- latin capital letter E with grave, U+00C8 ISOlat1 -->
953  <xsl:template match="ch.Eacute"><xsl:text>&#201;</xsl:text></xsl:template><!-- latin capital letter E with acute, U+00C9 ISOlat1 -->
954  <xsl:template match="ch.Ecirc"><xsl:text>&#202;</xsl:text></xsl:template><!-- latin capital letter E with circumflex, U+00CA ISOlat1 -->
955  <xsl:template match="ch.Euml"><xsl:text>&#203;</xsl:text></xsl:template><!-- latin capital letter E with diaeresis, U+00CB ISOlat1 -->
956  <xsl:template match="ch.Igrave"><xsl:text>&#204;</xsl:text></xsl:template><!-- latin capital letter I with grave, U+00CC ISOlat1 -->
957  <xsl:template match="ch.Iacute"><xsl:text>&#205;</xsl:text></xsl:template><!-- latin capital letter I with acute, U+00CD ISOlat1 -->
958  <xsl:template match="ch.Icirc"><xsl:text>&#206;</xsl:text></xsl:template><!-- latin capital letter I with circumflex, U+00CE ISOlat1 -->
959  <xsl:template match="ch.Iuml"><xsl:text>&#207;</xsl:text></xsl:template><!-- latin capital letter I with diaeresis, U+00CF ISOlat1 -->
960  <xsl:template match="ch.ETH"><xsl:text>&#208;</xsl:text></xsl:template><!-- latin capital letter ETH, U+00D0 ISOlat1 -->
961  <xsl:template match="ch.Ntilde"><xsl:text>&#209;</xsl:text></xsl:template><!-- latin capital letter N with tilde, U+00D1 ISOlat1 -->
962  <xsl:template match="ch.Ograve"><xsl:text>&#210;</xsl:text></xsl:template><!-- latin capital letter O with grave, U+00D2 ISOlat1 -->
963  <xsl:template match="ch.Oacute"><xsl:text>&#211;</xsl:text></xsl:template><!-- latin capital letter O with acute, U+00D3 ISOlat1 -->
964  <xsl:template match="ch.Ocirc"><xsl:text>&#212;</xsl:text></xsl:template><!-- latin capital letter O with circumflex, U+00D4 ISOlat1 -->
965  <xsl:template match="ch.Otilde"><xsl:text>&#213;</xsl:text></xsl:template><!-- latin capital letter O with tilde, U+00D5 ISOlat1 -->
966  <xsl:template match="ch.Ouml"><xsl:text>&#214;</xsl:text></xsl:template><!-- latin capital letter O with diaeresis, U+00D6 ISOlat1 -->
967  <xsl:template match="ch.times"><xsl:text>&#215;</xsl:text></xsl:template><!-- multiplication sign, U+00D7 ISOnum -->
968  <xsl:template match="ch.Oslash"><xsl:text>&#216;</xsl:text></xsl:template><!-- latin capital letter O with stroke = latin capital letter O slash, U+00D8 ISOlat1 -->
969  <xsl:template match="ch.Ugrave"><xsl:text>&#217;</xsl:text></xsl:template><!-- latin capital letter U with grave, U+00D9 ISOlat1 -->
970  <xsl:template match="ch.Uacute"><xsl:text>&#218;</xsl:text></xsl:template><!-- latin capital letter U with acute, U+00DA ISOlat1 -->
971  <xsl:template match="ch.Ucirc"><xsl:text>&#219;</xsl:text></xsl:template><!-- latin capital letter U with circumflex, U+00DB ISOlat1 -->
972  <xsl:template match="ch.Uuml"><xsl:text>&#220;</xsl:text></xsl:template><!-- latin capital letter U with diaeresis, U+00DC ISOlat1 -->
973  <xsl:template match="ch.Yacute"><xsl:text>&#221;</xsl:text></xsl:template><!-- latin capital letter Y with acute, U+00DD ISOlat1 -->
974  <xsl:template match="ch.THORN"><xsl:text>&#222;</xsl:text></xsl:template><!-- latin capital letter THORN, U+00DE ISOlat1 -->
975  <xsl:template match="ch.szlig"><xsl:text>&#223;</xsl:text></xsl:template><!-- latin small letter sharp s = ess-zed, U+00DF ISOlat1 -->
976  <xsl:template match="ch.agrave"><xsl:text>&#224;</xsl:text></xsl:template><!-- latin small letter a with grave = latin small letter a grave, U+00E0 ISOlat1 -->
977  <xsl:template match="ch.aacute"><xsl:text>&#225;</xsl:text></xsl:template><!-- latin small letter a with acute, U+00E1 ISOlat1 -->
978  <xsl:template match="ch.acirc"><xsl:text>&#226;</xsl:text></xsl:template><!-- latin small letter a with circumflex, U+00E2 ISOlat1 -->
979  <xsl:template match="ch.atilde"><xsl:text>&#227;</xsl:text></xsl:template><!-- latin small letter a with tilde, U+00E3 ISOlat1 -->
980  <xsl:template match="ch.auml"><xsl:text>&#228;</xsl:text></xsl:template><!-- latin small letter a with diaeresis, U+00E4 ISOlat1 -->
981  <xsl:template match="ch.aring"><xsl:text>&#229;</xsl:text></xsl:template><!-- latin small letter a with ring above = latin small letter a ring, U+00E5 ISOlat1 -->
982  <xsl:template match="ch.aelig"><xsl:text>&#230;</xsl:text></xsl:template><!-- latin small letter ae = latin small ligature ae, U+00E6 ISOlat1 -->
983  <xsl:template match="ch.ccedil"><xsl:text>&#231;</xsl:text></xsl:template><!-- latin small letter c with cedilla, U+00E7 ISOlat1 -->
984  <xsl:template match="ch.egrave"><xsl:text>&#232;</xsl:text></xsl:template><!-- latin small letter e with grave, U+00E8 ISOlat1 -->
985  <xsl:template match="ch.eacute"><xsl:text>&#233;</xsl:text></xsl:template><!-- latin small letter e with acute, U+00E9 ISOlat1 -->
986  <xsl:template match="ch.ecirc"><xsl:text>&#234;</xsl:text></xsl:template><!-- latin small letter e with circumflex, U+00EA ISOlat1 -->
987  <xsl:template match="ch.euml"><xsl:text>&#235;</xsl:text></xsl:template><!-- latin small letter e with diaeresis, U+00EB ISOlat1 -->
988  <xsl:template match="ch.igrave"><xsl:text>&#236;</xsl:text></xsl:template><!-- latin small letter i with grave, U+00EC ISOlat1 -->
989  <xsl:template match="ch.iacute"><xsl:text>&#237;</xsl:text></xsl:template><!-- latin small letter i with acute, U+00ED ISOlat1 -->
990  <xsl:template match="ch.icirc"><xsl:text>&#238;</xsl:text></xsl:template><!-- latin small letter i with circumflex, U+00EE ISOlat1 -->
991  <xsl:template match="ch.iuml"><xsl:text>&#239;</xsl:text></xsl:template><!-- latin small letter i with diaeresis, U+00EF ISOlat1 -->
992  <xsl:template match="ch.eth"><xsl:text>&#240;</xsl:text></xsl:template><!-- latin small letter eth, U+00F0 ISOlat1 -->
993  <xsl:template match="ch.ntilde"><xsl:text>&#241;</xsl:text></xsl:template><!-- latin small letter n with tilde, U+00F1 ISOlat1 -->
994  <xsl:template match="ch.ograve"><xsl:text>&#242;</xsl:text></xsl:template><!-- latin small letter o with grave, U+00F2 ISOlat1 -->
995  <xsl:template match="ch.oacute"><xsl:text>&#243;</xsl:text></xsl:template><!-- latin small letter o with acute, U+00F3 ISOlat1 -->
996  <xsl:template match="ch.ocirc"><xsl:text>&#244;</xsl:text></xsl:template><!-- latin small letter o with circumflex, U+00F4 ISOlat1 -->
997  <xsl:template match="ch.otilde"><xsl:text>&#245;</xsl:text></xsl:template><!-- latin small letter o with tilde, U+00F5 ISOlat1 -->
998  <xsl:template match="ch.ouml"><xsl:text>&#246;</xsl:text></xsl:template><!-- latin small letter o with diaeresis, U+00F6 ISOlat1 -->
999  <xsl:template match="ch.divide"><xsl:text>&#247;</xsl:text></xsl:template><!-- division sign, U+00F7 ISOnum -->
1000  <xsl:template match="ch.oslash"><xsl:text>&#248;</xsl:text></xsl:template><!-- latin small letter o with stroke, = latin small letter o slash, U+00F8 ISOlat1 -->
1001  <xsl:template match="ch.ugrave"><xsl:text>&#249;</xsl:text></xsl:template><!-- latin small letter u with grave, U+00F9 ISOlat1 -->
1002  <xsl:template match="ch.uacute"><xsl:text>&#250;</xsl:text></xsl:template><!-- latin small letter u with acute, U+00FA ISOlat1 -->
1003  <xsl:template match="ch.ucirc"><xsl:text>&#251;</xsl:text></xsl:template><!-- latin small letter u with circumflex, U+00FB ISOlat1 -->
1004  <xsl:template match="ch.uuml"><xsl:text>&#252;</xsl:text></xsl:template><!-- latin small letter u with diaeresis, U+00FC ISOlat1 -->
1005  <xsl:template match="ch.yacute"><xsl:text>&#253;</xsl:text></xsl:template><!-- latin small letter y with acute, U+00FD ISOlat1 -->
1006  <xsl:template match="ch.thorn"><xsl:text>&#254;</xsl:text></xsl:template><!-- latin small letter thorn, U+00FE ISOlat1 -->
1007  <xsl:template match="ch.yuml"><xsl:text>&#255;</xsl:text></xsl:template><!-- latin small letter y with diaeresis, U+00FF ISOlat1 -->
1008
1009  <!-- ~~~~~~~~~~~~~~~~~~~~~ Special Characters ~~~~~~~~~~~~~~~~~~~~ -->
1010
1011  <xsl:template match="ch.ampersand">&amp;</xsl:template><!-- ampersand -->
1012  <xsl:template match="ch.lsquot">&#8216;</xsl:template><!-- opening left quotation mark -->
1013  <xsl:template match="ch.rsquot">&#8217;</xsl:template><!-- closing right quotation mark -->
1014  <xsl:template match="ch.ldquot">&#8220;</xsl:template><!-- opening left double quotation mark -->
1015  <xsl:template match="ch.rdquot">&#8221;</xsl:template><!-- closing right double quotation mark -->
1016  <xsl:template match="ch.minus">&#8722;</xsl:template><!-- mathematical minus -->
1017  <xsl:template match="ch.endash">&#8211;</xsl:template><!-- endash -->
1018  <xsl:template match="ch.emdash">&#160;&#8212;&#32;</xsl:template><!-- emdash -->
1019  <xsl:template match="ch.ellips">&#160;&#8230;&#32;</xsl:template><!-- ellipsis -->
1020  <xsl:template match="ch.lellips">&#8230;&#32;</xsl:template><!-- left ellipsis, used at the beginning of edited material -->
1021  <xsl:template match="ch.blankline">_______</xsl:template><!-- blank line to be filled in -->
1022  <xsl:template match="ch.percent"><xsl:text>&#37;</xsl:text></xsl:template><!-- percent sign -->
1023  <xsl:template match="ch.thinspace"><xsl:text>&#32;</xsl:text></xsl:template><!-- small horizontal space for use between adjacent quotation marks - added mainly for LaTeX's sake -->
1024  <xsl:template match="ch.frac116"><xsl:text>1/16</xsl:text></xsl:template><!-- vulgar fraction one sixteenth = fraction on sixteenth -->
1025  <xsl:template match="ch.plus"><xsl:text>+</xsl:text></xsl:template><!-- mathematical plus -->
1026
1027  <!-- ==================== named templates ======================= -->
1028
1029  <xsl:template name="xhtml-wrapper">
1030   <xsl:param name="document-type">undefined</xsl:param>
1031   <xsl:param name="filename">undefined</xsl:param>
1032   <xsl:param name="glossary-id-prefix"></xsl:param>
1033
1034   <redirect:write file="{$filename}{$xhtml-ext}">
1035    <xsl:fallback>
1036     <xsl:text>xhtml-wrapper: Cannot write to filename: "</xsl:text>
1037     <xsl:value-of select="$filename" />
1038     <xsl:value-of select="$xhtml-ext" />
1039    </xsl:fallback>
1040
1041    <html xml:lang="{$language}">
1042
1043     <head>
1044      <title>
1045       <xsl:apply-templates select="/gamebook/meta/title[1]" />
1046       <xsl:text>: </xsl:text>
1047       <xsl:apply-templates select="meta/title[1]" />
1048      </title>
1049      <meta http-equiv="Content-type" content="application/xhtml+xml; charset=utf-8" />
1050      <link rel="stylesheet" href="main.css" type="text/css" />
1051     </head>
1052
1053     <xsl:comment>
1054      <xsl:text> </xsl:text>
1055      <xsl:apply-templates select="/gamebook/meta/rights[@class='copyrights']" />
1056      <xsl:choose>
1057       <xsl:when test="$language='es'">
1058        <xsl:text> Publicado por </xsl:text>
1059       </xsl:when>
1060       <xsl:otherwise>
1061        <xsl:text> Published by </xsl:text>
1062       </xsl:otherwise>
1063      </xsl:choose>
1064      <xsl:apply-templates select="/gamebook/meta/publisher[1]" />
1065      <xsl:text>. </xsl:text>
1066     </xsl:comment>
1067
1068     <body> 
1069      <div id="body"> 
1070       <xsl:choose>
1071
1072  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~ top-level ~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
1073
1074        <xsl:when test="$document-type='top-level'">
1075         <div class="frontmatter">
1076
1077          <div class="maintext">
1078           <h1 id="title">
1079            <xsl:apply-templates select="/gamebook/meta/title[1]"/>
1080           </h1>
1081           <xsl:apply-templates select="/gamebook/meta/description[@class='blurb']" />
1082           <xsl:apply-templates select="/gamebook/meta/creator[@class='long']" />
1083
1084           <hr />
1085
1086           <xsl:apply-templates select="/gamebook/meta/description[@class='publication']" />
1087
1088           <p>
1089            <xsl:choose>
1090             <xsl:when test="$language='es'">
1091              <xsl:text>Fecha de Publicaci&oacute;n: </xsl:text>
1092             </xsl:when>
1093             <xsl:otherwise>
1094              <xsl:text>Publication Date: </xsl:text>
1095             </xsl:otherwise>
1096            </xsl:choose>
1097            <xsl:value-of select="/gamebook/meta/date[@class='publication']/day" />
1098            <xsl:text> </xsl:text>
1099            <xsl:choose>
1100             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 1">
1101              <xsl:choose>
1102               <xsl:when test="$language='es'"><xsl:text>de enero de</xsl:text></xsl:when>
1103               <xsl:otherwise><xsl:text>January</xsl:text></xsl:otherwise>
1104              </xsl:choose>
1105             </xsl:when>
1106             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 2">
1107              <xsl:choose>
1108               <xsl:when test="$language='es'"><xsl:text>de febrero de</xsl:text></xsl:when>
1109               <xsl:otherwise><xsl:text>February</xsl:text></xsl:otherwise>
1110              </xsl:choose>
1111             </xsl:when>
1112             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 3">
1113              <xsl:choose>
1114               <xsl:when test="$language='es'"><xsl:text>de marzo de</xsl:text></xsl:when>
1115               <xsl:otherwise><xsl:text>March</xsl:text></xsl:otherwise>
1116              </xsl:choose>
1117             </xsl:when>
1118             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 4">
1119              <xsl:choose>
1120               <xsl:when test="$language='es'"><xsl:text>de abril de</xsl:text></xsl:when>
1121               <xsl:otherwise><xsl:text>April</xsl:text></xsl:otherwise>
1122              </xsl:choose>
1123             </xsl:when>
1124             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 5">
1125              <xsl:choose>
1126               <xsl:when test="$language='es'"><xsl:text>de mayo de</xsl:text></xsl:when>
1127               <xsl:otherwise><xsl:text>May</xsl:text></xsl:otherwise>
1128              </xsl:choose>
1129             </xsl:when>
1130             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 6">
1131              <xsl:choose>
1132               <xsl:when test="$language='es'"><xsl:text>de junio de</xsl:text></xsl:when>
1133               <xsl:otherwise><xsl:text>June</xsl:text></xsl:otherwise>
1134              </xsl:choose>
1135             </xsl:when>
1136             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 7">
1137              <xsl:choose>
1138               <xsl:when test="$language='es'"><xsl:text>de julio de</xsl:text></xsl:when>
1139               <xsl:otherwise><xsl:text>July</xsl:text></xsl:otherwise>
1140              </xsl:choose>
1141             </xsl:when>
1142             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 8">
1143              <xsl:choose>
1144               <xsl:when test="$language='es'"><xsl:text>de agosto de</xsl:text></xsl:when>
1145               <xsl:otherwise><xsl:text>August</xsl:text></xsl:otherwise>
1146              </xsl:choose>
1147             </xsl:when>
1148             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 9">
1149              <xsl:choose>
1150               <xsl:when test="$language='es'"><xsl:text>de septiembre de</xsl:text></xsl:when>
1151               <xsl:otherwise><xsl:text>September</xsl:text></xsl:otherwise>
1152              </xsl:choose>
1153             </xsl:when>
1154             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 10">
1155              <xsl:choose>
1156               <xsl:when test="$language='es'"><xsl:text>de octubre de</xsl:text></xsl:when>
1157               <xsl:otherwise><xsl:text>October</xsl:text></xsl:otherwise>
1158              </xsl:choose>
1159             </xsl:when>
1160             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 11">
1161              <xsl:choose>
1162               <xsl:when test="$language='es'"><xsl:text>de noviembre de</xsl:text></xsl:when>
1163               <xsl:otherwise><xsl:text>November</xsl:text></xsl:otherwise>
1164              </xsl:choose>
1165             </xsl:when>
1166             <xsl:when test="/gamebook/meta/date[@class='publication']/month = 12">
1167              <xsl:choose>
1168               <xsl:when test="$language='es'"><xsl:text>de diciembre de</xsl:text></xsl:when>
1169               <xsl:otherwise><xsl:text>December</xsl:text></xsl:otherwise>
1170              </xsl:choose>
1171             </xsl:when>
1172             <xsl:otherwise>
1173              <xsl:text>Invalid Month</xsl:text>
1174             </xsl:otherwise>
1175            </xsl:choose>
1176            <xsl:text> </xsl:text>
1177            <xsl:value-of select="/gamebook/meta/date[@class='publication']/year" />
1178           </p>
1179
1180           <xsl:apply-templates select="/gamebook/meta/rights[@class='license-notification']" />
1181          </div>
1182         </div>
1183
1184        </xsl:when>
1185
1186  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ toc ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
1187
1188        <xsl:when test="$document-type='toc'">
1189         <div class="frontmatter">
1190          <div class="maintext">
1191
1192           <h2>
1193            <xsl:choose>
1194             <xsl:when test="$language='es'">
1195              <xsl:text>&Iacute;ndice de Contenidos</xsl:text>
1196             </xsl:when>
1197             <xsl:otherwise>
1198              <xsl:text>Table of Contents</xsl:text>
1199             </xsl:otherwise>
1200            </xsl:choose>
1201           </h2>
1202
1203           <ul>
1204            <xsl:variable name="title-page">
1205             <xsl:choose>
1206              <xsl:when test="$language='es'">
1207               <xsl:text>P&aacute;gina Principal</xsl:text>
1208              </xsl:when>
1209              <xsl:otherwise>
1210               <xsl:text>Title Page</xsl:text>
1211              </xsl:otherwise>
1212             </xsl:choose>
1213            </xsl:variable>
1214
1215            <li><a href="title{$xhtml-ext}"><xsl:value-of select="$title-page"/></a></li>
1216            <xsl:for-each select="/gamebook/section/data/section">
1217             <li>
1218              <a><xsl:attribute name="href"><xsl:value-of select="@id" /><xsl:value-of select="$xhtml-ext"/></xsl:attribute>
1219               <xsl:apply-templates select="meta/title[1]" />
1220              </a>
1221              <xsl:if test="data/section[@class='frontmatter-separate' or @class='mainmatter-separate']">
1222
1223               <ul>
1224                <xsl:for-each select="data/section[@class='frontmatter-separate' or @class='mainmatter-separate']">
1225                 <li>
1226                  <a><xsl:attribute name="href"><xsl:value-of select="@id" /><xsl:value-of select="$xhtml-ext"/></xsl:attribute>
1227                   <xsl:value-of select ="meta/title[1]" />
1228                  </a>
1229                 </li>
1230                </xsl:for-each>
1231               </ul>
1232              </xsl:if>
1233             </li>
1234            </xsl:for-each>
1235           </ul>
1236
1237          </div>
1238         </div>
1239        </xsl:when>
1240
1241  <!-- ~~~~~~~~~~~~~~~~ second-level-frontmatter ~~~~~~~~~~~~~~~~~~~ -->
1242
1243        <xsl:when test="$document-type='second-level-frontmatter'">
1244         <div class="frontmatter">
1245          <div class="maintext">
1246           <h2><xsl:apply-templates select="meta/title" /></h2>
1247
1248           <xsl:apply-templates />
1249          </div>
1250         </div>
1251        </xsl:when>
1252
1253  <!-- ~~~~~~~~~~~~~ third-level-frontmatter-separate ~~~~~~~~~~~~~~ -->
1254
1255        <xsl:when test="$document-type='third-level-frontmatter-separate'">
1256         <div class="frontmatter">
1257          <div class="maintext">
1258           <h3><xsl:apply-templates select="meta/title" /></h3>
1259
1260           <xsl:apply-templates />
1261          </div>
1262         </div>
1263        </xsl:when>
1264
1265  <!-- ~~~~~~~~~~~~~~~~ second-level-mainmatter ~~~~~~~~~~~~~~~~~~~ -->
1266
1267        <xsl:when test="$document-type='second-level-mainmatter'">
1268         <div class="mainmatter">
1269          <div class="maintext">
1270           <h2><xsl:apply-templates select="meta/title" /></h2>
1271
1272           <xsl:apply-templates />
1273          </div>
1274         </div>
1275        </xsl:when>
1276
1277  <!-- ~~~~~~~~~~~~~ third-level-mainmatter-separate ~~~~~~~~~~~~~~ -->
1278
1279        <xsl:when test="$document-type='third-level-mainmatter-separate'">
1280         <div class="mainmatter">
1281          <div class="maintext">
1282           <h3><xsl:apply-templates select="meta/title" /></h3>
1283
1284           <xsl:apply-templates />
1285          </div>
1286         </div>
1287        </xsl:when>
1288
1289  <!-- ~~~~~~~~~~~~~~~~ second-level-glossary ~~~~~~~~~~~~~~~~~~~ -->
1290
1291        <xsl:when test="$document-type='second-level-glossary'">
1292         <div class="mainmatter">
1293          <div class="maintext">
1294           <h2><xsl:apply-templates select="meta/title" /></h2>
1295
1296           <xsl:call-template name="alpha-bar">
1297            <xsl:with-param name="alpha-bar-id-prefix"><xsl:value-of select="$glossary-id-prefix" /></xsl:with-param>
1298           </xsl:call-template>
1299
1300           <xsl:apply-templates />
1301          </div>
1302         </div>
1303        </xsl:when>
1304
1305  <!-- ~~~~~~~~~~~~~ third-level-glossary-separate ~~~~~~~~~~~~~~ -->
1306
1307        <xsl:when test="$document-type='third-level-glossary-separate'">
1308         <div class="glossary">
1309          <div class="maintext">
1310           <h3><xsl:apply-templates select="meta/title" /></h3>
1311           <xsl:call-template name="alpha-bar">
1312            <xsl:with-param name="alpha-bar-id-prefix"><xsl:value-of select="$glossary-id-prefix" /></xsl:with-param>
1313           </xsl:call-template>
1314
1315           <xsl:apply-templates />
1316          </div>
1317         </div>
1318        </xsl:when>
1319
1320  <!-- ~~~~~~~~~~~~~~~~~~ second-level-numbered ~~~~~~~~~~~~~~~~~~~~ -->
1321  <!--
1322
1323 The following automatically generated section list requires that the
1324 title of each section be a simple number.
1325
1326 -->
1327        <xsl:when test="$document-type='second-level-numbered'">
1328         <div class="numbered">
1329          <div class="maintext">
1330           <h2><xsl:apply-templates select="meta/title" /></h2>
1331
1332           <xsl:variable name="base-section-number" select="number( data/section[1]/meta/title ) - 1" />
1333           <p>
1334            <xsl:for-each select="data/section">
1335             <xsl:if test="position( ) mod 10 = 1">
1336              <b>
1337               <xsl:value-of select="position( ) + $base-section-number" />
1338               <xsl:if test="not( position( ) = last( ) )">
1339                <xsl:text>-</xsl:text>
1340                <xsl:choose>
1341                 <xsl:when test="position( ) + 9 &lt;= last( )">
1342                  <xsl:value-of select="position( ) + 9 + $base-section-number" />
1343                 </xsl:when>
1344                 <xsl:otherwise>
1345                  <xsl:value-of select="last( ) + $base-section-number" />
1346                 </xsl:otherwise>
1347                </xsl:choose>
1348               </xsl:if>
1349              <xsl:text>: </xsl:text></b>
1350             </xsl:if>
1351             <a>
1352              <xsl:attribute name="href"><xsl:value-of select="@id" /><xsl:value-of select="$xhtml-ext"/></xsl:attribute>
1353              <xsl:apply-templates select="meta/title" />
1354             </a>
1355             <xsl:choose>
1356              <xsl:when test="position( ) mod 10 = 0">
1357               <br />
1358              </xsl:when>
1359              <xsl:otherwise>
1360               <xsl:text> </xsl:text>
1361              </xsl:otherwise>
1362             </xsl:choose>
1363            </xsl:for-each>
1364           </p>
1365          </div>
1366
1367         </div>
1368        </xsl:when>
1369
1370  <!-- ~~~~~~~~~~~~~~~~~~ third-level-numbered ~~~~~~~~~~~~~~~~~~~~~ -->
1371
1372        <xsl:when test="$document-type='third-level-numbered'">
1373         <div class="numbered">
1374          <div class="maintext">
1375           <h3><xsl:apply-templates select="meta/title" /></h3>
1376
1377           <xsl:apply-templates />
1378          </div>
1379         </div>
1380        </xsl:when>
1381
1382  <!-- ~~~~~~~~~~~~~~~~~ footnotes ~~~~~~~~~~~~~~~~~~~ -->
1383
1384        <xsl:when test="$document-type='footnotz'">
1385         <div class="backmatter">
1386          <div class="maintext">
1387
1388           <!-- No particular reason to code title here -->
1389           <h2><xsl:apply-templates select="meta/title" /></h2>
1390           <!-- Generate list of footnotes -->
1391           <xsl:for-each select="//footnotes/footnote">
1392            <div class="footnote">
1393             <!-- will the list always contain the closest ancestor first? -->
1394             <xsl:variable name="footnote-section"><xsl:value-of select="ancestor::section[position()=1]/@id" /></xsl:variable>
1395             <xsl:variable name="footnote-marker"><xsl:number count="footnotes/footnote" from="/" level="any" format="1" /></xsl:variable>
1396             <xsl:variable name="footnote-idref"><xsl:value-of select="@idref" /></xsl:variable>
1397
1398             <xsl:for-each select="*[1]">
1399              <p>
1400               <xsl:text>[</xsl:text>
1401               <a>
1402                <xsl:attribute name="href"><xsl:value-of select="$footnote-section" /><xsl:value-of select="$xhtml-ext"/></xsl:attribute>
1403                <xsl:value-of select="$footnote-marker" />
1404               </a>
1405               <xsl:text>] </xsl:text>
1406
1407               <xsl:text> (</xsl:text>
1408               <xsl:call-template name="section-title-link" />
1409               <xsl:text>) </xsl:text>
1410
1411               <xsl:apply-templates select="child::* | child::text()" />
1412              </p>
1413             </xsl:for-each>
1414
1415             <xsl:for-each select="*[position() != 1]">
1416              <xsl:apply-templates select="." />
1417             </xsl:for-each>
1418
1419            </div>
1420           </xsl:for-each>
1421
1422           <!-- Backwards compatibility... needed? Probably not. -->
1423           <xsl:apply-templates />
1424          </div>
1425         </div>
1426        </xsl:when>
1427
1428  <!-- ~~~~~~~~~~~~~~~~~ second-level-backmatter ~~~~~~~~~~~~~~~~~~~ -->
1429
1430        <xsl:when test="$document-type='second-level-backmatter'">
1431         <div class="frontmatter">
1432          <div class="maintext">
1433           <h2><xsl:apply-templates select="meta/title" /></h2>
1434
1435           <xsl:apply-templates />
1436          </div>
1437         </div>
1438        </xsl:when>
1439
1440  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ map ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
1441
1442        <xsl:when test="$document-type='map'">
1443         <div class="frontmatter">
1444          <div class="maintext">
1445           <h2><xsl:apply-templates select="meta/title" /></h2>
1446
1447           <xsl:for-each select="data/* | data/text()">
1448            <xsl:variable name="map-illustration-alt-text">
1449             <xsl:choose>
1450              <xsl:when test="$language='es'">
1451               <xsl:text>mapa</xsl:text>
1452              </xsl:when>
1453              <xsl:otherwise>
1454               <xsl:text>map</xsl:text>
1455              </xsl:otherwise>
1456             </xsl:choose>
1457            </xsl:variable>
1458
1459            <!-- duplicated stuff here, no good way to avoid this while retaining backwards compatibility -->
1460            <xsl:choose>
1461             <xsl:when test="self::illustration and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )">
1462              <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
1463              <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
1464              <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
1465
1466              <div class="illustration">
1467               <xsl:call-template name="illustration-noframe">
1468                <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width" /></xsl:with-param>
1469                <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height" /></xsl:with-param>
1470                <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
1471                <xsl:with-param name="illustration-href">map<xsl:value-of select="$xhtml-ext"/></xsl:with-param>
1472                <xsl:with-param name="illustration-alt-text">
1473                 <xsl:text>[</xsl:text>
1474                        <xsl:value-of select="$map-illustration-alt-text"/>
1475                       <xsl:text>]</xsl:text>
1476               </xsl:with-param>
1477               </xsl:call-template>
1478              </div>
1479             </xsl:when>
1480
1481             <xsl:when test="self::illref and @class='html'">
1482              <xsl:for-each select="id( @idref )">
1483               <xsl:if test="contains( $use-illustrators, concat( ':', meta/creator, ':' ) )">
1484                <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
1485                <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
1486                <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
1487
1488                <div class="illustration">
1489                 <xsl:call-template name="illustration-noframe">
1490                  <xsl:with-param name="illustration-width"><xsl:value-of select="$illustration-width" /></xsl:with-param>
1491                  <xsl:with-param name="illustration-height"><xsl:value-of select="$illustration-height" /></xsl:with-param>
1492                  <xsl:with-param name="illustration-src"><xsl:value-of select="$illustration-src" /></xsl:with-param>
1493                  <xsl:with-param name="illustration-href">map<xsl:value-of select="$xhtml-ext"/></xsl:with-param>
1494                  <xsl:with-param name="illustration-alt-text">
1495                          <xsl:text>[</xsl:text>
1496                   <xsl:value-of select="$map-illustration-alt-text"/>
1497                          <xsl:text>]</xsl:text>
1498                         </xsl:with-param>
1499                 </xsl:call-template>
1500                </div>
1501               </xsl:if>
1502              </xsl:for-each>
1503             </xsl:when>
1504             <xsl:otherwise>
1505              <xsl:apply-templates select="." />
1506             </xsl:otherwise>
1507            </xsl:choose>
1508           </xsl:for-each>
1509          </div>
1510         </div>
1511        </xsl:when>
1512
1513  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~ error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
1514
1515        <xsl:otherwise>
1516         <xsl:message>
1517          <xsl:text>xhtml-wrapper: Cannot process document of type "</xsl:text>
1518          <xsl:value-of select="$document-type" />
1519          <xsl:text>".</xsl:text>
1520         </xsl:message>
1521         <p>
1522          <xsl:text>xhtml-wrapper: Cannot process document of type "</xsl:text>
1523          <xsl:value-of select="$document-type" />
1524          <xsl:text>".</xsl:text>
1525         </p>
1526        </xsl:otherwise>
1527
1528       </xsl:choose>
1529
1530  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~ footer ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
1531
1532       <xsl:call-template name="process-footnotes" />
1533
1534      </div>
1535     </body>
1536
1537    </html>
1538   </redirect:write>
1539
1540  </xsl:template>
1541
1542  <xsl:template name="process-footnotes">
1543   <xsl:if test="footnotes/footnote">
1544    <div id="footnotes">
1545     <xsl:for-each select="footnotes/footnote">
1546      <xsl:variable name="footnote-idref" select="@idref" />
1547      <xsl:variable name="footnote-id" select="@id" />
1548      <xsl:variable name="footnote-marker"><xsl:number count="footnotes/footnote" from="/" level="any" format="1" /></xsl:variable>
1549
1550      <xsl:for-each select="*[1]">
1551       <p>
1552        <xsl:text>[</xsl:text>
1553         <xsl:value-of select="$footnote-marker" />
1554        <xsl:text>] </xsl:text>
1555        <xsl:apply-templates select="child::* | child::text()" />
1556       </p>
1557      </xsl:for-each>
1558
1559      <xsl:for-each select="*[position() != 1]">
1560        <xsl:apply-templates select="." />
1561      </xsl:for-each>
1562     </xsl:for-each>
1563    </div>
1564   </xsl:if>
1565  </xsl:template>
1566
1567  <xsl:template name="alpha-bar">
1568   <xsl:param name="alpha-bar-id-prefix"></xsl:param>
1569
1570    <p class="navigation">[<a href="{$alpha-bar-id-prefix}a{$xhtml-ext}">A</a>&nbsp;<a href="{$alpha-bar-id-prefix}b{$xhtml-ext}">B</a>&nbsp;<a href="{$alpha-bar-id-prefix}c{$xhtml-ext}">C</a>&nbsp;<a href="{$alpha-bar-id-prefix}d{$xhtml-ext}">D</a>&nbsp;<a href="{$alpha-bar-id-prefix}e{$xhtml-ext}">E</a>&nbsp;<a href="{$alpha-bar-id-prefix}f{$xhtml-ext}">F</a>&nbsp;<a href="{$alpha-bar-id-prefix}g{$xhtml-ext}">G</a>&nbsp;<a href="{$alpha-bar-id-prefix}h{$xhtml-ext}">H</a>&nbsp;<a href="{$alpha-bar-id-prefix}i{$xhtml-ext}">I</a>&nbsp;<a href="{$alpha-bar-id-prefix}j{$xhtml-ext}">J</a>&nbsp;<a href="{$alpha-bar-id-prefix}k{$xhtml-ext}">K</a>&nbsp;<a href="{$alpha-bar-id-prefix}l{$xhtml-ext}">L</a>&nbsp;<a href="{$alpha-bar-id-prefix}m{$xhtml-ext}">M</a>&nbsp;<a href="{$alpha-bar-id-prefix}n{$xhtml-ext}">N</a>&nbsp;<a href="{$alpha-bar-id-prefix}o{$xhtml-ext}">O</a>&nbsp;<a href="{$alpha-bar-id-prefix}p{$xhtml-ext}">P</a>&nbsp;<a href="{$alpha-bar-id-prefix}q{$xhtml-ext}">Q</a>&nbsp;<a href="{$alpha-bar-id-prefix}r{$xhtml-ext}">R</a>&nbsp;<a href="{$alpha-bar-id-prefix}s{$xhtml-ext}">S</a>&nbsp;<a href="{$alpha-bar-id-prefix}t{$xhtml-ext}">T</a>&nbsp;<a href="{$alpha-bar-id-prefix}u{$xhtml-ext}">U</a>&nbsp;<a href="{$alpha-bar-id-prefix}v{$xhtml-ext}">V</a>&nbsp;<a href="{$alpha-bar-id-prefix}w{$xhtml-ext}">W</a>&nbsp;<a href="{$alpha-bar-id-prefix}x{$xhtml-ext}">X</a>&nbsp;<a href="{$alpha-bar-id-prefix}y{$xhtml-ext}">Y</a>&nbsp;<a href="{$alpha-bar-id-prefix}z{$xhtml-ext}">Z</a>]</p>
1571
1572  </xsl:template>
1573
1574  <xsl:template name="illustration-noframe">
1575   <xsl:param name="illustration-width" select="instance[@class='html']/@width" />
1576   <xsl:param name="illustration-height" select="instance[@class='html']/@height" />
1577   <xsl:param name="illustration-src" select="instance[@class='html']/@src" />
1578   <xsl:param name="illustration-alt-text">
1579    <xsl:choose>
1580     <xsl:when test="$language='es'">
1581      <xsl:text>ilustraci&oacute;n</xsl:text>
1582     </xsl:when>
1583     <xsl:otherwise>
1584      <xsl:text>illustration</xsl:text>
1585     </xsl:otherwise>
1586    </xsl:choose>
1587   </xsl:param>
1588
1589    <img src="{$illustration-src}" width="{$illustration-width}" height="{$illustration-height}" alt="[{$illustration-alt-text}]" />
1590    <xsl:if test="@class='float'">
1591     <br />
1592     <strong>
1593      <xsl:choose>
1594       <xsl:when test="$language='es'">
1595        <xsl:text>Ilustraci&oacute;n </xsl:text>
1596       </xsl:when>
1597       <xsl:otherwise>
1598        <xsl:text>Illustration </xsl:text>
1599       </xsl:otherwise>
1600      </xsl:choose>
1601      <xsl:number count="illustration[@class='float' and contains( $use-illustrators, concat( ':', meta/creator, ':' ) )]" from="/" level="any" format="I" />
1602     </strong>
1603     <xsl:text>&#8212;</xsl:text>
1604     <xsl:apply-templates select="meta/description" />
1605    </xsl:if>
1606    <br /><br />
1607  </xsl:template>
1608
1609  <!--
1610   A "subroutine" to generate a link to the current section, with the section title (expanded with "Section " in case of a numbered section) as link text.
1611 -->
1612  <xsl:template name="section-title-link">
1613   <!-- will the list always contain the closest ancestor first? -->
1614   <xsl:variable name="section-title">
1615    <!-- numbered or not? -->
1616    <xsl:if test="ancestor::section[position()=1]/@class='numbered'">
1617     <xsl:choose>
1618      <xsl:when test="$language='es'">
1619       <xsl:text>Secci&oacute;n </xsl:text>
1620      </xsl:when>
1621      <xsl:otherwise>
1622       <xsl:text>Section </xsl:text>
1623      </xsl:otherwise>
1624     </xsl:choose>
1625    </xsl:if>
1626    <xsl:apply-templates select="ancestor::section[position()=1]/meta/title[1]" />
1627   </xsl:variable>
1628
1629   <a>
1630    <xsl:attribute name="href"><xsl:value-of select="ancestor::section[position()=1]/@id" /><xsl:value-of select="$xhtml-ext"/></xsl:attribute>
1631    <xsl:value-of select="$section-title" />
1632   </a>
1633  </xsl:template>
1634
1635 </xsl:transform>