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