1<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE xsl:stylesheet [
3<!ENTITY % common.entities SYSTEM "../common/entities.ent">
4%common.entities;
5]>
6<xsl:stylesheet
7  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
8  xmlns:exsl="http://exslt.org/common"
9  xmlns="http://www.w3.org/1999/xhtml"
10  xmlns:stbl="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Table"
11  xmlns:xtbl="xalan://com.nwalsh.xalan.Table"
12  xmlns:lxslt="http://xml.apache.org/xslt"
13  xmlns:ptbl="http://nwalsh.com/xslt/ext/xsltproc/python/Table"
14  exclude-result-prefixes="exsl stbl xtbl lxslt ptbl"
15  version="1.0">
16
17<!-- $I html5-element-mods.xsl,v 1.2 2011-09-18 17:47:28 bobs Exp $ -->
18
19<!--==============================================================-->
20<!--  DocBook XSL Parameter settings                              -->
21<!--==============================================================-->
22<!-- Set these to blank so can output special HTML5 empty DOCTYPE -->
23<xsl:param name="chunker.output.doctype-system" select="''"/>
24<xsl:param name="chunker.output.doctype-public" select="''"/>
25
26<xsl:param name="table.borders.with.css" select="1"/>
27<xsl:param name="html.ext">.xhtml</xsl:param>
28<xsl:param name="toc.list.type">ul</xsl:param>
29<xsl:param name="css.decoration" select="1"/>
30<xsl:param name="make.clean.html" select="1"/>
31<xsl:param name="generate.id.attributes" select="1"/>
32<xsl:variable name="div.element">section</xsl:variable>
33
34<!--==============================================================-->
35<!--  Customized templates                                        -->
36<!--==============================================================-->
37
38<!-- HTML5: needs special doctype -->
39<xsl:template name="user.preroot">
40  <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html&gt;</xsl:text>
41</xsl:template>
42
43<!-- HTML5: Replace HTML acronum with abbr for HTML 5 -->
44<xsl:template match="acronym">
45  <xsl:call-template name="inline.charseq">
46    <xsl:with-param name="wrapper-name">abbr</xsl:with-param>
47  </xsl:call-template>
48</xsl:template>
49
50<!-- HTML5: replace border="0" with border="" -->
51<!-- HTML5: No @summary allowed -->
52<!-- HTML5: replace many table atts with CSS styles -->
53<xsl:template match="tgroup" name="tgroup">
54  <xsl:if test="not(@cols) or @cols = '' or string(number(@cols)) = 'NaN'">
55    <xsl:message terminate="yes">
56      <xsl:text>Error: CALS tables must specify the number of columns.</xsl:text>
57    </xsl:message>
58  </xsl:if>
59
60  <xsl:variable name="summary">
61    <xsl:call-template name="pi.dbhtml_table-summary"/>
62  </xsl:variable>
63
64  <xsl:variable name="cellspacing">
65    <xsl:call-template name="pi.dbhtml_cellspacing"/>
66  </xsl:variable>
67
68  <xsl:variable name="cellpadding">
69    <xsl:call-template name="pi.dbhtml_cellpadding"/>
70  </xsl:variable>
71
72  <!-- First generate colgroup with attributes -->
73  <xsl:variable name="colgroup.with.attributes">
74    <colgroup>
75      <xsl:call-template name="generate.colgroup">
76        <xsl:with-param name="cols" select="@cols"/>
77      </xsl:call-template>
78    </colgroup>
79  </xsl:variable>
80
81  <!-- then modify colgroup attributes with extension -->
82  <xsl:variable name="colgroup.with.extension">
83    <xsl:choose>
84      <xsl:when test="$use.extensions != 0
85                      and $tablecolumns.extension != 0">
86        <xsl:choose>
87          <xsl:when test="function-available('stbl:adjustColumnWidths')">
88            <xsl:copy-of select="stbl:adjustColumnWidths($colgroup.with.attributes)"/>
89          </xsl:when>
90          <xsl:when test="function-available('xtbl:adjustColumnWidths')">
91            <xsl:copy-of select="xtbl:adjustColumnWidths($colgroup.with.attributes)"/>
92          </xsl:when>
93          <xsl:when test="function-available('ptbl:adjustColumnWidths')">
94            <xsl:copy-of select="ptbl:adjustColumnWidths($colgroup.with.attributes)"/>
95          </xsl:when>
96          <xsl:otherwise>
97            <xsl:message terminate="yes">
98              <xsl:text>No adjustColumnWidths function available.</xsl:text>
99            </xsl:message>
100          </xsl:otherwise>
101        </xsl:choose>
102      </xsl:when>
103      <xsl:otherwise>
104        <xsl:copy-of select="$colgroup.with.attributes"/>
105      </xsl:otherwise>
106    </xsl:choose>
107  </xsl:variable>
108
109  <!-- Now convert to @style -->
110  <xsl:variable name="colgroup">
111    <xsl:call-template name="colgroup.with.style">
112      <xsl:with-param name="colgroup" select="$colgroup.with.extension"/>
113    </xsl:call-template>
114  </xsl:variable>
115
116  <xsl:variable name="explicit.table.width">
117    <xsl:call-template name="pi.dbhtml_table-width">
118      <xsl:with-param name="node" select=".."/>
119    </xsl:call-template>
120  </xsl:variable>
121
122  <xsl:variable name="table.width.candidate">
123    <xsl:choose>
124      <xsl:when test="$explicit.table.width != ''">
125        <xsl:value-of select="$explicit.table.width"/>
126      </xsl:when>
127      <xsl:when test="$default.table.width = ''">
128        <xsl:text>100%</xsl:text>
129      </xsl:when>
130      <xsl:otherwise>
131        <xsl:value-of select="$default.table.width"/>
132      </xsl:otherwise>
133    </xsl:choose>
134  </xsl:variable>
135
136
137  <xsl:variable name="table.width">
138    <xsl:if test="$default.table.width != ''
139                  or $explicit.table.width != ''">
140      <xsl:choose>
141        <xsl:when test="contains($table.width.candidate, '%')">
142          <xsl:value-of select="$table.width.candidate"/>
143        </xsl:when>
144        <xsl:when test="$use.extensions != 0
145                        and $tablecolumns.extension != 0">
146          <xsl:choose>
147            <xsl:when test="function-available('stbl:convertLength')">
148              <xsl:value-of select="stbl:convertLength($table.width.candidate)"/>
149            </xsl:when>
150            <xsl:when test="function-available('xtbl:convertLength')">
151              <xsl:value-of select="xtbl:convertLength($table.width.candidate)"/>
152            </xsl:when>
153            <xsl:otherwise>
154              <xsl:message terminate="yes">
155                <xsl:text>No convertLength function available.</xsl:text>
156              </xsl:message>
157            </xsl:otherwise>
158          </xsl:choose>
159        </xsl:when>
160        <xsl:otherwise>
161          <xsl:value-of select="$table.width.candidate"/>
162        </xsl:otherwise>
163      </xsl:choose>
164    </xsl:if>
165  </xsl:variable>
166
167  <!-- assemble a table @style -->
168  <xsl:variable name="table.style">
169
170    <xsl:if test="$cellspacing != '' or $html.cellspacing != ''">
171      <xsl:text>cellspacing: </xsl:text>
172      <xsl:choose>
173        <xsl:when test="$cellspacing != ''">
174          <xsl:value-of select="$cellspacing"/>
175        </xsl:when>
176        <xsl:otherwise>
177          <xsl:value-of select="$html.cellspacing"/>
178        </xsl:otherwise>
179      </xsl:choose>
180      <xsl:text>; </xsl:text>
181    </xsl:if>
182
183    <xsl:if test="$cellpadding != '' or $html.cellpadding != ''">
184      <xsl:text>cellpadding: </xsl:text>
185      <xsl:choose>
186        <xsl:when test="$cellpadding != ''">
187          <xsl:value-of select="$cellpadding"/>
188        </xsl:when>
189        <xsl:otherwise>
190          <xsl:value-of select="$html.cellpadding"/>
191        </xsl:otherwise>
192      </xsl:choose>
193      <xsl:text>; </xsl:text>
194    </xsl:if>
195
196    <xsl:choose>
197      <xsl:when test="string-length($table.width) != 0">
198        <xsl:text>width: </xsl:text>
199        <xsl:value-of select="$table.width"/>
200        <xsl:text>; </xsl:text>
201      </xsl:when>
202      <xsl:when test="../@pgwide=1 or local-name(.) = 'entrytbl'">
203        <xsl:text>width: 100%; </xsl:text>
204      </xsl:when>
205      <xsl:otherwise>
206      </xsl:otherwise>
207    </xsl:choose>
208
209    <xsl:choose>
210      <xsl:when test="../@frame='all' or (not(../@frame) and $default.table.frame='all')">
211        <xsl:text>border-collapse: collapse; </xsl:text>
212        <xsl:call-template name="border">
213          <xsl:with-param name="side" select="'top'"/>
214          <xsl:with-param name="style" select="$table.frame.border.style"/>
215          <xsl:with-param name="color" select="$table.frame.border.color"/>
216          <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
217        </xsl:call-template>
218        <xsl:call-template name="border">
219          <xsl:with-param name="side" select="'bottom'"/>
220          <xsl:with-param name="style" select="$table.frame.border.style"/>
221          <xsl:with-param name="color" select="$table.frame.border.color"/>
222          <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
223        </xsl:call-template>
224        <xsl:call-template name="border">
225          <xsl:with-param name="side" select="'left'"/>
226          <xsl:with-param name="style" select="$table.frame.border.style"/>
227          <xsl:with-param name="color" select="$table.frame.border.color"/>
228          <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
229        </xsl:call-template>
230        <xsl:call-template name="border">
231          <xsl:with-param name="side" select="'right'"/>
232          <xsl:with-param name="style" select="$table.frame.border.style"/>
233          <xsl:with-param name="color" select="$table.frame.border.color"/>
234          <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
235        </xsl:call-template>
236      </xsl:when>
237      <xsl:when test="../@frame='topbot' or (not(../@frame) and $default.table.frame='topbot')">
238        <xsl:text>border-collapse: collapse;</xsl:text>
239        <xsl:call-template name="border">
240          <xsl:with-param name="side" select="'top'"/>
241          <xsl:with-param name="style" select="$table.frame.border.style"/>
242          <xsl:with-param name="color" select="$table.frame.border.color"/>
243          <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
244        </xsl:call-template>
245        <xsl:call-template name="border">
246          <xsl:with-param name="side" select="'bottom'"/>
247          <xsl:with-param name="style" select="$table.frame.border.style"/>
248          <xsl:with-param name="color" select="$table.frame.border.color"/>
249          <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
250        </xsl:call-template>
251      </xsl:when>
252      <xsl:when test="../@frame='top' or (not(../@frame) and $default.table.frame='top')">
253        <xsl:text>border-collapse: collapse;</xsl:text>
254        <xsl:call-template name="border">
255          <xsl:with-param name="side" select="'top'"/>
256          <xsl:with-param name="style" select="$table.frame.border.style"/>
257          <xsl:with-param name="color" select="$table.frame.border.color"/>
258          <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
259        </xsl:call-template>
260      </xsl:when>
261      <xsl:when test="../@frame='bottom' or (not(../@frame) and $default.table.frame='bottom')">
262        <xsl:text>border-collapse: collapse;</xsl:text>
263        <xsl:call-template name="border">
264          <xsl:with-param name="side" select="'bottom'"/>
265          <xsl:with-param name="style" select="$table.frame.border.style"/>
266          <xsl:with-param name="color" select="$table.frame.border.color"/>
267          <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
268        </xsl:call-template>
269      </xsl:when>
270      <xsl:when test="../@frame='sides' or (not(../@frame) and $default.table.frame='sides')">
271        <xsl:text>border-collapse: collapse;</xsl:text>
272        <xsl:call-template name="border">
273          <xsl:with-param name="side" select="'left'"/>
274          <xsl:with-param name="style" select="$table.frame.border.style"/>
275          <xsl:with-param name="color" select="$table.frame.border.color"/>
276          <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
277        </xsl:call-template>
278        <xsl:call-template name="border">
279          <xsl:with-param name="side" select="'right'"/>
280          <xsl:with-param name="style" select="$table.frame.border.style"/>
281          <xsl:with-param name="color" select="$table.frame.border.color"/>
282          <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
283        </xsl:call-template>
284      </xsl:when>
285      <xsl:when test="../@frame='none'">
286        <xsl:text>border: none;</xsl:text>
287      </xsl:when>
288      <xsl:otherwise>
289        <xsl:text>border-collapse: collapse;</xsl:text>
290      </xsl:otherwise>
291    </xsl:choose>
292  </xsl:variable>
293
294  <table>
295    <!-- HTML5: no table summary allowed -->
296    <xsl:if test="string-length($table.style) != 0">
297      <xsl:attribute name="style">
298        <xsl:value-of select="$table.style"/>
299      </xsl:attribute>
300    </xsl:if>
301
302
303    <xsl:copy-of select="$colgroup"/>
304
305    <xsl:apply-templates select="thead"/>
306    <xsl:apply-templates select="tfoot"/>
307    <xsl:apply-templates select="tbody"/>
308
309    <xsl:if test=".//footnote|../title//footnote">
310      <tbody class="footnotes">
311        <tr>
312          <td colspan="{@cols}">
313            <xsl:apply-templates select=".//footnote|../title//footnote" mode="table.footnote.mode"/>
314          </td>
315        </tr>
316      </tbody>
317    </xsl:if>
318  </table>
319</xsl:template>
320
321<!-- HTML5: convert col attributes to col CSS styles -->
322<xsl:template name="colgroup.with.style">
323  <xsl:param name="colgroup"/>
324
325  <xsl:variable name="colgroup.nodeset" select="exsl:node-set($colgroup)"/>
326  <xsl:apply-templates select="$colgroup.nodeset" mode="convert.to.style"/>
327</xsl:template>
328
329<xsl:template match="colgroup" mode="convert.to.style">
330  <xsl:copy>
331    <xsl:copy-of select="@*"/>
332    <xsl:apply-templates mode="convert.to.style"/>
333  </xsl:copy>
334</xsl:template>
335
336<!-- HTML5: converts obsolete HTML attributes to CSS styles -->
337<xsl:template match="*" mode="convert.to.style">
338
339  <xsl:variable name="element" select="local-name(.)"/>
340
341  <xsl:variable name="style.from.atts">
342    <xsl:for-each select="@*">
343
344      <xsl:choose>
345        <!-- width and height attributes are ok for img element -->
346        <xsl:when test="local-name() = 'width' and $element != 'img'">
347          <xsl:variable name="attvalue" select="normalize-space(.)"/>
348          <xsl:text>width: </xsl:text>
349          <xsl:value-of select="$attvalue"/>
350          <!-- if integer value, add px unit -->
351          <xsl:if test="floor($attvalue) = $attvalue">
352            <xsl:text>px</xsl:text>
353          </xsl:if>
354          <xsl:text>; </xsl:text>
355        </xsl:when>
356
357        <xsl:when test="local-name() = 'height' and $element != 'img'">
358          <xsl:variable name="attvalue" select="normalize-space(.)"/>
359          <xsl:text>height: </xsl:text>
360          <xsl:value-of select="$attvalue"/>
361          <!-- if integer value, add px unit -->
362          <xsl:if test="floor($attvalue) = $attvalue">
363            <xsl:text>px</xsl:text>
364          </xsl:if>
365          <xsl:text>; </xsl:text>
366        </xsl:when>
367
368        <xsl:when test="local-name() = 'align'">
369          <xsl:text>text-align: </xsl:text>
370          <xsl:value-of select="."/>
371          <xsl:text>; </xsl:text>
372        </xsl:when>
373
374        <xsl:when test="local-name() = 'valign'">
375          <xsl:text>vertical-align: </xsl:text>
376          <xsl:value-of select="."/>
377          <xsl:text>; </xsl:text>
378        </xsl:when>
379
380        <xsl:when test="local-name() = 'border'">
381          <xsl:text>border: </xsl:text>
382          <xsl:value-of select="."/>
383          <xsl:text>; </xsl:text>
384        </xsl:when>
385
386        <xsl:when test="local-name() = 'cellspacing'">
387          <xsl:text>border-spacing: </xsl:text>
388          <xsl:value-of select="."/>
389          <xsl:text>px</xsl:text>
390          <xsl:text>; </xsl:text>
391        </xsl:when>
392
393        <xsl:when test="local-name() = 'cellpadding'">
394          <xsl:text>padding: </xsl:text>
395          <xsl:value-of select="."/>
396          <xsl:text>px</xsl:text>
397          <xsl:text>; </xsl:text>
398        </xsl:when>
399      </xsl:choose>
400    </xsl:for-each>
401  </xsl:variable>
402
403  <!-- merge existing styles with these new styles -->
404  <xsl:variable name="style">
405    <xsl:value-of select="concat($style.from.atts, @style)"/>
406  </xsl:variable>
407
408  <!-- HTML5: reserved for element name conversion if needed -->
409  <xsl:variable name="element.name">
410    <xsl:value-of select="local-name(.)"/>
411  </xsl:variable>
412
413  <xsl:element name="{$element.name}">
414    <xsl:if test="string-length($style) != 0">
415      <xsl:attribute name="style">
416        <xsl:value-of select="$style"/>
417      </xsl:attribute>
418    </xsl:if>
419    <!-- skip converted atts, and also skip disallowed summary attribute -->
420    <xsl:for-each select="@*">
421      <xsl:choose>
422        <xsl:when test="local-name(.) = 'width' and $element != 'img'"/>
423        <xsl:when test="local-name(.) = 'height' and $element != 'img'"/>
424        <xsl:when test="local-name(.) = 'summary'"/>
425        <xsl:when test="local-name(.) = 'border'"/>
426        <xsl:when test="local-name(.) = 'cellspacing'"/>
427        <xsl:when test="local-name(.) = 'cellpadding'"/>
428        <xsl:when test="local-name(.) = 'style'"/>
429        <xsl:when test="local-name(.) = 'align'"/>
430        <xsl:when test="local-name(.) = 'valign'"/>
431        <xsl:otherwise>
432          <xsl:copy-of select="."/>
433        </xsl:otherwise>
434      </xsl:choose>
435    </xsl:for-each>
436    <xsl:apply-templates mode="convert.to.style"/>
437  </xsl:element>
438</xsl:template>
439
440<!-- HTML5: convert some attributes to CSS style attribute -->
441<xsl:template match="entry|entrytbl">
442  <xsl:param name="col">
443    <xsl:choose>
444      <xsl:when test="@revisionflag">
445        <xsl:number from="row"/>
446      </xsl:when>
447      <xsl:otherwise>1</xsl:otherwise>
448    </xsl:choose>
449  </xsl:param>
450
451  <xsl:param name="spans"/>
452
453
454  <!-- Process with stock template -->
455  <xsl:variable name="cell">
456    <xsl:call-template name="entry">
457      <xsl:with-param name="col" select="$col"/>
458      <xsl:with-param name="spans" select="$spans"/>
459    </xsl:call-template>
460  </xsl:variable>
461
462  <xsl:variable name="cell.nodes" select="exsl:node-set($cell)"/>
463
464  <xsl:apply-templates select="$cell.nodes" mode="convert.to.style"/>
465
466</xsl:template>
467
468<xsl:template match="mediaobject|inlinemediaobject">
469  <xsl:call-template name="convert.styles"/>
470</xsl:template>
471
472<xsl:template match="qandaset">
473  <xsl:call-template name="convert.styles"/>
474</xsl:template>
475
476<xsl:template match="calloutlist|revhistory|footnote|figure|co">
477  <xsl:call-template name="convert.styles"/>
478</xsl:template>
479
480<xsl:template match="revhistory" mode="titlepage.mode">
481  <xsl:call-template name="convert.styles"/>
482</xsl:template>
483
484<xsl:template match="variablelist">
485  <xsl:call-template name="convert.styles"/>
486</xsl:template>
487
488<xsl:template match="orderedlist[@inheritnum = 'inherit']">
489  <xsl:call-template name="convert.styles"/>
490</xsl:template>
491
492<xsl:template match="simplelist">
493  <xsl:call-template name="convert.styles"/>
494</xsl:template>
495
496<xsl:template match="blockquote">
497  <xsl:call-template name="convert.styles"/>
498</xsl:template>
499
500<xsl:template match="note|important|warning|caution|tip">
501  <xsl:call-template name="convert.styles"/>
502</xsl:template>
503
504<xsl:template match="funcprototype" mode="ansi-tabular">
505  <xsl:call-template name="convert.styles"/>
506</xsl:template>
507
508<xsl:template match="funcprototype" mode="kr-tabular">
509  <xsl:call-template name="convert.styles"/>
510</xsl:template>
511
512<xsl:template name="convert.styles">
513  <xsl:param name="content">
514   <xsl:apply-imports/>
515  </xsl:param>
516  <xsl:variable name="nodes" select="exsl:node-set($content)"/>
517
518  <xsl:apply-templates mode="convert.to.style" select="$nodes"/>
519</xsl:template>
520
521<!-- HTML5: link rel="home" is not permitted -->
522<!-- Add support for attributes on <html> element  -->
523<xsl:template match="*" mode="process.root">
524  <xsl:variable name="doc" select="self::*"/>
525
526  <xsl:call-template name="user.preroot"/>
527  <xsl:call-template name="root.messages"/>
528
529  <html>
530    <xsl:call-template name="root.attributes"/>
531    <head>
532      <xsl:call-template name="system.head.content">
533        <xsl:with-param name="node" select="$doc"/>
534      </xsl:call-template>
535      <xsl:call-template name="head.content">
536        <xsl:with-param name="node" select="$doc"/>
537      </xsl:call-template>
538      <xsl:call-template name="user.head.content">
539        <xsl:with-param name="node" select="$doc"/>
540      </xsl:call-template>
541    </head>
542    <body>
543      <xsl:call-template name="body.attributes"/>
544      <xsl:call-template name="user.header.content">
545        <xsl:with-param name="node" select="$doc"/>
546      </xsl:call-template>
547      <xsl:apply-templates select="."/>
548      <xsl:call-template name="user.footer.content">
549        <xsl:with-param name="node" select="$doc"/>
550      </xsl:call-template>
551    </body>
552  </html>
553  <xsl:value-of select="$html.append"/>
554
555  <!-- Generate any css files only once, not once per chunk -->
556  <xsl:call-template name="generate.css.files"/>
557</xsl:template>
558
559<xsl:template name="root.attributes">
560</xsl:template>
561
562<!-- HTML5: uses <ul> instead of <dl> for TOC -->
563<xsl:template match="question" mode="qandatoc.mode">
564  <xsl:variable name="firstch">
565    <!-- Use a titleabbrev or title if available -->
566    <xsl:choose>
567      <xsl:when test="../blockinfo/titleabbrev">
568        <xsl:apply-templates select="../blockinfo/titleabbrev[1]/node()"/>
569      </xsl:when>
570      <xsl:when test="../blockinfo/title">
571        <xsl:apply-templates select="../blockinfo/title[1]/node()"/>
572      </xsl:when>
573      <xsl:when test="../info/titleabbrev">
574        <xsl:apply-templates select="../info/titleabbrev[1]/node()"/>
575      </xsl:when>
576      <xsl:when test="../titleabbrev">
577        <xsl:apply-templates select="../titleabbrev[1]/node()"/>
578      </xsl:when>
579      <xsl:when test="../info/title">
580        <xsl:apply-templates select="../info/title[1]/node()"/>
581      </xsl:when>
582      <xsl:when test="../title">
583        <xsl:apply-templates select="../title[1]/node()"/>
584      </xsl:when>
585      <xsl:otherwise>
586        <xsl:apply-templates select="(*[local-name(.)!='label'])[1]/node()"/>
587      </xsl:otherwise>
588    </xsl:choose>
589  </xsl:variable>
590  <xsl:variable name="deflabel">
591    <xsl:choose>
592      <xsl:when test="ancestor-or-self::*[@defaultlabel]">
593        <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
594                              /@defaultlabel"/>
595      </xsl:when>
596      <xsl:otherwise>
597        <xsl:value-of select="$qanda.defaultlabel"/>
598      </xsl:otherwise>
599    </xsl:choose>
600  </xsl:variable>
601
602  <li>
603    <a>
604      <xsl:attribute name="href">
605        <xsl:call-template name="href.target">
606          <xsl:with-param name="object" select=".."/>
607        </xsl:call-template>
608      </xsl:attribute>
609      <xsl:apply-templates select="." mode="label.markup"/>
610      <xsl:if test="contains($deflabel,'number') and not(label)">
611        <xsl:apply-templates select="." mode="intralabel.punctuation"/>
612      </xsl:if>
613      <xsl:text> </xsl:text>
614      <xsl:value-of select="$firstch"/>
615    </a>
616    <!-- * include nested qandaset/qandaentry in TOC if user wants it -->
617
618    <xsl:if test="not($qanda.nested.in.toc = 0)">
619      <xsl:apply-templates select="following-sibling::answer" mode="qandatoc.mode"/>
620    </xsl:if>
621  </li>
622</xsl:template>
623
624<xsl:template match="answer" mode="qandatoc.mode">
625  <xsl:if test="descendant::question">
626    <xsl:call-template name="process.qanda.toc"/>
627  </xsl:if>
628</xsl:template>
629
630<!-- html5 uses <ul> instead of <dl> for toc -->
631<xsl:template name="process.qanda.toc">
632  <ul>
633    <xsl:apply-templates select="qandadiv" mode="qandatoc.mode"/>
634    <xsl:apply-templates select="qandaset|qandaentry" mode="qandatoc.mode"/>
635  </ul>
636</xsl:template>
637
638<xsl:template match="qandadiv" mode="qandatoc.mode">
639  <!--
640  <dt><xsl:apply-templates select="title" mode="qandatoc.mode"/></dt>
641  <dd><xsl:call-template name="process.qanda.toc"/></dd>
642  -->
643  <li>
644    <xsl:apply-templates select="title" mode="qandatoc.mode"/>
645    <xsl:call-template name="process.qanda.toc"/>
646  </li>
647</xsl:template>
648
649<!-- output html5 video and source elements -->
650<xsl:template match="videoobject">
651  <video>
652    <xsl:call-template name="common.html.attributes"/>
653    <xsl:call-template name="video.poster"/>
654    <!-- copy videodata attributes from first videodata child only -->
655    <xsl:apply-templates select="videodata[1]/@*" mode="video.attribute"/>
656    <xsl:apply-templates select="videodata[1]/multimediaparam" mode="video.attribute"/>
657
658    <!-- generate <source> element for each videodata element -->
659    <xsl:apply-templates select="videodata"/>
660
661    <!-- add any fallback content -->
662    <xsl:call-template name="video.fallback"/>
663
664  </video>
665</xsl:template>
666
667<!-- output html5 audio and source elements -->
668<xsl:template match="audioobject">
669  <audio>
670    <xsl:call-template name="common.html.attributes"/>
671
672    <!-- copy audiodata attributes from first audiodata child only -->
673    <xsl:apply-templates select="audiodata[1]/@*" mode="audio.attribute"/>
674    <xsl:apply-templates select="audiodata[1]/multimediaparam" mode="audio.attribute"/>
675
676    <!-- generate <source> element for each videodata element -->
677    <xsl:apply-templates select="audiodata"/>
678
679    <!-- add any fallback content -->
680    <xsl:call-template name="audio.fallback"/>
681
682  </audio>
683</xsl:template>
684
685<xsl:template match="videodata">
686
687  <xsl:variable name="filename">
688    <xsl:call-template name="mediaobject.filename">
689      <!-- Call it with the videodata as the object -->
690      <xsl:with-param name="object" select="."/>
691    </xsl:call-template>
692  </xsl:variable>
693
694  <source>
695    <xsl:call-template name="common.html.attributes"/>
696
697    <xsl:attribute name="src">
698      <xsl:value-of select="$filename"/>
699    </xsl:attribute>
700
701    <xsl:apply-templates select="@format" mode="source.attribute"/>
702
703    <xsl:apply-templates select="multimediaparam" mode="source.attribute"/>
704
705  </source>
706</xsl:template>
707
708<xsl:template match="audiodata">
709
710  <xsl:variable name="filename">
711    <xsl:call-template name="mediaobject.filename">
712      <!-- Call it with the videodata as the object -->
713      <xsl:with-param name="object" select="."/>
714    </xsl:call-template>
715  </xsl:variable>
716
717  <source>
718    <xsl:call-template name="common.html.attributes"/>
719
720    <xsl:attribute name="src">
721      <xsl:value-of select="$filename"/>
722    </xsl:attribute>
723
724    <xsl:apply-templates select="@format" mode="source.attribute"/>
725
726    <xsl:apply-templates select="multimediaparam" mode="source.attribute"/>
727
728  </source>
729</xsl:template>
730
731<!-- attributes handled in modes, so default is off -->
732<xsl:template match="@*" mode="source.attribute"/>
733<xsl:template match="@*" mode="video.attribute"/>
734<xsl:template match="@*" mode="audio.attribute"/>
735
736<xsl:template match="@format" mode="source.attribute">
737  <xsl:attribute name="type">
738    <xsl:value-of select="normalize-space(.)"/>
739  </xsl:attribute>
740</xsl:template>
741
742<!-- use only an imageobject with @role = 'poster' -->
743<xsl:template name="video.poster">
744  <!-- context is videoobject -->
745  <xsl:variable name="imageobject"
746                select="../../imageobject[@role = 'poster'][1] |
747                           ../imageobject[@role = 'poster'][1]"/>
748  <xsl:if test="$imageobject">
749    <xsl:attribute name="poster">
750      <xsl:value-of select="$imageobject/imagedata/@fileref"/>
751    </xsl:attribute>
752  </xsl:if>
753</xsl:template>
754
755<xsl:template match="videodata/@fileref" mode="source.attribute">
756  <!-- process in normal mode -->
757  <xsl:apply-templates select="."/>
758</xsl:template>
759
760<xsl:template match="videodata/@fileref" mode="video.attribute"/>
761
762<xsl:template match="audiodata/@fileref" mode="source.attribute">
763  <!-- process in normal mode -->
764  <xsl:apply-templates select="."/>
765</xsl:template>
766
767<xsl:template match="audiodata/@fileref" mode="audio.attribute"/>
768
769<xsl:template match="videodata/@contentwidth | videodata/@width"
770              mode="video.attribute">
771  <xsl:attribute name="width">
772    <xsl:value-of select="."/>
773  </xsl:attribute>
774</xsl:template>
775
776<xsl:template match="videodata/@contentdepth | videodata/@depth"
777              mode="video.attribute">
778  <xsl:attribute name="height">
779    <xsl:value-of select="."/>
780  </xsl:attribute>
781</xsl:template>
782
783<xsl:template match="multimediaparam" mode="source.attribute"/>
784<xsl:template match="multimediaparam" mode="video.attribute"/>
785
786<xsl:template match="multimediaparam[@name = 'autoplay' or
787                                       @name = 'controls' or
788                                       @name = 'height' or
789                                       @name = 'loop' or
790                                       @name = 'muted' or
791                                       @name = 'preload' or
792                                       @name = 'width']"
793             mode="video.attribute">
794  <xsl:call-template name="process.multimediaparam">
795    <xsl:with-param name="object" select=".."/>
796    <xsl:with-param name="param.name" select="@name"/>
797    <xsl:with-param name="param.value" select="@value"/>
798  </xsl:call-template>
799</xsl:template>
800
801<xsl:template match="multimediaparam[@name = 'autoplay' or
802                                       @name = 'controls' or
803                                       @name = 'loop' or
804                                       @name = 'muted' or
805                                       @name = 'preload']"
806             mode="audio.attribute">
807  <xsl:call-template name="process.multimediaparam">
808    <xsl:with-param name="object" select=".."/>
809    <xsl:with-param name="param.name" select="@name"/>
810    <xsl:with-param name="param.value" select="@value"/>
811  </xsl:call-template>
812</xsl:template>
813
814<xsl:template match="multimediaparam[not(@name = 'autoplay' or
815                                       @name = 'controls' or
816                                       @name = 'height' or
817                                       @name = 'loop' or
818                                       @name = 'muted' or
819                                       @name = 'preload' or
820                                       @name = 'width')]"
821             mode="source.attribute">
822  <xsl:call-template name="process.multimediaparam">
823    <xsl:with-param name="object" select=".."/>
824    <xsl:with-param name="param.name" select="@name"/>
825    <xsl:with-param name="param.value" select="@value"/>
826  </xsl:call-template>
827</xsl:template>
828
829
830<!-- Determines the best value of a media attribute from the
831  attributes and multimediaparam elements -->
832<xsl:template name="process.multimediaparam">
833  <xsl:param name="object" select="NOTANELEMENT"/>
834  <xsl:param name="param.name"/>
835  <xsl:param name="param.value"/>
836
837  <xsl:choose>
838    <xsl:when test="$object/*/@*[local-name(.) = $param.name]">
839      <!-- explicit attribute with that name takes precedence -->
840      <xsl:attribute name="{$param.name}">
841        <xsl:value-of select="$object/*/@*[local-name(.) = $param.name]"/>
842      </xsl:attribute>
843    </xsl:when>
844    <xsl:otherwise>
845      <xsl:attribute name="{$param.name}">
846        <xsl:value-of select="$param.value"/>
847      </xsl:attribute>
848    </xsl:otherwise>
849  </xsl:choose>
850</xsl:template>
851
852<xsl:template name="video.fallback">
853  <xsl:param name="videoobject" select="."/>
854  <xsl:variable name="textobject" select="$videoobject/../textobject"/>
855
856  <xsl:choose>
857    <xsl:when test="$textobject">
858      <xsl:apply-templates select="$textobject" mode="fallback"/>
859    </xsl:when>
860    <xsl:otherwise>
861      <xsl:call-template name="video.fallback.text"/>
862    </xsl:otherwise>
863  </xsl:choose>
864</xsl:template>
865
866<xsl:template name="video.fallback.text">
867  <xsl:call-template name="gentext">
868    <xsl:with-param name="key" select="'video-unsupported'"/>
869  </xsl:call-template>
870</xsl:template>
871
872<xsl:template name="audio.fallback">
873  <xsl:param name="audiodata" select="."/>
874  <xsl:variable name="textobject" select="$audiodata/../../textobject"/>
875
876  <xsl:choose>
877    <xsl:when test="$textobject">
878      <xsl:apply-templates select="$textobject" mode="fallback"/>
879    </xsl:when>
880    <xsl:otherwise>
881      <xsl:call-template name="audio.fallback.text"/>
882    </xsl:otherwise>
883  </xsl:choose>
884
885</xsl:template>
886
887<xsl:template name="audio.fallback.text">
888  <xsl:call-template name="gentext">
889    <xsl:with-param name="key" select="'audio-unsupported'"/>
890  </xsl:call-template>
891</xsl:template>
892
893<xsl:template match="textobject" mode="fallback">
894  <div>
895    <xsl:apply-templates select="." mode="class.attribute"/>
896    <xsl:apply-templates/>
897  </div>
898</xsl:template>
899
900<!-- HTML5: no body attributes -->
901<xsl:template name="body.attributes"/>
902
903</xsl:stylesheet>
904