1<?xml version="1.0"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4		xmlns:ng="http://docbook.org/docbook-ng"
5		xmlns:db="http://docbook.org/ns/docbook"
6                version="1.0"
7                exclude-result-prefixes="doc ng db">
8
9<xsl:import href="../html/chunk.xsl"/>
10
11<xsl:output method="html"/>
12
13<!-- ********************************************************************
14     $Id: javahelp.xsl,v 1.13 2006/04/14 19:20:59 kosek Exp $
15     ********************************************************************
16
17     This file is part of the XSL DocBook Stylesheet distribution.
18     See ../README or http://nwalsh.com/docbook/xsl/ for copyright
19     and other information.
20
21     ******************************************************************** -->
22
23<!-- ==================================================================== -->
24<xsl:param name="javahelp.encoding" select="'ISO-8859-1'"/>
25
26<doc:param name="javahelp.encoding" xmlns="">
27<refpurpose>Character encoding to use in control files for Java Help.</refpurpose>
28<refdescription>
29<para>Java Help crashes on some characters when written as character
30references. In that case you can select appropriate encoding here.</para>
31</refdescription>
32</doc:param>
33
34<!-- ==================================================================== -->
35
36<xsl:template match="/">
37  <xsl:choose>
38    <xsl:when test="$rootid != ''">
39      <xsl:choose>
40        <xsl:when test="count(key('id',$rootid)) = 0">
41          <xsl:message terminate="yes">
42            <xsl:text>ID '</xsl:text>
43            <xsl:value-of select="$rootid"/>
44            <xsl:text>' not found in document.</xsl:text>
45          </xsl:message>
46        </xsl:when>
47        <xsl:otherwise>
48          <xsl:message>Formatting from <xsl:value-of select="$rootid"/></xsl:message>
49          <xsl:apply-templates select="key('id',$rootid)" mode="process.root"/>
50        </xsl:otherwise>
51      </xsl:choose>
52    </xsl:when>
53    <xsl:otherwise>
54      <xsl:apply-templates select="/" mode="process.root"/>
55    </xsl:otherwise>
56  </xsl:choose>
57
58  <xsl:for-each select="/">    <!-- This is just a hook for building profiling stylesheets -->
59    <xsl:call-template name="helpset"/>
60    <xsl:call-template name="helptoc"/>
61    <xsl:call-template name="helpmap"/>
62    <xsl:call-template name="helpidx"/>
63  </xsl:for-each>
64</xsl:template>
65
66
67<xsl:template name="header.navigation">
68</xsl:template>
69
70<xsl:template name="footer.navigation">
71</xsl:template>
72
73<!-- ==================================================================== -->
74
75<xsl:template name="helpset">
76  <xsl:call-template name="write.chunk.with.doctype">
77    <xsl:with-param name="filename" select="concat($base.dir,'jhelpset.hs')"/>
78    <xsl:with-param name="method" select="'xml'"/>
79    <xsl:with-param name="indent" select="'yes'"/>
80    <xsl:with-param name="doctype-public" select="'-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN'"/>
81    <xsl:with-param name="doctype-system" select="'http://java.sun.com/products/javahelp/helpset_1_0.dtd'"/>
82    <xsl:with-param name="content">
83      <xsl:call-template name="helpset.content"/>
84    </xsl:with-param>
85  </xsl:call-template>
86</xsl:template>
87
88<xsl:template name="helpset.content">
89  <xsl:variable name="title">
90    <xsl:apply-templates select="." mode="title.markup"/>
91  </xsl:variable>
92
93  <helpset version="1.0">
94    <title>
95      <xsl:value-of select="$title"/>
96    </title>
97
98    <!-- maps -->
99    <maps>
100      <homeID>top</homeID>
101      <mapref location="jhelpmap.jhm"/>
102    </maps>
103
104    <!-- views -->
105    <view>
106      <name>TOC</name>
107      <label>Table Of Contents</label>
108      <type>javax.help.TOCView</type>
109      <data>jhelptoc.xml</data>
110    </view>
111
112    <view>
113      <name>Index</name>
114      <label>Index</label>
115      <type>javax.help.IndexView</type>
116      <data>jhelpidx.xml</data>
117    </view>
118
119    <view>
120      <name>Search</name>
121      <label>Search</label>
122      <type>javax.help.SearchView</type>
123      <data engine="com.sun.java.help.search.DefaultSearchEngine">JavaHelpSearch</data>
124    </view>
125  </helpset>
126</xsl:template>
127
128<!-- ==================================================================== -->
129
130<xsl:template name="helptoc">
131  <xsl:call-template name="write.chunk.with.doctype">
132    <xsl:with-param name="filename" select="concat($base.dir,'jhelptoc.xml')"/>
133    <xsl:with-param name="method" select="'xml'"/>
134    <xsl:with-param name="indent" select="'yes'"/>
135    <xsl:with-param name="doctype-public" select="'-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 1.0//EN'"/>
136    <xsl:with-param name="doctype-system" select="'http://java.sun.com/products/javahelp/toc_1_0.dtd'"/>
137    <xsl:with-param name="encoding" select="$javahelp.encoding"/>
138    <xsl:with-param name="content">
139      <xsl:call-template name="helptoc.content"/>
140    </xsl:with-param>
141  </xsl:call-template>
142</xsl:template>
143
144<xsl:template name="helptoc.content">
145  <toc version="1.0">
146    <xsl:choose>
147      <xsl:when test="$rootid != ''">
148        <xsl:apply-templates select="key('id',$rootid)" mode="jhtoc"/>
149      </xsl:when>
150      <xsl:otherwise>
151        <xsl:apply-templates select="." mode="jhtoc"/>
152      </xsl:otherwise>
153    </xsl:choose>
154  </toc>
155</xsl:template>
156
157<xsl:template match="set" mode="jhtoc">
158  <xsl:variable name="id">
159    <xsl:call-template name="object.id">
160      <xsl:with-param name="object" select="."/>
161    </xsl:call-template>
162  </xsl:variable>
163  <xsl:variable name="title">
164    <xsl:apply-templates select="." mode="title.markup"/>
165  </xsl:variable>
166
167  <tocitem target="{$id}">
168    <xsl:attribute name="text">
169      <xsl:value-of select="$title"/>
170    </xsl:attribute>
171    <xsl:apply-templates select="book" mode="jhtoc"/>
172  </tocitem>
173</xsl:template>
174
175<xsl:template match="book" mode="jhtoc">
176  <xsl:variable name="id">
177    <xsl:call-template name="object.id"/>
178  </xsl:variable>
179  <xsl:variable name="title">
180    <xsl:apply-templates select="." mode="title.markup"/>
181  </xsl:variable>
182
183  <tocitem target="{$id}">
184    <xsl:attribute name="text">
185      <xsl:value-of select="$title"/>
186    </xsl:attribute>
187    <xsl:apply-templates select="part|reference|preface|chapter|appendix|article|colophon"
188                         mode="jhtoc"/>
189  </tocitem>
190</xsl:template>
191
192<xsl:template match="part|reference|preface|chapter|appendix|article"
193              mode="jhtoc">
194  <xsl:variable name="id">
195    <xsl:call-template name="object.id"/>
196  </xsl:variable>
197  <xsl:variable name="title">
198    <xsl:apply-templates select="." mode="title.markup"/>
199  </xsl:variable>
200
201  <tocitem target="{$id}">
202    <xsl:attribute name="text">
203      <xsl:value-of select="$title"/>
204    </xsl:attribute>
205    <xsl:apply-templates
206      select="preface|chapter|appendix|refentry|section|sect1"
207      mode="jhtoc"/>
208  </tocitem>
209</xsl:template>
210
211<xsl:template match="section" mode="jhtoc">
212  <xsl:variable name="id">
213    <xsl:call-template name="object.id"/>
214  </xsl:variable>
215  <xsl:variable name="title">
216    <xsl:apply-templates select="." mode="title.markup"/>
217  </xsl:variable>
218
219  <tocitem target="{$id}">
220    <xsl:attribute name="text">
221      <xsl:value-of select="$title"/>
222    </xsl:attribute>
223    <xsl:apply-templates select="section" mode="jhtoc"/>
224  </tocitem>
225</xsl:template>
226
227<xsl:template match="sect1" mode="jhtoc">
228  <xsl:variable name="id">
229    <xsl:call-template name="object.id"/>
230  </xsl:variable>
231  <xsl:variable name="title">
232    <xsl:apply-templates select="." mode="title.markup"/>
233  </xsl:variable>
234
235  <tocitem target="{$id}">
236    <xsl:attribute name="text">
237      <xsl:value-of select="$title"/>
238    </xsl:attribute>
239    <xsl:apply-templates select="sect2" mode="jhtoc"/>
240  </tocitem>
241</xsl:template>
242
243<xsl:template match="sect2" mode="jhtoc">
244  <xsl:variable name="id">
245    <xsl:call-template name="object.id"/>
246  </xsl:variable>
247  <xsl:variable name="title">
248    <xsl:apply-templates select="." mode="title.markup"/>
249  </xsl:variable>
250
251  <tocitem target="{$id}">
252    <xsl:attribute name="text">
253      <xsl:value-of select="$title"/>
254    </xsl:attribute>
255    <xsl:apply-templates select="sect3" mode="jhtoc"/>
256  </tocitem>
257</xsl:template>
258
259<xsl:template match="sect3" mode="jhtoc">
260  <xsl:variable name="id">
261    <xsl:call-template name="object.id"/>
262  </xsl:variable>
263  <xsl:variable name="title">
264    <xsl:apply-templates select="." mode="title.markup"/>
265  </xsl:variable>
266
267  <tocitem target="{$id}">
268    <xsl:attribute name="text">
269      <xsl:value-of select="$title"/>
270    </xsl:attribute>
271    <xsl:apply-templates select="sect4" mode="jhtoc"/>
272  </tocitem>
273</xsl:template>
274
275<xsl:template match="sect4" mode="jhtoc">
276  <xsl:variable name="id">
277    <xsl:call-template name="object.id"/>
278  </xsl:variable>
279  <xsl:variable name="title">
280    <xsl:apply-templates select="." mode="title.markup"/>
281  </xsl:variable>
282
283  <tocitem target="{$id}">
284    <xsl:attribute name="text">
285      <xsl:value-of select="$title"/>
286    </xsl:attribute>
287    <xsl:apply-templates select="sect5" mode="jhtoc"/>
288  </tocitem>
289</xsl:template>
290
291<xsl:template match="sect5|colophon|refentry" mode="jhtoc">
292  <xsl:variable name="id">
293    <xsl:call-template name="object.id"/>
294  </xsl:variable>
295  <xsl:variable name="title">
296    <xsl:apply-templates select="." mode="title.markup"/>
297  </xsl:variable>
298
299  <tocitem target="{$id}">
300    <xsl:attribute name="text">
301      <xsl:value-of select="$title"/>
302    </xsl:attribute>
303  </tocitem>
304</xsl:template>
305
306<!-- ==================================================================== -->
307
308<xsl:template name="helpmap">
309  <xsl:call-template name="write.chunk.with.doctype">
310    <xsl:with-param name="filename" select="concat($base.dir, 'jhelpmap.jhm')"/>
311    <xsl:with-param name="method" select="'xml'"/>
312    <xsl:with-param name="indent" select="'yes'"/>
313    <xsl:with-param name="doctype-public" select="'-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN'"/>
314    <xsl:with-param name="doctype-system" select="'http://java.sun.com/products/javahelp/map_1_0.dtd'"/>
315    <xsl:with-param name="encoding" select="$javahelp.encoding"/>
316    <xsl:with-param name="content">
317      <xsl:call-template name="helpmap.content"/>
318    </xsl:with-param>
319  </xsl:call-template>
320</xsl:template>
321
322<xsl:template name="helpmap.content">
323  <map version="1.0">
324    <xsl:choose>
325      <xsl:when test="$rootid != ''">
326        <xsl:apply-templates select="key('id',$rootid)//set
327                                     | key('id',$rootid)//book
328                                     | key('id',$rootid)//part
329                                     | key('id',$rootid)//reference
330                                     | key('id',$rootid)//preface
331                                     | key('id',$rootid)//chapter
332                                     | key('id',$rootid)//appendix
333                                     | key('id',$rootid)//article
334                                     | key('id',$rootid)//colophon
335                                     | key('id',$rootid)//refentry
336                                     | key('id',$rootid)//section
337                                     | key('id',$rootid)//sect1
338                                     | key('id',$rootid)//sect2
339                                     | key('id',$rootid)//sect3
340                                     | key('id',$rootid)//sect4
341                                     | key('id',$rootid)//sect5
342                                     | key('id',$rootid)//indexterm
343				     | key('id',$rootid)//*[@id]"
344                             mode="map"/>
345      </xsl:when>
346      <xsl:otherwise>
347        <xsl:apply-templates select="//set
348                                     | //book
349                                     | //part
350                                     | //reference
351                                     | //preface
352                                     | //chapter
353                                     | //appendix
354                                     | //article
355                                     | //colophon
356                                     | //refentry
357                                     | //section
358                                     | //sect1
359                                     | //sect2
360                                     | //sect3
361                                     | //sect4
362                                     | //sect5
363                                     | //indexterm
364				     | //*[@id]"
365                             mode="map"/>
366      </xsl:otherwise>
367    </xsl:choose>
368  </map>
369</xsl:template>
370
371<xsl:template match="set" mode="map">
372  <xsl:variable name="id">
373    <xsl:call-template name="object.id">
374      <xsl:with-param name="object" select="."/>
375    </xsl:call-template>
376  </xsl:variable>
377
378  <mapID target="{$id}">
379    <xsl:attribute name="url">
380      <xsl:call-template name="href.target.uri"/>
381    </xsl:attribute>
382  </mapID>
383</xsl:template>
384
385<xsl:template match="book" mode="map">
386  <xsl:variable name="id">
387    <xsl:call-template name="object.id"/>
388  </xsl:variable>
389
390  <mapID target="{$id}">
391    <xsl:attribute name="url">
392      <xsl:call-template name="href.target.uri"/>
393    </xsl:attribute>
394  </mapID>
395</xsl:template>
396
397<xsl:template match="part|reference|preface|chapter|appendix|refentry|article"
398              mode="map">
399  <xsl:variable name="id">
400    <xsl:call-template name="object.id"/>
401  </xsl:variable>
402
403  <mapID target="{$id}">
404    <xsl:attribute name="url">
405      <xsl:call-template name="href.target.uri"/>
406    </xsl:attribute>
407  </mapID>
408</xsl:template>
409
410<xsl:template match="section|sect1|sect2|sect3|sect4|sect5|colophon" mode="map">
411  <xsl:variable name="id">
412    <xsl:call-template name="object.id"/>
413  </xsl:variable>
414
415  <mapID target="{$id}">
416    <xsl:attribute name="url">
417      <xsl:call-template name="href.target.uri"/>
418    </xsl:attribute>
419  </mapID>
420</xsl:template>
421
422<xsl:template match="indexterm[@class='endofrange']" mode="map"/>
423
424<xsl:template match="indexterm" mode="map">
425  <xsl:variable name="id">
426    <xsl:call-template name="object.id"/>
427  </xsl:variable>
428
429  <mapID target="{$id}">
430    <xsl:attribute name="url">
431      <xsl:call-template name="href.target.uri"/>
432    </xsl:attribute>
433  </mapID>
434</xsl:template>
435
436<xsl:template match="*[@id]" mode="map">
437  <xsl:variable name="id">
438    <xsl:call-template name="object.id"/>
439  </xsl:variable>
440
441  <mapID target="{$id}">
442    <xsl:attribute name="url">
443      <xsl:call-template name="href.target.uri"/>
444    </xsl:attribute>
445  </mapID>
446</xsl:template>
447
448<!-- ==================================================================== -->
449
450<xsl:template name="helpidx">
451  <xsl:call-template name="write.chunk.with.doctype">
452    <xsl:with-param name="filename" select="concat($base.dir, 'jhelpidx.xml')"/>
453    <xsl:with-param name="method" select="'xml'"/>
454    <xsl:with-param name="indent" select="'yes'"/>
455    <xsl:with-param name="doctype-public" select="'-//Sun Microsystems Inc.//DTD JavaHelp Index Version 1.0//EN'"/>
456    <xsl:with-param name="doctype-system" select="'http://java.sun.com/products/javahelp/index_1_0.dtd'"/>
457    <xsl:with-param name="encoding" select="$javahelp.encoding"/>
458    <xsl:with-param name="content">
459      <xsl:call-template name="helpidx.content"/>
460    </xsl:with-param>
461  </xsl:call-template>
462</xsl:template>
463
464<xsl:template name="helpidx.content">
465  <index version="1.0">
466    <xsl:choose>
467      <xsl:when test="$rootid != ''">
468        <xsl:apply-templates select="key('id',$rootid)//indexterm" mode="idx"/>
469      </xsl:when>
470      <xsl:otherwise>
471        <xsl:apply-templates select="//indexterm" mode="idx"/>
472      </xsl:otherwise>
473    </xsl:choose>
474  </index>
475</xsl:template>
476
477<xsl:template match="indexterm[@class='endofrange']" mode="idx"/>
478
479<xsl:template match="indexterm" mode="idx">
480  <xsl:variable name="id">
481    <xsl:call-template name="object.id"/>
482  </xsl:variable>
483
484  <xsl:variable name="text">
485    <xsl:value-of select="primary"/>
486    <xsl:if test="secondary">
487      <xsl:text>, </xsl:text>
488      <xsl:value-of select="secondary"/>
489    </xsl:if>
490    <xsl:if test="tertiary">
491      <xsl:text>, </xsl:text>
492      <xsl:value-of select="tertiary"/>
493    </xsl:if>
494  </xsl:variable>
495
496  <xsl:choose>
497    <xsl:when test="see">
498      <xsl:variable name="see"><xsl:value-of select="see"/></xsl:variable>
499      <indexitem text="{$text} see '{$see}'"/>
500    </xsl:when>
501    <xsl:otherwise>
502      <indexitem text="{$text}" target="{$id}"/>
503    </xsl:otherwise>
504  </xsl:choose>
505</xsl:template>
506
507<!-- ==================================================================== -->
508<!-- Kludge for Xalan outputting &trade; which fails in javahelp -->
509<xsl:template name="dingbat.characters">
510  <!-- now that I'm using the real serializer, all that dingbat malarky -->
511  <!-- isn't necessary anymore... -->
512  <xsl:param name="dingbat">bullet</xsl:param>
513
514  <xsl:choose>
515    <xsl:when test="$dingbat='bullet'">&#x2022;</xsl:when>
516    <xsl:when test="$dingbat='copyright'">&#x00A9;</xsl:when>
517    <xsl:when test="$dingbat='trademark' or $dingbat='trade'">
518      <xsl:choose>
519        <xsl:when test="contains(system-property('xsl:vendor'),
520                                 'Apache Software Foundation')">
521          <sup>TM</sup>
522        </xsl:when>
523        <xsl:otherwise>&#x2122;</xsl:otherwise>
524      </xsl:choose>
525    </xsl:when>
526    <xsl:when test="$dingbat='registered'">&#x00AE;</xsl:when>
527    <xsl:when test="$dingbat='service'">(SM)</xsl:when>
528    <xsl:when test="$dingbat='nbsp'">&#x00A0;</xsl:when>
529    <xsl:when test="$dingbat='ldquo'">&#x201C;</xsl:when>
530    <xsl:when test="$dingbat='rdquo'">&#x201D;</xsl:when>
531    <xsl:when test="$dingbat='lsquo'">&#x2018;</xsl:when>
532    <xsl:when test="$dingbat='rsquo'">&#x2019;</xsl:when>
533    <xsl:when test="$dingbat='em-dash'">&#x2014;</xsl:when>
534    <xsl:when test="$dingbat='mdash'">&#x2014;</xsl:when>
535    <xsl:when test="$dingbat='en-dash'">&#x2013;</xsl:when>
536    <xsl:when test="$dingbat='ndash'">&#x2013;</xsl:when>
537    <xsl:otherwise>
538      <xsl:text>&#x2022;</xsl:text>
539    </xsl:otherwise>
540  </xsl:choose>
541</xsl:template>
542
543</xsl:stylesheet>
544