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