]> git.stg.codes - stg.git/blob - doc/xslt/htmlhelp/htmlhelp-common.xsl
Set output encoding to utf-8.
[stg.git] / doc / xslt / htmlhelp / htmlhelp-common.xsl
1 <?xml version="1.0"?>
2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY lf '<xsl:text xmlns:xsl="http://www.w3.org/1999/XSL/Transform">&#xA;</xsl:text>'>
4 ]>
5 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6   xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
7   xmlns:exsl="http://exslt.org/common"
8   xmlns:set="http://exslt.org/sets"
9   xmlns:h="urn:x-hex"
10   xmlns:ng="http://docbook.org/docbook-ng"
11   xmlns:db="http://docbook.org/ns/docbook"
12   version="1.0"
13   exclude-result-prefixes="doc exsl set h db ng">
14
15 <!-- ********************************************************************
16      $Id: htmlhelp-common.xsl 8400 2009-04-08 07:44:54Z bobstayton $
17      ******************************************************************** -->
18
19 <!-- ==================================================================== -->
20 <!-- Customizations of standard HTML stylesheet parameters -->
21
22 <!-- no navigation on pages by default, HTML Help provides its own navigation controls -->
23 <xsl:param name="suppress.navigation" select="1"/>
24
25 <!-- no separate HTML page with index, index is built inside CHM index pane -->
26 <xsl:param name="generate.index" select="0"/>
27
28 <!-- ==================================================================== -->
29
30 <xsl:param name="htmlhelp.generate.index" select="//indexterm[1]|//db:indexterm[1]|//ng:indexterm[1]"/>
31   
32 <!-- Set up HTML Help flag -->
33 <xsl:variable name="htmlhelp.output" select="1"/>
34
35 <!-- ==================================================================== -->
36
37 <xsl:template match="/">
38
39   <!-- * Get a title for current doc so that we let the user -->
40   <!-- * know what document we are processing at this point. -->
41   <xsl:variable name="doc.title">
42     <xsl:call-template name="get.doc.title"/>
43   </xsl:variable>
44   <xsl:choose>
45     <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
46          toss the namespace and continue.  Use the docbook5 namespaced
47          stylesheets for DocBook5 if you don't want to use this feature.-->
48     <xsl:when test="$exsl.node.set.available != 0
49                     and (*/self::ng:* or */self::db:*)">
50       <xsl:call-template name="log.message">
51         <xsl:with-param name="level">Note</xsl:with-param>
52         <xsl:with-param name="source" select="$doc.title"/>
53         <xsl:with-param name="context-desc">
54           <xsl:text>namesp. cut</xsl:text>
55         </xsl:with-param>
56         <xsl:with-param name="message">
57           <xsl:text>stripped namespace before processing</xsl:text>
58         </xsl:with-param>
59       </xsl:call-template>
60       <xsl:variable name="nons">
61         <xsl:apply-templates mode="stripNS"/>
62       </xsl:variable>
63       <xsl:call-template name="log.message">
64         <xsl:with-param name="level">Note</xsl:with-param>
65         <xsl:with-param name="source" select="$doc.title"/>
66         <xsl:with-param name="context-desc">
67           <xsl:text>namesp. cut</xsl:text>
68         </xsl:with-param>
69         <xsl:with-param name="message">
70           <xsl:text>processing stripped document</xsl:text>
71         </xsl:with-param>
72       </xsl:call-template>
73       <xsl:apply-templates select="exsl:node-set($nons)"/>
74     </xsl:when>
75     <xsl:otherwise>
76   <xsl:if test="$htmlhelp.only != 1">
77     <xsl:choose>
78       <xsl:when test="$rootid != ''">
79         <xsl:choose>
80           <xsl:when test="count(key('id',$rootid)) = 0">
81             <xsl:message terminate="yes">
82               <xsl:text>ID '</xsl:text>
83               <xsl:value-of select="$rootid"/>
84               <xsl:text>' not found in document.</xsl:text>
85             </xsl:message>
86           </xsl:when>
87           <xsl:otherwise>
88             <xsl:message>Formatting from <xsl:value-of select="$rootid"/></xsl:message>
89             <xsl:apply-templates select="key('id',$rootid)" mode="process.root"/>
90           </xsl:otherwise>
91         </xsl:choose>
92       </xsl:when>
93       <xsl:otherwise>
94         <xsl:if test="$collect.xref.targets = 'yes' or
95                       $collect.xref.targets = 'only'">
96           <xsl:apply-templates select="/" mode="collect.targets"/>
97         </xsl:if>
98         <xsl:if test="$collect.xref.targets != 'only'">
99           <xsl:apply-templates select="/" mode="process.root"/>
100         </xsl:if>
101       </xsl:otherwise>
102     </xsl:choose>
103   </xsl:if>
104
105
106   <xsl:if test="$collect.xref.targets != 'only'">
107     <xsl:call-template name="hhp"/>
108     <xsl:call-template name="hhc"/>
109     <xsl:if test="($rootid = '' and //processing-instruction('dbhh')) or
110                   ($rootid != '' and key('id',$rootid)//processing-instruction('dbhh'))">
111       <xsl:call-template name="hh-map"/>
112       <xsl:call-template name="hh-alias"/>
113     </xsl:if>
114     <xsl:if test="$htmlhelp.generate.index">
115       <xsl:call-template name="hhk"/>
116     </xsl:if>
117   </xsl:if>
118 </xsl:otherwise>
119 </xsl:choose>
120 </xsl:template>
121
122 <!-- ==================================================================== -->
123
124 <xsl:template name="hhp">
125   <xsl:call-template name="write.text.chunk">
126     <xsl:with-param name="filename">
127       <xsl:if test="$manifest.in.base.dir != 0">
128         <xsl:value-of select="$base.dir"/>
129       </xsl:if>
130       <xsl:value-of select="$htmlhelp.hhp"/>
131     </xsl:with-param>
132     <xsl:with-param name="method" select="'text'"/>
133     <xsl:with-param name="content">
134       <xsl:call-template name="hhp-main"/>
135     </xsl:with-param>
136     <xsl:with-param name="encoding" select="$htmlhelp.encoding"/>
137     <xsl:with-param name="quiet" select="$chunk.quietly"/>
138   </xsl:call-template>
139 </xsl:template>
140
141 <!-- ==================================================================== -->
142 <xsl:template name="hhp-main">
143
144   <xsl:variable name="raw.help.title">
145     <xsl:choose>
146       <xsl:when test="$htmlhelp.title = ''">
147         <xsl:choose>
148           <xsl:when test="$rootid != ''">
149             <xsl:apply-templates select="key('id',$rootid)" mode="title.markup"/>
150           </xsl:when>
151           <xsl:otherwise>
152             <xsl:apply-templates select="/*" mode="title.markup"/>
153           </xsl:otherwise>
154         </xsl:choose>
155       </xsl:when>
156       <xsl:otherwise>
157         <xsl:value-of select="$htmlhelp.title"/>
158       </xsl:otherwise>
159     </xsl:choose>
160   </xsl:variable>
161
162   <xsl:variable name="help.title" select="normalize-space($raw.help.title)"/>
163   
164 <xsl:variable name="default.topic">
165   <xsl:choose>
166     <xsl:when test="$htmlhelp.default.topic != ''">
167       <xsl:value-of select="$htmlhelp.default.topic"/>
168     </xsl:when>
169     <xsl:otherwise>
170       <xsl:call-template name="make-relative-filename">
171         <xsl:with-param name="base.dir">
172           <xsl:if test="$manifest.in.base.dir = 0">
173             <xsl:value-of select="$base.dir"/>
174           </xsl:if>
175         </xsl:with-param>
176         <xsl:with-param name="base.name">
177           <xsl:choose>
178             <xsl:when test="$rootid != ''">
179               <xsl:apply-templates select="key('id',$rootid)" mode="chunk-filename"/>
180             </xsl:when>
181             <xsl:otherwise>
182               <xsl:apply-templates select="/" mode="chunk-filename"/>
183             </xsl:otherwise>
184           </xsl:choose>
185         </xsl:with-param>
186       </xsl:call-template>
187     </xsl:otherwise>
188   </xsl:choose>
189 </xsl:variable>
190 <xsl:variable name="xnavigation">
191   <xsl:text>0x</xsl:text>
192   <xsl:call-template name="toHex">
193     <xsl:with-param name="n" select="9504 + $htmlhelp.show.menu * 65536
194                                           + $htmlhelp.show.advanced.search * 131072
195                                           + $htmlhelp.show.favorities * 4096
196                                           + (1 - $htmlhelp.show.toolbar.text) * 64
197                                           + $htmlhelp.remember.window.position * 262144"/>
198   </xsl:call-template>
199 </xsl:variable>
200 <xsl:variable name="xbuttons">
201   <xsl:text>0x</xsl:text>
202   <xsl:call-template name="toHex">
203     <xsl:with-param name="n" select="0 + $htmlhelp.button.hideshow * 2
204                                        + $htmlhelp.button.back * 4
205                                        + $htmlhelp.button.forward * 8
206                                        + $htmlhelp.button.stop * 16
207                                        + $htmlhelp.button.refresh * 32
208                                        + $htmlhelp.button.home * 64
209                                        + $htmlhelp.button.options * 4096
210                                        + $htmlhelp.button.print * 8192
211                                        + $htmlhelp.button.locate * 2048
212                                        + $htmlhelp.button.jump1 * 262144
213                                        + $htmlhelp.button.jump2 * 524288
214                                        + $htmlhelp.button.next * 2097152
215                                        + $htmlhelp.button.prev * 4194304
216                                        + $htmlhelp.button.zoom * 1048576"/>
217   </xsl:call-template>
218 </xsl:variable>
219 <xsl:text>[OPTIONS]
220 </xsl:text>
221 <xsl:if test="$htmlhelp.generate.index">
222 <xsl:text>Auto Index=Yes
223 </xsl:text></xsl:if>
224 <xsl:if test="$htmlhelp.hhc.binary != 0">
225 <xsl:text>Binary TOC=Yes
226 </xsl:text></xsl:if>
227 <xsl:text>Compatibility=1.1 or later
228 Compiled file=</xsl:text><xsl:value-of select="$htmlhelp.chm"/><xsl:text>
229 Contents file=</xsl:text><xsl:value-of select="$htmlhelp.hhc"/><xsl:text>
230 </xsl:text>
231 <xsl:if test="$htmlhelp.hhp.window != ''">
232 <xsl:text>Default Window=</xsl:text><xsl:value-of select="$htmlhelp.hhp.window"/><xsl:text>
233 </xsl:text></xsl:if>
234 <xsl:text>Default topic=</xsl:text><xsl:value-of select="$default.topic"/>
235 <xsl:text>
236 Display compile progress=</xsl:text>
237   <xsl:choose>
238     <xsl:when test="$htmlhelp.display.progress != 1">
239       <xsl:text>No</xsl:text>
240     </xsl:when>
241     <xsl:otherwise>
242       <xsl:text>Yes</xsl:text>
243     </xsl:otherwise>
244   </xsl:choose>
245 <xsl:text>
246 Full-text search=Yes
247 </xsl:text>
248 <xsl:if test="$htmlhelp.generate.index">
249 <xsl:text>Index file=</xsl:text><xsl:value-of select="$htmlhelp.hhk"/><xsl:text>
250 </xsl:text></xsl:if>
251 <xsl:text>Language=</xsl:text>
252 <xsl:for-each select="*">   <!-- Change context from / to root element -->
253   <xsl:call-template name="gentext.template">
254     <xsl:with-param name="context" select="'htmlhelp'"/>
255     <xsl:with-param name="name" select="'langcode'"/>
256   </xsl:call-template>
257 </xsl:for-each>
258 <xsl:text>
259 Title=</xsl:text>
260   <xsl:value-of select="$help.title"/>
261 <xsl:text>
262 Enhanced decompilation=</xsl:text>
263   <xsl:choose>
264     <xsl:when test="$htmlhelp.enhanced.decompilation != 0">
265       <xsl:text>Yes</xsl:text>
266     </xsl:when>
267     <xsl:otherwise>
268       <xsl:text>No</xsl:text>
269     </xsl:otherwise>
270   </xsl:choose>
271
272 <xsl:if test="$htmlhelp.hhp.window != ''">
273   <xsl:text>
274
275 [WINDOWS]
276 </xsl:text>
277 <xsl:value-of select="$htmlhelp.hhp.window"/>
278 <xsl:text>="</xsl:text>
279 <xsl:value-of select="$help.title"/>
280 <xsl:text>","</xsl:text><xsl:value-of select="$htmlhelp.hhc"/>
281 <xsl:text>",</xsl:text>
282 <xsl:if test="$htmlhelp.generate.index">
283   <xsl:text>"</xsl:text>
284   <xsl:value-of select="$htmlhelp.hhk"/>
285   <xsl:text>"</xsl:text>
286 </xsl:if>
287 <xsl:text>,"</xsl:text>
288 <xsl:value-of select="$default.topic"/>
289 <xsl:text>",</xsl:text>
290 <xsl:text>"</xsl:text>
291 <xsl:choose>
292   <xsl:when test="$htmlhelp.button.home != 0">
293     <xsl:value-of select="$htmlhelp.button.home.url"/>
294   </xsl:when>
295   <xsl:otherwise>
296     <xsl:value-of select="$default.topic"/>
297   </xsl:otherwise>
298 </xsl:choose>
299 <xsl:text>"</xsl:text>
300 <xsl:text>,</xsl:text>
301 <xsl:if test="$htmlhelp.button.jump1 != 0">
302   <xsl:text>"</xsl:text>
303   <xsl:value-of select="$htmlhelp.button.jump1.url"/>
304   <xsl:text>"</xsl:text>
305 </xsl:if>
306 <xsl:text>,</xsl:text>
307 <xsl:if test="$htmlhelp.button.jump1 != 0">
308   <xsl:text>"</xsl:text>
309   <xsl:value-of select="$htmlhelp.button.jump1.title"/>
310   <xsl:text>"</xsl:text>
311 </xsl:if>
312 <xsl:text>,</xsl:text>
313 <xsl:if test="$htmlhelp.button.jump2 != 0">
314   <xsl:text>"</xsl:text>
315   <xsl:value-of select="$htmlhelp.button.jump2.url"/>
316   <xsl:text>"</xsl:text>
317 </xsl:if>
318 <xsl:text>,</xsl:text>
319 <xsl:if test="$htmlhelp.button.jump2 != 0">
320   <xsl:text>"</xsl:text>
321   <xsl:value-of select="$htmlhelp.button.jump2.title"/>
322   <xsl:text>"</xsl:text>
323 </xsl:if>
324 <xsl:text>,</xsl:text>
325 <xsl:value-of select="$xnavigation"/>
326 <xsl:text>,</xsl:text><xsl:value-of select="$htmlhelp.hhc.width"/><xsl:text>,</xsl:text>
327 <xsl:value-of select="$xbuttons"/>
328 <xsl:text>,</xsl:text><xsl:value-of select="$htmlhelp.window.geometry"/><xsl:text>,,,,,,,0
329 </xsl:text>
330 </xsl:if>
331
332 <!-- 
333   Needs more investigation to generate propetly all fields 
334 <xsl:text>search="</xsl:text>
335 <xsl:value-of select="normalize-space(//title[1])"/>
336 <xsl:text>","toc.hhc","index.hhk","</xsl:text>
337 <xsl:value-of select="$root.filename"/>
338 <xsl:text>.html","</xsl:text>
339 <xsl:value-of select="$root.filename"/>
340 <xsl:text>.html",,,,,</xsl:text>
341 <xsl:value-of select="$xnavigation"/>
342 <xsl:text>,</xsl:text>
343 <xsl:value-of select="$htmlhelp.hhc.width"/>
344 <xsl:text>,</xsl:text>
345 <xsl:value-of select="$xbuttons"/>
346 <xsl:text>,</xsl:text>
347 <xsl:value-of select="$htmlhelp.window.geometry"/>
348 <xsl:text>,,,,,2,,0
349 </xsl:text>
350 -->
351
352 <xsl:if test="$htmlhelp.hhp.windows">
353   <xsl:value-of select="$htmlhelp.hhp.windows"/>
354 </xsl:if>
355 <xsl:text>
356
357 [FILES]
358 </xsl:text>
359
360 <xsl:choose>
361   <xsl:when test="$rootid != ''">
362     <xsl:apply-templates select="key('id',$rootid)" mode="enumerate-files"/>
363   </xsl:when>
364   <xsl:otherwise>
365     <xsl:apply-templates select="/" mode="enumerate-files"/>
366   </xsl:otherwise>
367 </xsl:choose>
368
369 <xsl:if test="$htmlhelp.enumerate.images">
370   <xsl:variable name="imagelist">
371     <xsl:choose>
372       <xsl:when test="$rootid != ''">
373         <xsl:apply-templates select="key('id',$rootid)" mode="enumerate-images"/>
374       </xsl:when>
375       <xsl:otherwise>
376         <xsl:apply-templates select="/" mode="enumerate-images"/>
377       </xsl:otherwise>
378     </xsl:choose>
379   </xsl:variable>
380   <xsl:choose>
381     <xsl:when test="$exsl.node.set.available != 0
382                     and function-available('set:distinct')">
383       <xsl:for-each select="set:distinct(exsl:node-set($imagelist)/filename)">
384         <xsl:value-of select="."/>
385         <xsl:text>&#10;</xsl:text>
386       </xsl:for-each>
387     </xsl:when>
388     <xsl:otherwise>
389       <xsl:value-of select="$imagelist"/>
390     </xsl:otherwise>
391   </xsl:choose>
392 </xsl:if>
393
394 <xsl:if test="($htmlhelp.force.map.and.alias != 0) or 
395               ($rootid = '' and //processing-instruction('dbhh')) or
396               ($rootid != '' and key('id',$rootid)//processing-instruction('dbhh'))">
397   <xsl:text>
398 [ALIAS]
399 #include </xsl:text><xsl:value-of select="$htmlhelp.alias.file"/><xsl:text>
400
401 [MAP]
402 #include </xsl:text><xsl:value-of select="$htmlhelp.map.file"/><xsl:text>
403 </xsl:text>
404 </xsl:if>
405
406 <xsl:value-of select="$htmlhelp.hhp.tail"/>
407 </xsl:template>
408
409 <!-- ==================================================================== -->
410
411 <xsl:template match="graphic|inlinegraphic[@format!='linespecific']" mode="enumerate-images">
412   <xsl:call-template name="write.filename.enumerate-images">
413     <xsl:with-param name="filename">
414       <xsl:call-template name="mediaobject.filename.enumerate-images">
415         <xsl:with-param name="object" select="."/>
416       </xsl:call-template>  
417     </xsl:with-param>
418   </xsl:call-template>
419 </xsl:template>
420
421 <xsl:template match="mediaobject|inlinemediaobject" mode="enumerate-images">
422   <xsl:call-template name="select.mediaobject.enumerate-images"/>
423 </xsl:template>
424
425 <xsl:template name="select.mediaobject.enumerate-images">
426   <xsl:param name="olist"
427              select="imageobject|imageobjectco
428                      |videoobject|audioobject|textobject"/>
429   <xsl:param name="count">1</xsl:param>
430
431   <xsl:if test="$count &lt;= count($olist)">
432     <xsl:variable name="object" select="$olist[position()=$count]"/>
433
434     <xsl:variable name="useobject">
435       <xsl:choose>
436         <!-- The phrase is never used -->
437         <xsl:when test="name($object)='textobject' and $object/phrase">
438           <xsl:text>0</xsl:text>
439         </xsl:when>
440         <!-- The first textobject is a reasonable fallback (but not for image in HH) -->
441         <xsl:when test="name($object)='textobject'">
442           <xsl:text>0</xsl:text>
443         </xsl:when>
444         <!-- If there's only one object, use it -->
445         <xsl:when test="$count = 1 and count($olist) = 1">
446           <xsl:text>1</xsl:text>
447         </xsl:when>
448         <!-- Otherwise, see if this one is a useable graphic -->
449         <xsl:otherwise>
450           <xsl:choose>
451             <!-- peek inside imageobjectco to simplify the test -->
452             <xsl:when test="local-name($object) = 'imageobjectco'">
453               <xsl:call-template name="is.acceptable.mediaobject">
454                 <xsl:with-param name="object" select="$object/imageobject"/>
455               </xsl:call-template>
456             </xsl:when>
457             <xsl:otherwise>
458               <xsl:call-template name="is.acceptable.mediaobject">
459                 <xsl:with-param name="object" select="$object"/>
460               </xsl:call-template>
461             </xsl:otherwise>
462           </xsl:choose>
463         </xsl:otherwise>
464       </xsl:choose>
465     </xsl:variable>
466
467     <xsl:choose>
468       <xsl:when test="$useobject='1' and $object[not(*/@format='linespecific')]">
469         <xsl:call-template name="write.filename.enumerate-images">
470           <xsl:with-param name="filename">
471             <xsl:call-template name="mediaobject.filename.enumerate-images">
472               <xsl:with-param name="object" select="$object"/>
473             </xsl:call-template>
474           </xsl:with-param>
475         </xsl:call-template>
476       </xsl:when>
477       <xsl:otherwise>
478         <xsl:call-template name="select.mediaobject.enumerate-images">
479           <xsl:with-param name="olist" select="$olist"/>
480           <xsl:with-param name="count" select="$count + 1"/>
481         </xsl:call-template>
482       </xsl:otherwise>
483     </xsl:choose>
484   </xsl:if>
485 </xsl:template>
486
487 <xsl:template name="mediaobject.filename.enumerate-images">
488   <xsl:param name="object"/>
489
490   <xsl:variable name="urifilename">
491     <xsl:call-template name="mediaobject.filename">
492       <xsl:with-param name="object" select="$object"/>
493     </xsl:call-template>
494   </xsl:variable>
495
496   <xsl:variable name="filename">
497     <xsl:choose>
498       <xsl:when test="starts-with($urifilename, 'file:/')">
499         <xsl:value-of select="substring-after($urifilename, 'file:/')"/>
500       </xsl:when>
501       <xsl:otherwise>
502         <xsl:value-of select="$urifilename"/>
503       </xsl:otherwise>
504     </xsl:choose>
505   </xsl:variable>
506
507   <xsl:value-of select="translate($filename, '/', '\')"/>
508
509 </xsl:template>
510
511 <xsl:template match="text()" mode="enumerate-images">
512 </xsl:template>
513
514 <xsl:template name="write.filename.enumerate-images">
515   <xsl:param name="filename"/>
516   <xsl:choose>
517     <xsl:when test="function-available('exsl:node-set') and function-available('set:distinct')">
518       <filename><xsl:value-of select="$filename"/></filename>
519     </xsl:when>
520     <xsl:otherwise>
521       <xsl:value-of select="$filename"/>
522       <xsl:text>&#10;</xsl:text>
523     </xsl:otherwise>
524   </xsl:choose>
525 </xsl:template>
526
527 <!-- ==================================================================== -->
528
529 <!-- HHC and HHK files are processed by compiler line by line
530      and therefore are very sensitive to whitespaces (linefeeds for sure).  -->
531
532 <xsl:template name="hhc">
533   <xsl:call-template name="write.chunk">
534     <xsl:with-param name="filename">
535       <xsl:if test="$manifest.in.base.dir != 0">
536         <xsl:value-of select="$base.dir"/>
537       </xsl:if>
538       <xsl:value-of select="$htmlhelp.hhc"/>
539     </xsl:with-param>
540     <xsl:with-param name="indent" select="'no'"/>
541     <xsl:with-param name="content">
542       <xsl:call-template name="hhc-main"/>
543     </xsl:with-param>
544     <xsl:with-param name="encoding" select="$htmlhelp.encoding"/>
545     <xsl:with-param name="quiet" select="$chunk.quietly"/>
546   </xsl:call-template>
547 </xsl:template>
548
549 <xsl:template name="hhc-main">
550 <HTML>&lf;
551  <HEAD></HEAD>&lf;
552  <BODY>&lf;
553   <xsl:if test="$htmlhelp.hhc.folders.instead.books != 0">
554    <OBJECT type="text/site properties">&lf;
555      <param name="ImageType" value="Folder"/>&lf;
556    </OBJECT>&lf;
557   </xsl:if>
558   <xsl:variable name="content">
559     <xsl:choose>
560       <xsl:when test="$rootid != ''">
561         <xsl:apply-templates select="key('id',$rootid)" mode="hhc"/>
562       </xsl:when>
563       <xsl:otherwise>
564         <xsl:apply-templates select="/" mode="hhc"/>
565       </xsl:otherwise>
566     </xsl:choose>
567   </xsl:variable>
568
569   <xsl:choose>
570     <xsl:when test="$htmlhelp.hhc.show.root != 0">
571       <UL>&lf;
572         <xsl:copy-of select="$content"/>
573       </UL>&lf;
574     </xsl:when>
575     <xsl:otherwise>
576     <xsl:copy-of select="$content"/>
577     </xsl:otherwise>
578   </xsl:choose>
579
580  </BODY>
581 </HTML>
582 </xsl:template>
583
584 <xsl:template name="hhc.entry">
585   <xsl:param name="title">
586     <xsl:if test="$htmlhelp.autolabel=1">
587       <xsl:variable name="label.markup">
588         <xsl:apply-templates select="." mode="label.markup"/>
589       </xsl:variable>
590       <xsl:if test="normalize-space($label.markup)">
591         <xsl:value-of select="concat($label.markup,$autotoc.label.separator)"/>
592       </xsl:if>
593     </xsl:if>
594     <xsl:apply-templates select="." mode="title.markup"/>
595   </xsl:param>
596
597   <LI><OBJECT type="text/sitemap">&lf;
598     <param name="Name">
599       <xsl:attribute name="value">
600           <xsl:value-of select="normalize-space($title)"/>
601       </xsl:attribute>
602     </param>&lf;
603     <param name="Local">
604       <xsl:attribute name="value">
605           <xsl:call-template name="href.target.with.base.dir"/>
606       </xsl:attribute>
607     </param>
608   </OBJECT></LI>&lf;
609 </xsl:template>
610
611 <xsl:template match="set" mode="hhc">
612   <xsl:if test="$htmlhelp.hhc.show.root != 0">
613     <xsl:call-template name="hhc.entry"/>
614   </xsl:if>
615   <xsl:if test="book">
616     <xsl:variable name="toc.params">
617       <xsl:call-template name="find.path.params">
618         <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
619       </xsl:call-template>
620     </xsl:variable>
621     <UL>
622       <xsl:if test="contains($toc.params, 'toc') and $htmlhelp.hhc.show.root = 0">
623       <LI><OBJECT type="text/sitemap">&lf;
624           <param name="Name">
625             <xsl:attribute name="value">
626             <xsl:call-template name="gentext">
627               <xsl:with-param name="key" select="'TableofContents'"/>
628             </xsl:call-template>
629             </xsl:attribute>
630           </param>&lf;
631           <param name="Local">
632             <xsl:attribute name="value">
633               <xsl:choose>
634                 <xsl:when test="$chunk.tocs.and.lots != 0">
635                   <xsl:apply-templates select="." mode="recursive-chunk-filename">
636                     <xsl:with-param name="recursive" select="true()"/>
637                   </xsl:apply-templates>
638                   <xsl:text>-toc</xsl:text>
639                   <xsl:value-of select="$html.ext"/>
640                 </xsl:when>
641                 <xsl:otherwise>
642                   <xsl:call-template name="href.target.with.base.dir"/>
643                 </xsl:otherwise>
644               </xsl:choose>
645             </xsl:attribute>
646           </param>
647       </OBJECT></LI>&lf;
648       </xsl:if>
649       <xsl:apply-templates select="book" mode="hhc"/>
650     </UL>&lf;
651   </xsl:if>
652 </xsl:template>
653
654 <xsl:template match="book" mode="hhc">
655   <xsl:if test="$htmlhelp.hhc.show.root != 0 or parent::*">
656     <xsl:call-template name="hhc.entry"/>
657   </xsl:if>
658   <xsl:if test="part|reference|preface|chapter|appendix|bibliography|article|colophon|glossary">
659     <xsl:variable name="toc.params">
660       <xsl:call-template name="find.path.params">
661         <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
662       </xsl:call-template>
663     </xsl:variable>
664     <UL>
665       <xsl:if test="contains($toc.params, 'toc') and $htmlhelp.hhc.show.root = 0 and not(parent::*)">
666         <LI><OBJECT type="text/sitemap">&lf;
667             <param name="Name">
668               <xsl:attribute name="value">
669                 <xsl:call-template name="gentext">
670                   <xsl:with-param name="key" select="'TableofContents'"/>
671                 </xsl:call-template>
672               </xsl:attribute>
673             </param>&lf;
674             <param name="Local">
675               <xsl:attribute name="value">
676                 <xsl:choose>
677                   <xsl:when test="$chunk.tocs.and.lots != 0">
678                     <xsl:apply-templates select="." mode="recursive-chunk-filename">
679                       <xsl:with-param name="recursive" select="true()"/>
680                     </xsl:apply-templates>
681                     <xsl:text>-toc</xsl:text>
682                     <xsl:value-of select="$html.ext"/>
683                   </xsl:when>
684                   <xsl:otherwise>
685                     <xsl:call-template name="href.target.with.base.dir"/>
686                   </xsl:otherwise>
687                 </xsl:choose>
688               </xsl:attribute>
689             </param>
690         </OBJECT></LI>&lf;
691       </xsl:if>
692       <xsl:apply-templates select="part|reference|preface|chapter|bibliography|appendix|article|colophon|glossary"
693                            mode="hhc"/>
694     </UL>&lf;
695   </xsl:if>
696 </xsl:template>
697
698 <xsl:template match="part|reference|preface|chapter|bibliography|appendix|article|glossary"
699               mode="hhc">
700   <xsl:if test="$htmlhelp.hhc.show.root != 0 or parent::*">
701     <xsl:call-template name="hhc.entry"/>
702   </xsl:if>
703   <xsl:if test="article|reference|preface|chapter|appendix|refentry|section|sect1|bibliodiv">
704     <UL>&lf;
705       <xsl:apply-templates
706         select="article|reference|preface|chapter|appendix|refentry|section|sect1|bibliodiv"
707         mode="hhc"/>
708     </UL>
709   </xsl:if>
710 </xsl:template>
711
712 <xsl:template match="section" mode="hhc">
713   <xsl:if test="$htmlhelp.hhc.show.root != 0 or parent::*">
714     <xsl:call-template name="hhc.entry"/>
715   </xsl:if>
716   <xsl:if test="section[count(ancestor::section) &lt; $htmlhelp.hhc.section.depth]|refentry">
717     <UL>&lf;
718       <xsl:apply-templates select="section|refentry" mode="hhc"/>
719     </UL>
720   </xsl:if>
721 </xsl:template>
722
723 <xsl:template match="sect1" mode="hhc">
724   <xsl:if test="$htmlhelp.hhc.show.root != 0 or parent::*">
725     <xsl:call-template name="hhc.entry"/>
726   </xsl:if>
727   <xsl:if test="sect2[$htmlhelp.hhc.section.depth > 1]|refentry">
728     <UL>&lf;
729       <xsl:apply-templates select="sect2|refentry"
730                            mode="hhc"/>
731     </UL>
732   </xsl:if>
733 </xsl:template>
734
735 <xsl:template match="sect2" mode="hhc">
736   <xsl:if test="$htmlhelp.hhc.show.root != 0 or parent::*">
737     <xsl:call-template name="hhc.entry"/>
738   </xsl:if>
739   <xsl:if test="sect3[$htmlhelp.hhc.section.depth > 2]|refentry">
740     <UL>&lf;
741       <xsl:apply-templates select="sect3|refentry"
742                            mode="hhc"/>
743     </UL>
744   </xsl:if>
745 </xsl:template>
746
747 <xsl:template match="sect3" mode="hhc">
748   <xsl:if test="$htmlhelp.hhc.show.root != 0 or parent::*">
749     <xsl:call-template name="hhc.entry"/>
750   </xsl:if>
751   <xsl:if test="sect4[$htmlhelp.hhc.section.depth > 3]|refentry">
752     <UL>&lf;
753       <xsl:apply-templates select="sect4|refentry"
754                            mode="hhc"/>
755     </UL>
756   </xsl:if>
757 </xsl:template>
758
759 <xsl:template match="sect4" mode="hhc">
760   <xsl:if test="$htmlhelp.hhc.show.root != 0 or parent::*">
761     <xsl:call-template name="hhc.entry"/>
762   </xsl:if>
763   <xsl:if test="sect5[$htmlhelp.hhc.section.depth > 4]|refentry">
764     <UL>&lf;
765       <xsl:apply-templates select="sect5|refentry"
766                            mode="hhc"/>
767     </UL>
768   </xsl:if>
769 </xsl:template>
770
771 <xsl:template match="sect5|refentry|colophon|bibliodiv" mode="hhc">
772   <xsl:if test="$htmlhelp.hhc.show.root != 0 or parent::*">
773     <xsl:call-template name="hhc.entry"/>
774   </xsl:if>
775   <xsl:if test="refentry">
776     <UL>&lf;
777       <xsl:apply-templates select="refentry"
778                            mode="hhc"/>
779     </UL>
780   </xsl:if>
781 </xsl:template>
782
783 <!-- ==================================================================== -->
784
785 <xsl:template match="indexterm">
786   <xsl:choose>
787     <xsl:when test="$htmlhelp.use.hhk = 0">
788   
789       <xsl:variable name="primary" select="normalize-space(primary)"/>
790       <xsl:variable name="secondary" select="normalize-space(secondary)"/>
791       <xsl:variable name="tertiary" select="normalize-space(tertiary)"/>
792       
793       <xsl:variable name="text">
794         <xsl:value-of select="$primary"/>
795         <xsl:if test="secondary">
796           <xsl:text>, </xsl:text>
797           <xsl:value-of select="$secondary"/>
798         </xsl:if>
799         <xsl:if test="tertiary">
800           <xsl:text>, </xsl:text>
801           <xsl:value-of select="$tertiary"/>
802         </xsl:if>
803       </xsl:variable>
804       
805       <xsl:if test="secondary">
806         <xsl:if test="not(//indexterm[normalize-space(primary)=$primary and not(secondary)])">
807           <xsl:call-template name="write.indexterm">
808             <xsl:with-param name="text" select="$primary"/>
809           </xsl:call-template>
810         </xsl:if>
811       </xsl:if>
812
813       <xsl:if test="tertiary">
814         <xsl:if test="not(//indexterm[normalize-space(primary)=$primary and 
815                                       normalize-space(secondary)=$secondary and not(tertiary)])">
816           <xsl:call-template name="write.indexterm">
817             <xsl:with-param name="text" select="concat($primary, ', ', $secondary)"/>
818           </xsl:call-template>
819         </xsl:if>
820       </xsl:if>
821       
822       <xsl:call-template name="write.indexterm">
823         <xsl:with-param name="text" select="$text"/>
824       </xsl:call-template>
825       
826     </xsl:when>
827     <xsl:otherwise>
828       <a>
829         <xsl:attribute name="name">
830           <xsl:call-template name="object.id"/>
831         </xsl:attribute>
832       </a>
833     </xsl:otherwise>
834     
835   </xsl:choose>
836 </xsl:template>
837
838 <xsl:template name="write.indexterm">
839   <xsl:param name="text"/>
840   <OBJECT type="application/x-oleobject"
841           classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e">
842     <param name="Keyword" value="{$text}"/>
843   </OBJECT>
844 </xsl:template>
845
846 <!-- ==================================================================== -->
847
848 <xsl:template name="hhk">
849   <xsl:call-template name="write.chunk">
850     <xsl:with-param name="filename">
851       <xsl:if test="$manifest.in.base.dir != 0">
852         <xsl:value-of select="$base.dir"/>
853       </xsl:if>
854       <xsl:value-of select="$htmlhelp.hhk"/>
855     </xsl:with-param>
856     <xsl:with-param name="indent" select="'no'"/>
857     <xsl:with-param name="content"><xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
858 <HTML>
859 <HEAD>
860 <meta name="GENERATOR" content="Microsoft&reg; HTML Help Workshop 4.1">
861 <!-- Sitemap 1.0 -->
862 </HEAD><BODY>
863 <OBJECT type="text/site properties">
864 </OBJECT>
865 <UL>]]>
866 </xsl:text>
867 <xsl:if test="($htmlhelp.use.hhk != 0) and $htmlhelp.generate.index">
868   <xsl:choose>
869     <xsl:when test="$rootid != ''">
870       <xsl:apply-templates select="key('id',$rootid)" mode="hhk"/>
871     </xsl:when>
872     <xsl:otherwise>
873       <xsl:apply-templates select="/" mode="hhk"/>
874     </xsl:otherwise>
875   </xsl:choose>
876 </xsl:if>
877 <xsl:text disable-output-escaping="yes"><![CDATA[</UL>
878 </BODY></HTML>]]>
879 </xsl:text></xsl:with-param>
880     <xsl:with-param name="encoding" select="$htmlhelp.encoding"/>
881     <xsl:with-param name="quiet" select="$chunk.quietly"/>
882   </xsl:call-template>
883 </xsl:template>
884
885 <xsl:template match="indexterm[@class='endofrange']" mode="hhk"/>
886
887 <xsl:template match="indexterm" mode="hhk">
888   <xsl:variable name="primary" select="normalize-space(primary)"/>
889   <xsl:variable name="secondary" select="normalize-space(secondary)"/>
890   <xsl:variable name="tertiary" select="normalize-space(tertiary)"/>
891
892   <xsl:call-template name="write.indexterm.hhk">
893     <xsl:with-param name="text" select="$primary"/>
894     <xsl:with-param name="seealso" select="seealso"/>
895   </xsl:call-template>
896
897   <xsl:if test="secondary">
898     <xsl:if test="not(//indexterm[normalize-space(primary)=$primary and not(secondary)])">
899       <xsl:call-template name="write.indexterm.hhk">
900         <!-- We must create fake entry when there is secondary without primary --> 
901         <xsl:with-param name="text" select="$primary"/>
902         <xsl:with-param name="seealso" select="$primary"/>
903       </xsl:call-template>
904     </xsl:if>
905     <UL>
906     <xsl:call-template name="write.indexterm.hhk">
907       <xsl:with-param name="text" select="$secondary"/>
908       <xsl:with-param name="seealso" select="secondary/seealso"/>
909     </xsl:call-template>
910     <xsl:if test="tertiary">
911       <UL>&lf;
912       <xsl:call-template name="write.indexterm.hhk">
913         <xsl:with-param name="text" select="$tertiary"/>
914         <xsl:with-param name="seealso" select="tertiary/seealso"/>
915       </xsl:call-template>
916       </UL>
917     </xsl:if>
918     </UL>
919   </xsl:if>
920
921 </xsl:template>
922
923 <xsl:template name="write.indexterm.hhk">
924   <xsl:param name="text"/>
925   <xsl:param name="seealso"/>
926
927   <LI> <OBJECT type="text/sitemap">&lf;
928     <param name="Name">
929       <xsl:attribute name="value">
930         <xsl:value-of select="$text"/>
931       </xsl:attribute>
932     </param>&lf;
933
934       <xsl:if test="not(seealso)">
935         <xsl:variable name="href">
936           <xsl:call-template name="href.target.with.base.dir"/>
937         </xsl:variable>
938         <xsl:variable name="title">
939           <xsl:call-template name="nearest.title">
940             <xsl:with-param name="object" select=".."/>
941           </xsl:call-template>
942         </xsl:variable>
943
944         <param name="Name">
945           <xsl:attribute name="value">
946           <xsl:value-of select="$title"/>
947           </xsl:attribute>
948         </param>&lf;
949         <param name="Local">
950           <xsl:attribute name="value">
951           <xsl:value-of select="$href"/>
952           </xsl:attribute>
953         </param>&lf;
954       </xsl:if>
955
956       <xsl:if test="seealso">
957         <param name="See Also">
958           <xsl:attribute name="value">
959           <xsl:value-of select="$seealso"/>
960           </xsl:attribute>
961         </param>&lf;
962       </xsl:if>
963       </OBJECT></LI>
964 </xsl:template>
965
966 <xsl:template match="text()" mode="hhk"/>
967
968 <xsl:template name="nearest.title">
969   <xsl:param name="object"/>
970   <xsl:apply-templates select="$object/ancestor-or-self::*[title][1]" mode="title.markup"/>
971 </xsl:template>
972
973 <!-- ==================================================================== -->
974
975 <xsl:template name="hh-map">
976   <xsl:call-template name="write.text.chunk">
977     <xsl:with-param name="filename">
978       <xsl:if test="$manifest.in.base.dir != 0">
979         <xsl:value-of select="$base.dir"/>
980       </xsl:if>
981       <xsl:value-of select="$htmlhelp.map.file"/>
982     </xsl:with-param>
983     <xsl:with-param name="method" select="'text'"/>
984     <xsl:with-param name="content">
985      <xsl:choose>
986        <xsl:when test="$rootid != ''">
987          <xsl:apply-templates select="key('id',$rootid)" mode="hh-map"/>
988        </xsl:when>
989        <xsl:otherwise>
990          <xsl:apply-templates select="/" mode="hh-map"/>
991        </xsl:otherwise>
992      </xsl:choose>
993     </xsl:with-param>
994     <xsl:with-param name="encoding" select="$htmlhelp.encoding"/>
995     <xsl:with-param name="quiet" select="$chunk.quietly"/>
996   </xsl:call-template>
997 </xsl:template>
998
999 <xsl:template match="processing-instruction('dbhh')" mode="hh-map">
1000   <xsl:variable name="topicname">
1001     <xsl:call-template name="pi-attribute">
1002       <xsl:with-param name="pis"
1003                       select="."/>
1004       <xsl:with-param name="attribute" select="'topicname'"/>
1005     </xsl:call-template>
1006   </xsl:variable>
1007   <xsl:variable name="topicid">
1008     <xsl:call-template name="pi-attribute">
1009       <xsl:with-param name="pis"
1010                       select="."/>
1011       <xsl:with-param name="attribute" select="'topicid'"/>
1012     </xsl:call-template>
1013   </xsl:variable>
1014   <xsl:text>#define </xsl:text>
1015   <xsl:value-of select="$topicname"/>
1016   <xsl:text>&#9;</xsl:text>
1017   <xsl:value-of select="$topicid"/>
1018   <xsl:text>&#xA;</xsl:text>
1019 </xsl:template>
1020
1021 <xsl:template match="text()" mode="hh-map"/>
1022
1023 <!-- ==================================================================== -->
1024
1025 <xsl:template name="hh-alias">
1026   <xsl:call-template name="write.text.chunk">
1027     <xsl:with-param name="filename">
1028       <xsl:if test="$manifest.in.base.dir != 0">
1029         <xsl:value-of select="$base.dir"/>
1030       </xsl:if>
1031       <xsl:value-of select="$htmlhelp.alias.file"/>
1032     </xsl:with-param>
1033     <xsl:with-param name="method" select="'text'"/>
1034     <xsl:with-param name="content">
1035      <xsl:choose>
1036        <xsl:when test="$rootid != ''">
1037          <xsl:apply-templates select="key('id',$rootid)" mode="hh-alias"/>
1038        </xsl:when>
1039        <xsl:otherwise>
1040          <xsl:apply-templates select="/" mode="hh-alias"/>
1041        </xsl:otherwise>
1042      </xsl:choose>
1043     </xsl:with-param>
1044     <xsl:with-param name="encoding" select="$htmlhelp.encoding"/>
1045     <xsl:with-param name="quiet" select="$chunk.quietly"/>
1046   </xsl:call-template>
1047 </xsl:template>
1048
1049 <xsl:template match="processing-instruction('dbhh')" mode="hh-alias">
1050   <xsl:variable name="topicname">
1051     <xsl:call-template name="pi-attribute">
1052       <xsl:with-param name="pis"
1053                       select="."/>
1054       <xsl:with-param name="attribute" select="'topicname'"/>
1055     </xsl:call-template>
1056   </xsl:variable>
1057   <xsl:variable name="href">
1058     <xsl:call-template name="href.target.with.base.dir">
1059       <xsl:with-param name="object" select=".."/>
1060     </xsl:call-template>
1061   </xsl:variable>
1062   <xsl:value-of select="$topicname"/>
1063   <xsl:text>=</xsl:text>
1064   <!-- Some versions of HH doesn't like fragment identifires, but some does. -->
1065   <!-- <xsl:value-of select="substring-before(concat($href, '#'), '#')"/> -->
1066   <xsl:value-of select="$href"/>
1067   <xsl:text>&#xA;</xsl:text>
1068 </xsl:template>
1069
1070 <xsl:template match="text()" mode="hh-alias"/>
1071
1072 <!-- ==================================================================== -->
1073 <!-- This code can be used to convert any number to hexadecimal format -->
1074
1075   <h:hex>
1076     <d>0</d>
1077     <d>1</d>
1078     <d>2</d>
1079     <d>3</d>
1080     <d>4</d>
1081     <d>5</d>
1082     <d>6</d>
1083     <d>7</d>
1084     <d>8</d>
1085     <d>9</d>
1086     <d>A</d>
1087     <d>B</d>
1088     <d>C</d>
1089     <d>D</d>
1090     <d>E</d>
1091     <d>F</d>
1092   </h:hex>
1093
1094   <xsl:template name="toHex">
1095     <xsl:param name="n" select="0"/>
1096     <xsl:param name="digit" select="$n mod 16"/>
1097     <xsl:param name="rest" select="floor($n div 16)"/>
1098     <xsl:if test="$rest > 0">
1099       <xsl:call-template name="toHex">
1100         <xsl:with-param name="n" select="$rest"/>
1101       </xsl:call-template>
1102     </xsl:if>
1103     <xsl:value-of select="document('')//h:hex/d[$digit+1]"/>
1104   </xsl:template>
1105
1106 <!-- ==================================================================== -->
1107 <!-- Modification to standard HTML stylesheets -->
1108
1109 <!-- There are links from ToC pane to bibliodivs, so there must be anchor -->
1110 <xsl:template match="bibliodiv/title">
1111   <h3 class="{name(.)}">
1112     <xsl:call-template name="anchor">
1113       <xsl:with-param name="node" select=".."/>
1114       <xsl:with-param name="conditional" select="0"/>
1115     </xsl:call-template>
1116     <xsl:apply-templates/>
1117   </h3>
1118 </xsl:template>
1119
1120 </xsl:stylesheet>