Freeway Warrior 1-4:
[project-aon.git] / xhtml-pda.xsl
1 <?xml version="1.0"?>
2 <!DOCTYPE xhtml-transform [
3  <!ENTITY nbsp "&#160;">
4 ]>
5
6 <!--
7
8 $Id$
9
10 $Log$
11 Revision 1.2  2005/04/09 19:51:50  angantyr
12 Added handling of open-ended quotes.
13
14 Revision 1.1  2005/01/30 01:32:52  jonathan.blake
15 Initial freepository revision of XML support documents.
16
17 Revision 1.1  2003/01/15 17:22:44  jblake
18 Initial revision
19
20
21 Revision 1.1  2002/10/22 16:35:26  jblake
22 Initial revision
23
24
25 Revision 1.2  2002/10/20 06:25:35  jblake
26 Added support for CLOSE COMBAT SKILL for Freeway Warrior books.
27
28 Revision 1.1  2002/10/15 23:29:51  jblake
29 Initial revision
30
31
32 20020327 - repurposed to be used with Xalan Java 2
33 -->
34
35 <xsl:transform version="1.0"
36   xmlns:xml="http://www.w3.org/XML/1998/namespace"
37   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
38   xmlns:lxslt="http://xml.apache.org/xslt"
39   xmlns:redirect="org.apache.xalan.lib.Redirect"
40   extension-element-prefixes="redirect">
41
42 <xsl:output method="xml"
43             encoding="ISO-8859-1"
44             omit-xml-declaration="yes"
45             doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
46             doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
47
48 <xsl:strip-space elements="section data ol ul dl li dd footnotes footnote" />
49 <xsl:preserve-space elements="p" />
50
51 <!-- ====================== parameters ========================== -->
52
53 <xsl:param name="book-path"><xsl:text>undefined-book</xsl:text></xsl:param>
54
55 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~ colors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
56
57 <xsl:param name="link-color"><xsl:text>#ff0000</xsl:text></xsl:param>
58 <xsl:param name="alink-color"><xsl:value-of select="$link-color" /></xsl:param>
59 <xsl:param name="vlink-color"><xsl:value-of select="$link-color" /></xsl:param>
60
61 <xsl:param name="text-color"><xsl:text>#000000</xsl:text></xsl:param>
62 <xsl:param name="background-color"><xsl:text>ffffe4</xsl:text></xsl:param>
63
64 <!-- ======================= variables ========================== -->
65
66 <xsl:variable name="newline">
67 <xsl:text>
68 </xsl:text>
69 </xsl:variable>
70
71 <!-- ======================== Templates ========================= -->
72
73 <!-- ================= hierarchical sections ==================== -->
74
75 <xsl:template match="meta" />
76 <xsl:template match="section" />
77
78 <!-- ::::::::::::::::::: top-level section :::::::::::::::::::::: -->
79
80 <xsl:template match="/gamebook/section">
81  <xsl:call-template name="xhtml-wrapper">
82   <xsl:with-param name="document-type">top-level</xsl:with-param>
83   <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
84  </xsl:call-template>
85
86  <xsl:call-template name="xhtml-wrapper">
87   <xsl:with-param name="document-type">toc</xsl:with-param>
88   <xsl:with-param name="filename">toc</xsl:with-param>
89  </xsl:call-template>
90
91  <xsl:apply-templates />
92
93 </xsl:template>
94
95 <!-- ::::::::::: second-level frontmatter sections :::::::::::::: -->
96
97 <xsl:template match="/gamebook/section/data/section[@class='frontmatter']">
98  <xsl:call-template name="xhtml-wrapper">
99   <xsl:with-param name="document-type">second-level-frontmatter</xsl:with-param>
100   <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
101  </xsl:call-template>
102 </xsl:template>
103
104 <!-- :::::::::::: third-level front matter sections ::::::::::::: -->
105
106 <xsl:template match="/gamebook/section/data/section/data/section[@class='frontmatter']">
107  <h3><xsl:value-of select="meta/title[1]" /></h3>
108
109  <xsl:value-of select="$newline" />
110  <xsl:value-of select="$newline" />
111
112  <xsl:apply-templates />
113 </xsl:template>
114
115 <xsl:template match="/gamebook/section/data/section/data/section[@class='frontmatter-separate']">
116  <xsl:call-template name="xhtml-wrapper">
117   <xsl:with-param name="document-type">third-level-frontmatter-separate</xsl:with-param>
118   <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
119  </xsl:call-template>
120 </xsl:template>
121
122 <!-- :::::::::::: fourth-level front matter sections :::::::::::: -->
123
124 <xsl:template match="/gamebook/section/data/section/data/section/data/section[@class='frontmatter']">
125  <h4><xsl:value-of select="meta/title[1]" /></h4>
126
127  <xsl:value-of select="$newline" />
128  <xsl:value-of select="$newline" />
129
130  <xsl:apply-templates />
131 </xsl:template>
132
133 <!-- ::::::::::::: fifth-level front matter sections :::::::::::: -->
134
135 <xsl:template match="/gamebook/section/data/section/data/section/data/section/data/section[@class='frontmatter']">
136  <h5><xsl:value-of select="meta/title[1]" /></h5>
137
138  <xsl:value-of select="$newline" />
139  <xsl:value-of select="$newline" />
140
141  <xsl:apply-templates />
142 </xsl:template>
143
144 <!-- ::::::::::: second-level main matter sections :::::::::::::: -->
145
146 <xsl:template match="/gamebook/section/data/section[@class='mainmatter']">
147  <xsl:call-template name="xhtml-wrapper">
148   <xsl:with-param name="document-type">second-level-mainmatter</xsl:with-param>
149   <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
150  </xsl:call-template>
151 </xsl:template>
152
153 <!-- :::::::::::: third-level main matter sections ::::::::::::: -->
154
155 <xsl:template match="/gamebook/section/data/section/data/section[@class='mainmatter']">
156  <h3><xsl:value-of select="meta/title[1]" /></h3>
157
158  <xsl:value-of select="$newline" />
159  <xsl:value-of select="$newline" />
160
161  <xsl:apply-templates />
162 </xsl:template>
163
164 <xsl:template match="/gamebook/section/data/section/data/section[@class='mainmatter-separate']">
165  <xsl:call-template name="xhtml-wrapper">
166   <xsl:with-param name="document-type">third-level-mainmatter-separate</xsl:with-param>
167   <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
168  </xsl:call-template>
169 </xsl:template>
170
171 <!-- :::::::::::: fourth-level main matter sections :::::::::::: -->
172
173 <xsl:template match="/gamebook/section/data/section/data/section/data/section[@class='mainmatter']">
174  <h4><xsl:value-of select="meta/title[1]" /></h4>
175
176  <xsl:value-of select="$newline" />
177  <xsl:value-of select="$newline" />
178
179  <xsl:apply-templates />
180 </xsl:template>
181
182 <!-- ::::::::::::: fifth-level main matter sections :::::::::::: -->
183
184 <xsl:template match="/gamebook/section/data/section/data/section/data/section/data/section[@class='mainmatter']">
185  <h5><xsl:value-of select="meta/title[1]" /></h5>
186
187  <xsl:value-of select="$newline" />
188  <xsl:value-of select="$newline" />
189
190  <xsl:apply-templates />
191 </xsl:template>
192
193 <!-- :::::::::::: second-level glossary sections ::::::::::::: -->
194
195 <xsl:template match="/gamebook/section/data/section[@class='glossary']">
196  <xsl:call-template name="xhtml-wrapper">
197   <xsl:with-param name="document-type">second-level-glossary</xsl:with-param>
198   <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
199   <xsl:with-param name="glossary-id-prefix">topics</xsl:with-param>
200  </xsl:call-template>
201 </xsl:template>
202
203 <!-- :::::::::::: third-level glossary sections ::::::::::::: -->
204 <!-- glossary sections should be enclosed in a second level glossary section -->
205
206 <xsl:template match="/gamebook/section/data/section/data/section[@class='glossary']">
207  <h3><xsl:value-of select="meta/title[1]" /></h3>
208
209  <xsl:value-of select="$newline" />
210  <xsl:value-of select="$newline" />
211
212  <xsl:apply-templates />
213 </xsl:template>
214
215 <xsl:template match="/gamebook/section/data/section/data/section[@class='glossary-separate']">
216  <xsl:call-template name="xhtml-wrapper">
217   <xsl:with-param name="document-type">third-level-glossary-separate</xsl:with-param>
218   <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
219   <xsl:with-param name="glossary-id-prefix">topics</xsl:with-param>
220  </xsl:call-template>
221 </xsl:template>
222
223 <!-- :::::::::::::::::: numbered sections ::::::::::::::::::::::: -->
224
225 <xsl:template match="/gamebook/section/data/section[@class='numbered']">
226  <xsl:call-template name="xhtml-wrapper">
227   <xsl:with-param name="document-type">second-level-numbered</xsl:with-param>
228   <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
229  </xsl:call-template>
230
231  <xsl:apply-templates />
232 </xsl:template>
233
234 <xsl:template match="/gamebook/section/data/section/data/section[@class='numbered']">
235  <xsl:call-template name="xhtml-wrapper">
236   <xsl:with-param name="document-type">third-level-numbered</xsl:with-param>
237   <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
238  </xsl:call-template>
239 </xsl:template>
240
241 <!-- :::::::::::: second-level backmatter sections :::::::::::::: -->
242
243 <xsl:template match="/gamebook/section/data/section[@class='backmatter']">
244  <xsl:call-template name="xhtml-wrapper">
245   <xsl:with-param name="document-type">second-level-backmatter</xsl:with-param>
246   <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
247  </xsl:call-template>
248 </xsl:template>
249
250 <!-- ::::::::::::: third-level back matter sections ::::::::::::: -->
251
252 <xsl:template match="/gamebook/section/data/section/data/section[@class='backmatter']">
253  <h3><xsl:value-of select="meta/title[1]" /></h3>
254
255  <xsl:value-of select="$newline" />
256  <xsl:value-of select="$newline" />
257
258  <xsl:apply-templates />
259 </xsl:template>
260
261 <!-- ::::::::::::: fourth-level back matter sections ::::::::::::: -->
262
263 <xsl:template match="/gamebook/section/data/section/data/section/data/section[@class='backmatter']">
264  <h4><xsl:value-of select="meta/title[1]" /></h4>
265
266  <xsl:value-of select="$newline" />
267  <xsl:value-of select="$newline" />
268
269  <xsl:apply-templates />
270 </xsl:template>
271
272 <!-- ::::::::::::::::::::: map template ::::::::::::::::::::::::: -->
273
274 <xsl:template match="id( 'map' )">
275  <xsl:call-template name="xhtml-wrapper">
276   <xsl:with-param name="document-type">map-adjusted</xsl:with-param>
277   <xsl:with-param name="filename"><xsl:value-of select="@id" /></xsl:with-param>
278  </xsl:call-template>
279
280  <xsl:call-template name="xhtml-wrapper">
281   <xsl:with-param name="document-type">map</xsl:with-param>
282   <xsl:with-param name="filename"><xsl:value-of select="@id" /><xsl:text>large</xsl:text></xsl:with-param>
283  </xsl:call-template>
284 </xsl:template>
285
286 <!-- ==================== block elements ======================== -->
287
288 <xsl:template match="p">
289  <p><xsl:apply-templates /></p>
290  <xsl:value-of select="$newline" />
291 </xsl:template>
292
293 <xsl:template match="p[@class='dedication']">
294  <p class="dedication"><xsl:apply-templates /></p>
295  <xsl:value-of select="$newline" />
296 </xsl:template>
297
298 <xsl:template match="dl[@class='paragraphed']/dd/node() | ol[@class='paragraphed']/li/node() | ul[@class='paragraphed']/li/node()">
299  <xsl:choose>
300   <xsl:when test="self::p">
301    <xsl:apply-templates /><br /><br /><xsl:value-of select="$newline" />
302   </xsl:when>
303   <xsl:when test="self::dl">
304    <dl><xsl:value-of select="$newline" />
305     <xsl:apply-templates />
306    </dl><br /><br /><xsl:value-of select="$newline" />
307   </xsl:when>
308   <xsl:when test="self::ol">
309    <ol><xsl:value-of select="$newline" />
310     <xsl:apply-templates />
311    </ol><br /><br /><xsl:value-of select="$newline" />
312   </xsl:when>
313   <xsl:when test="self::ul">
314    <ul>
315     <xsl:if test="self::*[@class='unbulleted']"><xsl:attribute name="class"><xsl:text>unbulleted</xsl:text></xsl:attribute></xsl:if>
316     <xsl:value-of select="$newline" />
317     <xsl:apply-templates />
318    </ul><br /><br /><xsl:value-of select="$newline" />
319   </xsl:when>
320   <xsl:when test="self::blockquote">
321    <blockquote><xsl:value-of select="$newline" />
322     <xsl:apply-templates />
323    </blockquote><xsl:value-of select="$newline" />
324   </xsl:when>
325   <xsl:when test="self::illustration">
326    <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
327    <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
328    <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
329
330    <xsl:if test="instance[@class='pdaxhtml']">
331     <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
332      <p><img src="{$illustration-src}" width="{$illustration-width}" height="{$illustration-height}" border="0" align="middle" alt="[illustration]" /></p><xsl:value-of select="$newline" />
333     </div></div><xsl:value-of select="$newline" />
334    </xsl:if>
335   </xsl:when>
336   <xsl:otherwise>
337    <xsl:text>[error: paragraphed list template]</xsl:text>
338   </xsl:otherwise>
339  </xsl:choose>
340 </xsl:template>
341
342 <xsl:template match="ol">
343  <ol><xsl:value-of select="$newline" />
344   <xsl:apply-templates />
345  </ol><xsl:value-of select="$newline" />
346 </xsl:template>
347
348 <xsl:template match="ul">
349  <ul>
350   <xsl:if test="self::*[@class='unbulleted']"><xsl:attribute name="class"><xsl:text>unbulleted</xsl:text></xsl:attribute></xsl:if>
351   <xsl:value-of select="$newline" />
352   <xsl:apply-templates />
353  </ul><xsl:value-of select="$newline" />
354 </xsl:template>
355
356 <xsl:template match="dl">
357  <dl><xsl:value-of select="$newline" />
358   <xsl:apply-templates />
359  </dl><xsl:value-of select="$newline" />
360 </xsl:template>
361
362 <xsl:template match="dt">
363  <dt><xsl:apply-templates /></dt>
364  <xsl:value-of select="$newline" />
365 </xsl:template>
366
367 <xsl:template match="dd">
368  <dd><xsl:apply-templates /></dd>
369  <xsl:value-of select="$newline" />
370 </xsl:template>
371
372 <xsl:template match="li">
373  <li><xsl:apply-templates /></li>
374  <xsl:value-of select="$newline" />
375 </xsl:template>
376
377 <xsl:template match="table">
378  <table border="1" cellspacing="0" cellpadding="2">
379   <xsl:apply-templates />
380  </table>
381  <xsl:value-of select="$newline" />
382 </xsl:template>
383
384 <xsl:template match="tr">
385  <tr>
386   <xsl:apply-templates />
387  </tr>
388 </xsl:template>
389
390 <xsl:template match="th">
391  <th>
392   <xsl:if test="@align"><xsl:attribute name="align"><xsl:value-of select="@align" /></xsl:attribute></xsl:if>
393   <xsl:if test="@valign"><xsl:attribute name="valign"><xsl:value-of select="@valign" /></xsl:attribute></xsl:if>
394   <xsl:if test="@char"><xsl:attribute name="char"><xsl:value-of select="@char" /></xsl:attribute></xsl:if>
395   <xsl:apply-templates />
396  </th>
397 </xsl:template>
398
399 <xsl:template match="td">
400  <td>
401   <xsl:if test="@align"><xsl:attribute name="align"><xsl:value-of select="@align" /></xsl:attribute></xsl:if>
402   <xsl:if test="@valign"><xsl:attribute name="valign"><xsl:value-of select="@valign" /></xsl:attribute></xsl:if>
403   <xsl:if test="@char"><xsl:attribute name="char"><xsl:value-of select="@char" /></xsl:attribute></xsl:if>
404   <xsl:apply-templates />
405  </td>
406 </xsl:template>
407
408 <xsl:template match="combat">
409  <p class="combat">
410   <xsl:apply-templates select="enemy" />
411   <xsl:text>: </xsl:text>
412   <xsl:choose>
413    <xsl:when test="enemy-attribute[@class='combatskill']">
414     <span class="smallcaps">COMBAT<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>SKILL</span>
415     <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
416     <xsl:value-of select="enemy-attribute[@class='combatskill']" />
417    </xsl:when>
418    <xsl:when test="enemy-attribute[@class='closecombatskill']">
419     <span class="smallcaps">CLOSE<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>COMBAT<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>SKILL</span>
420     <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
421     <xsl:value-of select="enemy-attribute[@class='closecombatskill']" />
422    </xsl:when>
423   </xsl:choose>
424   <xsl:text disable-output-escaping="yes"> &amp;nbsp;&amp;nbsp;</xsl:text>
425   <span class="smallcaps">ENDURANCE</span>
426   <xsl:choose>
427    <xsl:when test="enemy-attribute[@class='target']">
428     <xsl:text>(</xsl:text><span class="smallcaps">TARGET</span><xsl:text> points)</xsl:text>
429     <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
430     <xsl:value-of select="enemy-attribute[@class='target']" />
431    </xsl:when>
432    <xsl:when test="enemy-attribute[@class='resistance']">
433     <xsl:text>(</xsl:text><span class="smallcaps">RESISTANCE</span><xsl:text> points)</xsl:text>
434     <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
435     <xsl:value-of select="enemy-attribute[@class='resistance']" />
436    </xsl:when>
437    <xsl:otherwise>
438     <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
439     <xsl:value-of select="enemy-attribute[@class='endurance']" />
440    </xsl:otherwise>
441   </xsl:choose>
442  </p>
443  <xsl:value-of select="$newline" />
444 </xsl:template>
445
446 <xsl:template match="choice">
447  <xsl:variable name="link">
448   <xsl:value-of select="@idref" />
449  </xsl:variable>
450
451  <p class="choice">
452   <xsl:for-each select="* | text()">
453    <xsl:choose>
454     <xsl:when test="self::link-text">
455      <a href="{$link}.htm">
456       <xsl:apply-templates />
457      </a>
458     </xsl:when>
459     <xsl:otherwise>
460      <xsl:apply-templates select="." />
461     </xsl:otherwise>
462    </xsl:choose>
463   </xsl:for-each>
464  </p>
465  <xsl:value-of select="$newline" />
466 </xsl:template>
467
468 <xsl:template match="signpost">
469  <div class="signpost">
470   <xsl:apply-templates />
471  </div>
472  <xsl:value-of select="$newline" />
473 </xsl:template>
474
475 <xsl:template match="blockquote">
476  <blockquote><xsl:value-of select="$newline" />
477   <xsl:apply-templates /><xsl:value-of select="$newline" />
478  </blockquote><xsl:value-of select="$newline" />
479 </xsl:template>
480
481 <xsl:template match="illustration">
482  <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
483  <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
484  <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
485
486  <xsl:variable name="illustration-width-adjusted"><xsl:number value="$illustration-width div 2" /></xsl:variable>
487  <xsl:variable name="illustration-height-adjusted"><xsl:number value="$illustration-height div 2" /></xsl:variable>
488
489  <xsl:if test="instance[@class='pdaxhtml']">
490   <xsl:choose>
491    <xsl:when test="@class='float'">
492     <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
493      <p>
494       <a>
495        <xsl:attribute name="href"><xsl:text>ill</xsl:text><xsl:number count="illustration[@class='float']" from="/" level="any" format="1" /><xsl:text>.htm</xsl:text></xsl:attribute>
496        <img src="{$illustration-src}" width="{$illustration-width-adjusted}" height="{$illustration-height-adjusted}" border="0" align="middle" alt="[illustration]" />
497       </a>
498      </p><xsl:value-of select="$newline" />
499     </div></div><xsl:value-of select="$newline" />
500
501     <xsl:call-template name="xhtml-wrapper">
502      <xsl:with-param name="document-type">illustration</xsl:with-param>
503      <xsl:with-param name="filename"><xsl:text>ill</xsl:text><xsl:number count="illustration[@class='float']" from="/" level="any" format="1" /></xsl:with-param>
504     </xsl:call-template>
505    </xsl:when>
506
507    <xsl:otherwise>
508     <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
509      <p><img src="{$illustration-src}" width="{$illustration-width}" height="{$illustration-height}" border="0" align="middle" alt="[illustration]" /></p><xsl:value-of select="$newline" />
510     </div></div><xsl:value-of select="$newline" />
511    </xsl:otherwise>
512   </xsl:choose>
513
514  </xsl:if>
515 </xsl:template>
516
517 <xsl:template match="instance" />
518
519 <xsl:template match="footnotes" />
520
521 <xsl:template match="footnote" />
522
523 <xsl:template match="hr">
524  <hr />
525  <xsl:value-of select="$newline" />
526 </xsl:template>
527
528 <!-- ==================== inline elements ======================= -->
529
530 <xsl:template match="a">
531  <xsl:choose>
532   <xsl:when test="@href">
533    <a>
534     <xsl:attribute name="href"><xsl:value-of select="@href" /></xsl:attribute>
535     <xsl:if test="@id"><xsl:attribute name="name"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>
536     <xsl:apply-templates />
537    </a>
538   </xsl:when>
539   <xsl:otherwise>
540    <a>
541     <xsl:if test="@idref">
542      <xsl:variable name="my-idref" select="@idref" />
543      <xsl:attribute name="href">
544       <xsl:choose>
545        <!-- The order of these tests is deliberate. They are ordered roughly from most to least specific. -->
546        <xsl:when test="/gamebook/section[@id=$my-idref] | /gamebook/section/data/section[@id=$my-idref]">
547         <xsl:value-of select="$my-idref" /><xsl:text>.htm</xsl:text>
548        </xsl:when>
549        <xsl:when test="/gamebook/section/data/section/data/section[@class='frontmatter-separate' and @id=$my-idref]">
550         <xsl:value-of select="$my-idref" /><xsl:text>.htm</xsl:text>
551        </xsl:when>
552        <xsl:when test="/gamebook/section/data/section/data/section[@class='mainmatter-separate' and @id=$my-idref]">
553         <xsl:value-of select="$my-idref" /><xsl:text>.htm</xsl:text>
554        </xsl:when>
555        <xsl:when test="/gamebook/section/data/section/data/section[@class='numbered' and @id=$my-idref]">
556         <xsl:value-of select="$my-idref" /><xsl:text>.htm</xsl:text>
557        </xsl:when>
558        <xsl:when test="/gamebook/section/data/section/data/section[@class='glossary-separate' and @id=$my-idref]">
559         <xsl:value-of select="$my-idref" /><xsl:text>.htm</xsl:text>
560        </xsl:when>
561        <xsl:when test="/gamebook/section/data/section/data/section[@class='frontmatter-separate' and descendant::*[@id=$my-idref]]">
562         <xsl:value-of select="/gamebook/section/data/section/data/section[@class='frontmatter-separate' and descendant::*[@id=$my-idref]]/@id" /><xsl:text>.htm#</xsl:text><xsl:value-of select="$my-idref" />
563        </xsl:when>
564        <xsl:when test="/gamebook/section/data/section/data/section[@class='mainmatter-separate' and descendant::*[@id=$my-idref]]">
565         <xsl:value-of select="/gamebook/section/data/section/data/section[@class='mainmatter-separate' and descendant::*[@id=$my-idref]]/@id" /><xsl:text>.htm#</xsl:text><xsl:value-of select="$my-idref" />
566        </xsl:when>
567        <xsl:when test="/gamebook/section/data/section/data/section[@class='glossary-separate' and descendant::*[@id=$my-idref]]">
568         <xsl:value-of select="/gamebook/section/data/section/data/section[@class='glossary-separate' and descendant::*[@id=$my-idref]]/@id" /><xsl:text>.htm#</xsl:text><xsl:value-of select="$my-idref" />
569        </xsl:when>
570        <xsl:when test="/gamebook/section/data/section[descendant::*[@id=$my-idref]]">
571         <xsl:value-of select="/gamebook/section/data/section[descendant::*[@id=$my-idref]]/@id" /><xsl:text>.htm#</xsl:text><xsl:value-of select="$my-idref" />
572        </xsl:when>
573        <xsl:otherwise>
574         <xsl:text>[error: "a" template]</xsl:text>
575        </xsl:otherwise>
576       </xsl:choose>
577      </xsl:attribute>
578     </xsl:if>
579     <xsl:if test="@id"><xsl:attribute name="name"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>
580     <xsl:apply-templates />
581    </a>
582   </xsl:otherwise>
583  </xsl:choose>
584 </xsl:template>
585
586 <xsl:template match="a[@class='footnote']">
587  <xsl:apply-templates />
588  <sup>
589   <a>
590    <xsl:attribute name="href"><xsl:text>#</xsl:text><xsl:value-of select="@idref" /></xsl:attribute>
591    <xsl:attribute name="name"><xsl:value-of select="@id" /></xsl:attribute>
592    <xsl:number count="a[@class='footnote']" from="/" level="any" format="1" />
593   </a>
594  </sup>
595 </xsl:template>
596
597 <xsl:template match="em">
598  <em><xsl:apply-templates /></em>
599 </xsl:template>
600
601 <xsl:template match="strong">
602  <strong><xsl:apply-templates /></strong>
603 </xsl:template>
604
605 <xsl:template match="thought">
606  <i><xsl:apply-templates /></i>
607 </xsl:template>
608
609 <xsl:template match="onomatopoeia">
610  <i><xsl:apply-templates /></i>
611 </xsl:template>
612
613 <xsl:template match="spell">
614  <i><xsl:apply-templates /></i>
615 </xsl:template>
616
617 <xsl:template match="item">
618  <xsl:apply-templates />
619 </xsl:template>
620
621 <xsl:template match="foreign">
622  <i><xsl:apply-templates /></i>
623 </xsl:template>
624
625 <xsl:template match="quote">
626  <xsl:text>&apos;</xsl:text>
627   <xsl:apply-templates />
628  <xsl:if test="not(self::*[@class='open-ended'])"><xsl:text>&apos;</xsl:text></xsl:if>
629 </xsl:template>
630
631 <xsl:template match="quote//quote">
632  <xsl:text>&quot;</xsl:text>
633   <xsl:apply-templates />
634  <xsl:if test="not(self::*[@class='open-ended'])"><xsl:text>&quot;</xsl:text></xsl:if>
635 </xsl:template>
636
637 <xsl:template match="cite">
638  <cite><xsl:apply-templates /></cite>
639 </xsl:template>
640
641 <xsl:template match="code">
642  <tt><xsl:apply-templates /></tt>
643 </xsl:template>
644
645 <xsl:template match="br">
646  <br />
647 </xsl:template>
648
649 <xsl:template match="typ[@class='attribute']">
650  <span class="smallcaps"><xsl:apply-templates /></span>
651 </xsl:template>
652
653 <!-- ==================== named templates ======================= -->
654
655 <xsl:template name="xhtml-wrapper">
656  <xsl:param name="document-type">undefined</xsl:param>
657  <xsl:param name="filename">undefined</xsl:param>
658  <xsl:param name="glossary-id-prefix"></xsl:param>
659
660  <redirect:write file="{$book-path}/{$filename}.htm">
661   <xsl:fallback>
662    <xsl:text>xhtml-wrapper: Cannot write to filename: "</xsl:text>
663    <xsl:value-of select="$filename" /><xsl:text>.htm"</xsl:text>
664   </xsl:fallback>
665
666   <xsl:comment>
667    <xsl:text> </xsl:text>
668    <xsl:apply-templates select="/gamebook/meta/rights[@class='copyrights']" />
669    <xsl:text> Published by </xsl:text>
670    <xsl:value-of select="/gamebook/meta/publisher[1]" />
671    <xsl:text>. </xsl:text>
672   </xsl:comment>
673   <xsl:value-of select="$newline" />
674
675   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-UK" lang="en-UK">
676
677    <xsl:value-of select="$newline" />
678    <xsl:value-of select="$newline" />
679
680    <head><xsl:value-of select="$newline" />
681     <title>
682      <xsl:value-of select="/gamebook/meta/title[1]" />
683      <xsl:text>: </xsl:text>
684      <xsl:choose>
685       <xsl:when test="$document-type='illustration'">
686        <xsl:text>Illustration </xsl:text>
687        <xsl:number count="illustration[@class='float']" from="/" level="any" format="I" />
688       </xsl:when>
689       <xsl:otherwise><xsl:value-of select="meta/title[1]" /></xsl:otherwise>
690      </xsl:choose>
691     </title><xsl:value-of select="$newline" />
692     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><xsl:value-of select="$newline" />
693     <meta name="robots" content="noindex,nofollow" /><xsl:value-of select="$newline" />
694     <link rel="stylesheet" href="main.css" type="text/css" /><xsl:value-of select="$newline" />
695    </head>
696
697    <xsl:value-of select="$newline" />
698    <xsl:value-of select="$newline" />
699
700    <body>
701     <xsl:attribute name="text"><xsl:value-of select="$text-color" /></xsl:attribute>
702     <xsl:attribute name="bgcolor"><xsl:value-of select="$background-color" /></xsl:attribute>
703     <xsl:attribute name="background"><xsl:text>bckgrnd.gif</xsl:text></xsl:attribute>
704     <xsl:attribute name="link"><xsl:value-of select="$link-color" /></xsl:attribute>
705     <xsl:attribute name="alink"><xsl:value-of select="$alink-color" /></xsl:attribute>
706     <xsl:attribute name="vlink"><xsl:value-of select="$vlink-color" /></xsl:attribute>
707
708     <xsl:value-of select="$newline" />
709     <h1><xsl:value-of select="/gamebook/meta/title[1]" /></h1><xsl:value-of select="$newline" />
710     <div id="body"><xsl:value-of select="$newline" />
711
712      <xsl:choose>
713
714 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~ top-level ~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
715
716       <xsl:when test="$document-type='top-level'">
717        <div class="frontmatter"><xsl:value-of select="$newline" />
718         <p class="author"><xsl:apply-templates select="/gamebook/meta/creator[@class='medium']" /></p>
719
720         <xsl:apply-templates select="/gamebook/meta/description[@class='publication']" />
721
722         <p>
723          <xsl:text>Publication Date: </xsl:text>
724          <xsl:value-of select="/gamebook/meta/date[@class='publication']/day" />
725          <xsl:text> </xsl:text>
726          <xsl:choose>
727           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 1">
728            <xsl:text>January</xsl:text>
729           </xsl:when>
730           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 2">
731            <xsl:text>February</xsl:text>
732           </xsl:when>
733           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 3">
734            <xsl:text>March</xsl:text>
735           </xsl:when>
736           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 4">
737            <xsl:text>April</xsl:text>
738           </xsl:when>
739           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 5">
740            <xsl:text>May</xsl:text>
741           </xsl:when>
742           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 6">
743            <xsl:text>June</xsl:text>
744           </xsl:when>
745           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 7">
746            <xsl:text>July</xsl:text>
747           </xsl:when>
748           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 8">
749            <xsl:text>August</xsl:text>
750           </xsl:when>
751           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 9">
752            <xsl:text>September</xsl:text>
753           </xsl:when>
754           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 10">
755            <xsl:text>October</xsl:text>
756           </xsl:when>
757           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 11">
758            <xsl:text>November</xsl:text>
759           </xsl:when>
760           <xsl:when test="/gamebook/meta/date[@class='publication']/month = 12">
761            <xsl:text>December</xsl:text>
762           </xsl:when>
763           <xsl:otherwise>
764            <xsl:text>Invalid Month</xsl:text>
765           </xsl:otherwise>
766          </xsl:choose>
767          <xsl:text> </xsl:text>
768          <xsl:value-of select="/gamebook/meta/date[@class='publication']/year" />
769         </p>
770
771         <xsl:apply-templates select="/gamebook/meta/rights[@class='license-notification']" />
772
773         <hr />
774
775         <xsl:apply-templates select="/gamebook/meta/description[@class='blurb']" />
776         <xsl:apply-templates select="/gamebook/meta/creator[@class='long']" />
777
778         <xsl:value-of select="$newline" />
779
780         <xsl:call-template name="navigation-bar" />
781
782         <xsl:value-of select="$newline" />
783        </div><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
784
785       </xsl:when>
786
787 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ toc ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
788
789       <xsl:when test="$document-type='toc'">
790        <div class="frontmatter"><xsl:value-of select="$newline" />
791         <h2>Table of Contents</h2><xsl:value-of select="$newline" />
792
793         <xsl:value-of select="$newline" />
794         <xsl:value-of select="$newline" />
795
796         <ul><xsl:value-of select="$newline" />
797          <li>
798           <a><xsl:attribute name="href"><xsl:value-of select="@id" /><xsl:text>.htm</xsl:text></xsl:attribute>
799            <xsl:value-of select="meta/title[1]" />
800           </a>
801          </li>
802          <xsl:for-each select="data/section">
803           <li>
804            <a><xsl:attribute name="href"><xsl:value-of select="@id" /><xsl:text>.htm</xsl:text></xsl:attribute>
805             <xsl:value-of select="meta/title[1]" />
806            </a>
807            <xsl:if test="data/section[@class='frontmatter-separate' or @class='mainmatter-separate']">
808             <xsl:value-of select="$newline" />
809             <ul><xsl:value-of select="$newline" />
810              <xsl:for-each select="data/section[@class='frontmatter-separate' or @class='mainmatter-separate']">
811               <li>
812                <a><xsl:attribute name="href"><xsl:value-of select="@id" /><xsl:text>.htm</xsl:text></xsl:attribute>
813                 <xsl:value-of select ="meta/title[1]" />
814                </a>
815               </li><xsl:value-of select="$newline" />
816              </xsl:for-each>
817             </ul><xsl:value-of select="$newline" />
818            </xsl:if>
819           </li><xsl:value-of select="$newline" />
820          </xsl:for-each>
821         </ul><xsl:value-of select="$newline" />
822
823         <xsl:value-of select="$newline" />
824         <xsl:value-of select="$newline" />
825         <xsl:call-template name="navigation-bar" />
826        </div><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
827       </xsl:when>
828
829 <!-- ~~~~~~~~~~~~~~~~ second-level-frontmatter ~~~~~~~~~~~~~~~~~~~ -->
830
831       <xsl:when test="$document-type='second-level-frontmatter'">
832        <div class="frontmatter"><xsl:value-of select="$newline" />
833         <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
834
835         <xsl:value-of select="$newline" />
836
837         <xsl:apply-templates />
838
839         <xsl:value-of select="$newline" />
840
841         <xsl:call-template name="navigation-bar" />
842
843        </div><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
844       </xsl:when>
845
846 <!-- ~~~~~~~~~~~~~ third-level-frontmatter-separate ~~~~~~~~~~~~~~ -->
847
848       <xsl:when test="$document-type='third-level-frontmatter-separate'">
849        <div class="frontmatter"><xsl:value-of select="$newline" />
850         <h3><xsl:value-of select="meta/title" /></h3><xsl:value-of select="$newline" />
851         <xsl:value-of select="$newline" />
852
853         <xsl:apply-templates />
854
855         <xsl:value-of select="$newline" />
856
857         <xsl:call-template name="navigation-bar" />
858
859        </div><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
860       </xsl:when>
861
862 <!-- ~~~~~~~~~~~~~~~~ second-level-mainmatter ~~~~~~~~~~~~~~~~~~~ -->
863
864       <xsl:when test="$document-type='second-level-mainmatter'">
865        <div class="mainmatter"><xsl:value-of select="$newline" />
866         <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
867         <xsl:value-of select="$newline" />
868
869         <xsl:apply-templates />
870
871         <xsl:value-of select="$newline" />
872
873         <xsl:call-template name="navigation-bar" />
874
875        </div><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
876       </xsl:when>
877
878 <!-- ~~~~~~~~~~~~~ third-level-mainmatter-separate ~~~~~~~~~~~~~~ -->
879
880       <xsl:when test="$document-type='third-level-mainmatter-separate'">
881        <div class="mainmatter"><xsl:value-of select="$newline" />
882         <h3><xsl:value-of select="meta/title" /></h3><xsl:value-of select="$newline" />
883         <xsl:value-of select="$newline" />
884
885         <xsl:apply-templates />
886
887         <xsl:value-of select="$newline" />
888
889         <xsl:call-template name="navigation-bar" />
890
891        </div><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
892       </xsl:when>
893
894 <!-- ~~~~~~~~~~~~~~~~ second-level-glossary ~~~~~~~~~~~~~~~~~~~ -->
895
896       <xsl:when test="$document-type='second-level-glossary'">
897        <div class="mainmatter"><xsl:value-of select="$newline" />
898         <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
899         <xsl:value-of select="$newline" />
900
901         <xsl:apply-templates />
902
903         <xsl:value-of select="$newline" />
904
905         <xsl:call-template name="alpha-bar">
906          <xsl:with-param name="alpha-bar-id-prefix"><xsl:value-of select="$glossary-id-prefix" /></xsl:with-param>
907         </xsl:call-template>
908
909         <xsl:call-template name="navigation-bar" />
910
911        </div><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
912       </xsl:when>
913
914 <!-- ~~~~~~~~~~~~~ third-level-glossary-separate ~~~~~~~~~~~~~~ -->
915
916       <xsl:when test="$document-type='third-level-glossary-separate'">
917        <div class="glossary"><xsl:value-of select="$newline" />
918         <h3><xsl:value-of select="meta/title" /></h3><xsl:value-of select="$newline" />
919         <xsl:call-template name="alpha-bar">
920          <xsl:with-param name="alpha-bar-id-prefix"><xsl:value-of select="$glossary-id-prefix" /></xsl:with-param>
921         </xsl:call-template>
922
923         <xsl:value-of select="$newline" />
924
925         <xsl:apply-templates />
926
927         <xsl:value-of select="$newline" />
928
929         <xsl:call-template name="navigation-bar" />
930         <xsl:value-of select="$newline" />
931        </div><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
932       </xsl:when>
933
934 <!-- ~~~~~~~~~~~~~~~~~~ second-level-numbered ~~~~~~~~~~~~~~~~~~~~ -->
935
936       <xsl:when test="$document-type='second-level-numbered'">
937        <div class="frontmatter"><xsl:value-of select="$newline" />
938         <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
939         <xsl:value-of select="$newline" />
940
941         <p>
942          <xsl:for-each select="data/section">
943           <xsl:if test="position() mod 50 = 1">
944            <a>
945             <xsl:attribute name="href"><xsl:text>#</xsl:text><xsl:value-of select="position()" /></xsl:attribute>
946             <xsl:value-of select="position()" /><xsl:text> - </xsl:text>
947             <xsl:choose>
948              <xsl:when test="position() + 49 &lt;= last()">
949               <xsl:value-of select="position() + 49" />
950              </xsl:when>
951              <xsl:otherwise>
952               <xsl:value-of select="last()" />
953              </xsl:otherwise>
954             </xsl:choose>
955            </a><br /><xsl:value-of select="$newline" />
956           </xsl:if>
957          </xsl:for-each>
958         </p>
959
960         <xsl:value-of select="$newline" />
961         <xsl:value-of select="$newline" />
962
963         <hr />
964
965         <xsl:value-of select="$newline" />
966         <xsl:value-of select="$newline" />
967
968         <xsl:for-each select="data/section">
969          <xsl:if test="position() mod 10 = 1">
970           <h3>
971            <a>
972             <xsl:attribute name="name"><xsl:value-of select="position()" /></xsl:attribute>
973             <xsl:value-of select="position()" /><xsl:text> - </xsl:text>
974             <xsl:choose>
975              <xsl:when test="position() + 9 &lt;= last()">
976               <xsl:value-of select="position() + 9" />
977              </xsl:when>
978              <xsl:otherwise>
979               <xsl:value-of select="last()" />
980              </xsl:otherwise>
981             </xsl:choose>
982            </a>
983           </h3><xsl:value-of select="$newline" />
984           <xsl:text disable-output-escaping="yes">&lt;p class="center"&gt;&lt;tt&gt;[</xsl:text>
985          </xsl:if>
986          <a>
987           <xsl:attribute name="href"><xsl:value-of select="@id" /><xsl:text>.htm</xsl:text></xsl:attribute>
988           <xsl:value-of select="meta/title[1]" />
989          </a>
990          <xsl:choose>
991           <xsl:when test="position() mod 10 = 0">
992            <xsl:text disable-output-escaping="yes">]&lt;/tt&gt;&lt;/p&gt;</xsl:text>
993            <xsl:value-of select="$newline" />
994            <xsl:value-of select="$newline" />
995           </xsl:when>
996           <xsl:otherwise>
997            <xsl:text>|</xsl:text>
998           </xsl:otherwise>
999          </xsl:choose>
1000         </xsl:for-each>
1001
1002         <xsl:value-of select="$newline" />
1003         <xsl:value-of select="$newline" />
1004
1005         <xsl:call-template name="navigation-bar" />
1006         <xsl:value-of select="$newline" />
1007        </div><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
1008       </xsl:when>
1009
1010 <!-- ~~~~~~~~~~~~~~~~~~ third-level-numbered ~~~~~~~~~~~~~~~~~~~~~ -->
1011
1012       <xsl:when test="$document-type='third-level-numbered'">
1013        <div class="numbered"><xsl:value-of select="$newline" />
1014         <h3><xsl:value-of select="meta/title" /></h3><xsl:value-of select="$newline" />
1015         <xsl:value-of select="$newline" />
1016
1017         <xsl:apply-templates />
1018
1019         <xsl:value-of select="$newline" />
1020         <xsl:call-template name="navigation-bar" />
1021         <xsl:value-of select="$newline" />
1022        </div>
1023       </xsl:when>
1024
1025 <!-- ~~~~~~~~~~~~~~~~~ second-level-backmatter ~~~~~~~~~~~~~~~~~~~ -->
1026
1027       <xsl:when test="$document-type='second-level-backmatter'">
1028        <div class="frontmatter"><xsl:value-of select="$newline" />
1029         <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
1030
1031         <xsl:value-of select="$newline" />
1032         <xsl:value-of select="$newline" />
1033
1034         <xsl:apply-templates />
1035
1036         <xsl:value-of select="$newline" />
1037
1038         <xsl:call-template name="navigation-bar" />
1039         <xsl:value-of select="$newline" />
1040        </div><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
1041       </xsl:when>
1042
1043 <!-- ~~~~~~~~~~~~~~~~~~~~~~~ map-adjusted ~~~~~~~~~~~~~~~~~~~~~~~~ -->
1044
1045       <xsl:when test="$document-type='map-adjusted'">
1046        <div class="frontmatter"><xsl:value-of select="$newline" />
1047         <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
1048
1049         <xsl:value-of select="$newline" />
1050         <xsl:value-of select="$newline" />
1051
1052         <xsl:for-each select="data/* | data/text()">
1053          <xsl:choose>
1054           <xsl:when test="self::illustration">
1055            <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
1056            <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
1057            <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
1058
1059            <xsl:variable name="illustration-width-adjusted"><xsl:number value="386" /></xsl:variable>
1060            <xsl:variable name="illustration-height-adjusted"><xsl:number value="$illustration-height * $illustration-width-adjusted div $illustration-width" /></xsl:variable>
1061
1062            <p>[map]</p>
1063
1064 <!--           <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
1065             <table border="0" cellpadding="0" cellspacing="0"><xsl:value-of select="$newline" />
1066              <tr><xsl:value-of select="$newline" />
1067               <td><img src="brdrtpl.gif" width="31" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1068               <td><img src="brdrtp.gif" width="{$illustration-width-adjusted}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1069               <td><img src="brdrtpr.gif" width="33" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1070              </tr><xsl:value-of select="$newline" />
1071              <tr><xsl:value-of select="$newline" />
1072               <td><img src="brdrl.gif" width="31" height="{$illustration-height-adjusted}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1073               <td><a href="maplarge.htm"><img src="{$illustration-src}" width="{$illustration-width-adjusted}" height="{$illustration-height-adjusted}" align="middle" border="0" alt="[map]" /></a></td><xsl:value-of select="$newline" />
1074               <td><img src="brdrr.gif" width="33" height="{$illustration-height-adjusted}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1075              </tr><xsl:value-of select="$newline" />
1076              <tr><xsl:value-of select="$newline" />
1077               <td><img src="brdrbtl.gif" width="31" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1078               <td><img src="brdrbt.gif" width="{$illustration-width-adjusted}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1079               <td><img src="brdrbtr.gif" width="33" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1080              </tr><xsl:value-of select="$newline" />
1081             </table><xsl:value-of select="$newline" />
1082             <br /><br />
1083            </div></div><xsl:value-of select="$newline" /> -->
1084           </xsl:when>
1085           <xsl:otherwise>
1086            <xsl:apply-templates select="." />
1087           </xsl:otherwise>
1088          </xsl:choose>
1089         </xsl:for-each>
1090
1091         <xsl:value-of select="$newline" />
1092
1093         <xsl:call-template name="navigation-bar" />
1094         <xsl:value-of select="$newline" />
1095        </div>
1096       </xsl:when>
1097
1098 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ map ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
1099
1100       <xsl:when test="$document-type='map'">
1101        <div class="frontmatter"><xsl:value-of select="$newline" />
1102         <h2><xsl:value-of select="meta/title" /></h2><xsl:value-of select="$newline" />
1103
1104         <xsl:value-of select="$newline" />
1105         <xsl:value-of select="$newline" />
1106
1107         <xsl:for-each select="data/* | data/text()">
1108          <xsl:choose>
1109           <xsl:when test="self::illustration">
1110            <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
1111            <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
1112            <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
1113
1114            <p>[map]</p>
1115
1116 <!--           <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
1117             <table border="0" cellpadding="0" cellspacing="0"><xsl:value-of select="$newline" />
1118              <tr><xsl:value-of select="$newline" />
1119               <td><img src="brdrtpl.gif" width="31" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1120               <td><img src="brdrtp.gif" width="{$illustration-width}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1121               <td><img src="brdrtpr.gif" width="33" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1122              </tr><xsl:value-of select="$newline" />
1123              <tr><xsl:value-of select="$newline" />
1124               <td><img src="brdrl.gif" width="31"  height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1125               <td><a href="map.htm"><img src="{$illustration-src}" width="{$illustration-width}" height="{$illustration-height}" align="middle" border="0" alt="[map]" /></a></td><xsl:value-of select="$newline" />
1126               <td><img src="brdrr.gif" width="33" height="{$illustration-height}" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1127              </tr><xsl:value-of select="$newline" />
1128              <tr><xsl:value-of select="$newline" />
1129               <td><img src="brdrbtl.gif" width="31" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1130               <td><img src="brdrbt.gif" width="{$illustration-width}" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1131               <td><img src="brdrbtr.gif" width="33" height="32" align="middle" alt="" /></td><xsl:value-of select="$newline" />
1132              </tr><xsl:value-of select="$newline" />
1133             </table><br /><xsl:value-of select="$newline" />
1134            </div></div><xsl:value-of select="$newline" />-->
1135           </xsl:when>
1136           <xsl:otherwise>
1137            <xsl:apply-templates select="." />
1138           </xsl:otherwise>
1139          </xsl:choose>
1140         </xsl:for-each>
1141
1142         <xsl:value-of select="$newline" />
1143
1144         <xsl:call-template name="navigation-bar" />
1145         <xsl:value-of select="$newline" />
1146        </div>
1147       </xsl:when>
1148
1149 <!-- ~~~~~~~~~~~~~~~~~~~~~~ illustration ~~~~~~~~~~~~~~~~~~~~~~~~~ -->
1150
1151       <xsl:when test="$document-type='illustration'">
1152        <xsl:variable name="illustration-width" select="instance[@class='html']/@width" />
1153        <xsl:variable name="illustration-height" select="instance[@class='html']/@height" />
1154        <xsl:variable name="illustration-src" select="instance[@class='html']/@src" />
1155
1156        <h3>
1157         <xsl:text>Illustration </xsl:text>
1158         <xsl:number count="illustration[@class='float']" from="/" level="any" format="I" />
1159        </h3><xsl:value-of select="$newline" />
1160
1161        <div class="illustration"><div align="center"><xsl:value-of select="$newline" />
1162         <p><img src="{$illustration-src}" width="{$illustration-width}" height="{$illustration-height}" align="middle" border="0" alt="[illustration]" /></p><xsl:value-of select="$newline" />
1163        </div></div><xsl:value-of select="$newline" />
1164        <p class="caption"><strong><xsl:apply-templates select="meta/description" /></strong></p><xsl:value-of select="$newline" />
1165       </xsl:when>
1166
1167 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~ error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
1168
1169       <xsl:otherwise>
1170        <xsl:message>
1171         <xsl:text>xhtml-wrapper: Cannot process document of type "</xsl:text>
1172         <xsl:value-of select="$document-type" />
1173         <xsl:text>".</xsl:text>
1174        </xsl:message>
1175        <p>
1176         <xsl:text>xhtml-wrapper: Cannot process document of type "</xsl:text>
1177         <xsl:value-of select="$document-type" />
1178         <xsl:text>".</xsl:text>
1179        </p>
1180       </xsl:otherwise>
1181
1182      </xsl:choose>
1183
1184 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~ footer ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
1185
1186      <xsl:call-template name="process-footnotes" />
1187
1188      <p class="copyright"><xsl:apply-templates select="/gamebook/meta/rights[@class='copyrights']" /></p><xsl:value-of select="$newline" /><xsl:value-of select="$newline" />
1189
1190     </div><xsl:value-of select="$newline" />
1191
1192     <map name="imagemap" id="imagemap">
1193      <area shape="rect" coords="0,0,99,99" href="http://www.projectaon.org/" alt="Project Aon" />
1194      <area shape="default" href="title.htm" alt="The Masters of Darkness" />
1195     </map>
1196
1197    </body>
1198
1199    <xsl:value-of select="$newline" />
1200    <xsl:value-of select="$newline" />
1201
1202   </html>
1203  </redirect:write>
1204
1205 </xsl:template>
1206
1207 <xsl:template name="process-footnotes">
1208  <xsl:if test="footnotes/footnote">
1209   <div id="footnotes"><xsl:value-of select="$newline" />
1210    <xsl:for-each select="footnotes/footnote">
1211     <xsl:variable name="footnote-idref" select="@idref" />
1212     <xsl:variable name="footnote-id" select="@id" />
1213     <xsl:variable name="footnote-marker"><xsl:number count="footnotes/footnote" from="/" level="any" format="1" /></xsl:variable>
1214
1215     <xsl:for-each select="*[1]">
1216      <p>
1217       <xsl:text>[</xsl:text>
1218        <a href="#{$footnote-idref}" name="{$footnote-id}"><xsl:value-of select="$footnote-marker" /></a>
1219       <xsl:text>] </xsl:text>
1220       <xsl:apply-templates select="child::* | child::text()" />
1221      </p>
1222     </xsl:for-each>
1223
1224     <xsl:for-each select="*[position() != 1]">
1225       <xsl:apply-templates select="." />
1226     </xsl:for-each>
1227    </xsl:for-each>
1228   </div><xsl:value-of select="$newline" />
1229  </xsl:if>
1230 </xsl:template>
1231
1232 <xsl:template name="navigation-bar">
1233  <div class="navigation">
1234   <table cellspacing="0" cellpadding="0" border="0">
1235    <tr>
1236     <td>
1237      <xsl:choose>
1238       <xsl:when test="meta/link[@class='prev']">
1239        <a>
1240         <xsl:attribute name="href">
1241          <xsl:value-of select="meta/link[@class='prev']/@idref" />
1242          <xsl:text>.htm</xsl:text>
1243         </xsl:attribute>
1244         <img src="back.gif" width="150" height="30" border="0">
1245          <xsl:attribute name="alt">
1246           <xsl:value-of select="id( meta/link[@class='prev']/@idref )/meta/title" />
1247          </xsl:attribute>
1248         </img>
1249        </a>
1250       </xsl:when>
1251       <xsl:otherwise>
1252        <img src="left.gif" width="150" height="30" border="0" alt="" />
1253       </xsl:otherwise>
1254      </xsl:choose>
1255     </td>
1256     <td><a href="toc.htm"><img src="toc.gif" width="150" height="30" border="0" alt="" /></a></td>
1257     <td>
1258      <xsl:choose>
1259       <xsl:when test="meta/link[@class='next']">
1260        <a>
1261         <xsl:attribute name="href">
1262          <xsl:value-of select="meta/link[@class='next']/@idref" />
1263          <xsl:text>.htm</xsl:text>
1264         </xsl:attribute>
1265         <img src="forward.gif" width="150" height="30" border="0">
1266          <xsl:attribute name="alt">
1267           <xsl:choose>
1268            <xsl:when test="$next-id = 'sect1'">
1269             <xsl:text>Section 1</xsl:text>
1270            </xsl:when>
1271            <xsl:otherwise>
1272             <xsl:value-of select="id( meta/link[@class='next']/@idref )/meta/title" />
1273            </xsl:otherwise>
1274           </xsl:choose>
1275          </xsl:attribute>
1276         </img>
1277        </a>
1278       </xsl:when>
1279       <xsl:otherwise>
1280        <img src="right.gif" width="150" height="30" border="0" alt="" />
1281       </xsl:otherwise>
1282      </xsl:choose>
1283     </td>
1284    </tr>
1285   </table>
1286  </div>
1287 </xsl:template>
1288
1289 <xsl:template name="alpha-bar">
1290  <xsl:param name="alpha-bar-id-prefix"></xsl:param>
1291
1292   <p class="navigation">[<a href="{$alpha-bar-id-prefix}a.htm">A</a>&nbsp;<a href="{$alpha-bar-id-prefix}b.htm">B</a>&nbsp;<a href="{$alpha-bar-id-prefix}c.htm">C</a>&nbsp;<a href="{$alpha-bar-id-prefix}d.htm">D</a>&nbsp;<a href="{$alpha-bar-id-prefix}e.htm">E</a>&nbsp;<a href="{$alpha-bar-id-prefix}f.htm">F</a>&nbsp;<a href="{$alpha-bar-id-prefix}g.htm">G</a>&nbsp;<a href="{$alpha-bar-id-prefix}h.htm">H</a>&nbsp;<a href="{$alpha-bar-id-prefix}i.htm">I</a>&nbsp;<a href="{$alpha-bar-id-prefix}j.htm">J</a>&nbsp;<a href="{$alpha-bar-id-prefix}k.htm">K</a>&nbsp;<a href="{$alpha-bar-id-prefix}l.htm">L</a>&nbsp;<a href="{$alpha-bar-id-prefix}m.htm">M</a>&nbsp;<a href="{$alpha-bar-id-prefix}n.htm">N</a>&nbsp;<a href="{$alpha-bar-id-prefix}o.htm">O</a>&nbsp;<a href="{$alpha-bar-id-prefix}p.htm">P</a>&nbsp;<a href="{$alpha-bar-id-prefix}q.htm">Q</a>&nbsp;<a href="{$alpha-bar-id-prefix}r.htm">R</a>&nbsp;<a href="{$alpha-bar-id-prefix}s.htm">S</a>&nbsp;<a href="{$alpha-bar-id-prefix}t.htm">T</a>&nbsp;<a href="{$alpha-bar-id-prefix}u.htm">U</a>&nbsp;<a href="{$alpha-bar-id-prefix}v.htm">V</a>&nbsp;<a href="{$alpha-bar-id-prefix}w.htm">W</a>&nbsp;<a href="{$alpha-bar-id-prefix}x.htm">X</a>&nbsp;<a href="{$alpha-bar-id-prefix}y.htm">Y</a>&nbsp;<a href="{$alpha-bar-id-prefix}z.htm">Z</a>]</p><xsl:value-of select="$newline" />
1293
1294 </xsl:template>
1295
1296 </xsl:transform>