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