]> git.lyx.org Git - lyx.git/blob - lib/docbook/xhtml/qandaset.xsl
Release notes
[lyx.git] / lib / docbook / xhtml / qandaset.xsl
1 <?xml version="1.0" encoding="ASCII"?><!--This file was created automatically by html2xhtml--><!--from the HTML stylesheets.--><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:d="http://docbook.org/ns/docbook" xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="doc d" version="1.0">
2
3 <!-- ********************************************************************
4
5      This file is part of the XSL DocBook Stylesheet distribution.
6      See ../README or http://cdn.docbook.org/release/xsl/current/ for
7      copyright and other information.
8
9      ******************************************************************** -->
10
11 <!-- ==================================================================== -->
12
13 <xsl:template match="d:qandaset">
14   <xsl:variable name="title" select="(d:blockinfo/d:title|d:info/d:title|d:title)[1]"/>
15   <xsl:variable name="preamble" select="*[local-name(.) != 'title'                                           and local-name(.) != 'titleabbrev'                                           and local-name(.) != 'qandadiv'                                           and local-name(.) != 'qandaentry']"/>
16   <xsl:variable name="toc">
17     <xsl:call-template name="pi.dbhtml_toc"/>
18   </xsl:variable>
19
20   <xsl:variable name="toc.params">
21     <xsl:call-template name="find.path.params">
22       <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
23     </xsl:call-template>
24   </xsl:variable>
25
26   <div>
27     <xsl:apply-templates select="." mode="common.html.attributes"/>
28     <xsl:call-template name="id.attribute">
29       <xsl:with-param name="conditional" select="0"/>
30     </xsl:call-template>
31     <xsl:apply-templates select="$title"/>
32     <xsl:if test="not($title)">
33       <!-- andhor is output on title if there is one -->
34       <xsl:call-template name="anchor">
35         <xsl:with-param name="conditional" select="0"/>
36       </xsl:call-template>
37     </xsl:if>
38     <xsl:if test="((contains($toc.params, 'toc') and $toc != '0') or $toc = '1')                   and not(ancestor::d:answer and not($qanda.nested.in.toc=0))">
39       <xsl:call-template name="process.qanda.toc"/>
40     </xsl:if>
41     <xsl:apply-templates select="$preamble"/>
42     <xsl:call-template name="process.qandaset"/>
43   </div>
44 </xsl:template>
45
46 <xsl:template match="d:qandaset/d:blockinfo/d:title|                      d:qandaset/d:info/d:title|                      d:qandaset/d:title">
47   <xsl:variable name="qalevel">
48     <xsl:call-template name="qanda.section.level"/>
49   </xsl:variable>
50   <xsl:element name="h{string(number($qalevel)+1)}" namespace="http://www.w3.org/1999/xhtml">
51     <xsl:apply-templates select="." mode="class.attribute"/>
52     <xsl:call-template name="anchor">
53       <xsl:with-param name="node" select=".."/>
54       <xsl:with-param name="conditional" select="0"/>
55     </xsl:call-template>
56     <xsl:apply-templates/>
57   </xsl:element>
58 </xsl:template>
59
60 <xsl:template match="d:qandaset/d:blockinfo|d:qandaset/d:info">
61   <!-- what should this template really do? -->
62   <xsl:apply-templates select="d:legalnotice" mode="titlepage.mode"/>
63 </xsl:template>
64
65 <xsl:template match="d:qandadiv">
66   <xsl:variable name="preamble" select="*[local-name(.) != 'title'                                           and local-name(.) != 'titleabbrev'                                           and local-name(.) != 'qandadiv'                                           and local-name(.) != 'qandaentry']"/>
67
68   <xsl:if test="d:blockinfo/d:title|d:info/d:title|d:title">
69     <tr class="qandadiv">
70       <td align="{$direction.align.start}" valign="top" colspan="2">
71         <xsl:apply-templates select="(d:blockinfo/d:title|d:info/d:title|d:title)[1]"/>
72       </td>
73     </tr>
74   </xsl:if>
75
76   <xsl:variable name="toc">
77     <xsl:call-template name="pi.dbhtml_toc"/>
78   </xsl:variable>
79
80   <xsl:variable name="toc.params">
81     <xsl:call-template name="find.path.params">
82       <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
83     </xsl:call-template>
84   </xsl:variable>
85
86   <xsl:if test="(contains($toc.params, 'toc') and $toc != '0') or $toc = '1'">
87     <tr class="toc">
88       <td align="{$direction.align.start}" valign="top" colspan="2">
89         <xsl:call-template name="process.qanda.toc"/>
90       </td>
91     </tr>
92   </xsl:if>
93   <xsl:if test="$preamble">
94     <tr class="toc">
95       <td align="{$direction.align.start}" valign="top" colspan="2">
96         <xsl:apply-templates select="$preamble"/>
97       </td>
98     </tr>
99   </xsl:if>
100   <xsl:apply-templates select="d:qandadiv|d:qandaentry"/>
101 </xsl:template>
102
103 <xsl:template match="d:qandadiv/d:blockinfo/d:title|                      d:qandadiv/d:info/d:title|                      d:qandadiv/d:title">
104   <xsl:variable name="qalevel">
105     <xsl:call-template name="qandadiv.section.level"/>
106   </xsl:variable>
107
108   <xsl:element name="h{string(number($qalevel)+1)}" namespace="http://www.w3.org/1999/xhtml">
109     <xsl:apply-templates select="." mode="class.attribute"/>
110     <xsl:call-template name="id.attribute">
111       <xsl:with-param name="node" select=".."/>
112       <xsl:with-param name="conditional" select="0"/>
113     </xsl:call-template>
114     <xsl:call-template name="anchor">
115       <xsl:with-param name="node" select=".."/>
116       <xsl:with-param name="conditional" select="0"/>
117     </xsl:call-template>
118     <xsl:apply-templates select="parent::d:qandadiv" mode="label.markup"/>
119     <xsl:if test="$qandadiv.autolabel != 0">
120       <xsl:apply-templates select="." mode="intralabel.punctuation"/>
121       <xsl:text> </xsl:text>
122     </xsl:if>
123     <xsl:apply-templates/>
124   </xsl:element>
125 </xsl:template>
126
127 <xsl:template match="d:qandaentry">
128   <xsl:apply-templates/>
129 </xsl:template>
130
131 <xsl:template match="d:question">
132   <xsl:variable name="deflabel">
133     <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
134   </xsl:variable>
135
136   <tr>
137     <xsl:apply-templates select="." mode="common.html.attributes"/>
138     <!-- capture the id of the  quandaentry -->
139     <xsl:call-template name="id.attribute">
140       <xsl:with-param name="node" select=".."/>
141       <xsl:with-param name="conditional" select="0"/>
142     </xsl:call-template>
143     <td align="{$direction.align.start}" valign="top">
144       <!-- and the id of the question too -->
145       <xsl:call-template name="id.attribute">
146         <xsl:with-param name="conditional" select="0"/>
147       </xsl:call-template>
148       <xsl:call-template name="anchor">
149         <xsl:with-param name="node" select=".."/>
150         <xsl:with-param name="conditional" select="0"/>
151       </xsl:call-template>
152       <xsl:call-template name="anchor">
153         <xsl:with-param name="conditional" select="0"/>
154       </xsl:call-template>
155
156       <xsl:variable name="label.content">
157         <xsl:apply-templates select="." mode="qanda.label"/>
158       </xsl:variable>
159
160       <xsl:if test="string-length($label.content) &gt; 0">
161         <p><strong>
162           <xsl:copy-of select="$label.content"/>
163         </strong></p>
164       </xsl:if>
165     </td>
166     <td align="{$direction.align.start}" valign="top">
167       <xsl:choose>
168         <xsl:when test="$deflabel = 'none' and not(d:label)">
169           <strong><xsl:apply-templates select="*[local-name(.) != 'label']"/></strong>
170         </xsl:when>
171         <xsl:otherwise>
172           <xsl:apply-templates select="*[local-name(.) != 'label']"/>
173         </xsl:otherwise>
174       </xsl:choose>
175     </td>
176   </tr>
177 </xsl:template>
178
179 <xsl:template match="*" mode="qanda.defaultlabel">
180   <xsl:choose>
181     <xsl:when test="ancestor-or-self::*[@defaultlabel]">
182       <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]                             /@defaultlabel"/>
183     </xsl:when>
184     <xsl:otherwise>
185       <xsl:value-of select="$qanda.defaultlabel"/>
186     </xsl:otherwise>
187   </xsl:choose>
188 </xsl:template>
189
190 <xsl:template match="d:question" mode="qanda.label">
191   <xsl:variable name="deflabel">
192     <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
193   </xsl:variable>
194   <xsl:apply-templates select="." mode="label.markup"/>
195   <xsl:if test="contains($deflabel, 'number') and not(d:label)">
196     <xsl:apply-templates select="." mode="intralabel.punctuation"/>
197   </xsl:if>
198 </xsl:template>
199
200 <xsl:template match="d:answer">
201   <xsl:variable name="deflabel">
202     <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
203   </xsl:variable>
204
205   <tr>
206     <xsl:apply-templates select="." mode="common.html.attributes"/>
207     <xsl:call-template name="id.attribute"/>
208     <td align="{$direction.align.start}" valign="top">
209       <xsl:call-template name="anchor"/>
210       <xsl:variable name="answer.label">
211         <xsl:apply-templates select="." mode="label.markup"/>
212       </xsl:variable>
213       <xsl:if test="string-length($answer.label) &gt; 0">
214         <p><strong>
215           <xsl:copy-of select="$answer.label"/>
216         </strong></p>
217       </xsl:if>
218     </td>
219     <td align="{$direction.align.start}" valign="top">
220       <xsl:apply-templates select="*[local-name(.) != 'label'         and local-name(.) != 'qandaentry']"/>
221       <!-- * handle nested answer/qandaentry instances -->
222       <!-- * (bug 1509043 from Daniel Leidert) -->
223       <xsl:if test="descendant::d:question">
224         <xsl:call-template name="process.qandaset"/>
225       </xsl:if>
226     </td>
227   </tr>
228 </xsl:template>
229
230 <xsl:template match="d:answer" mode="qanda.label">
231   <xsl:apply-templates select="." mode="label.markup"/>
232 </xsl:template>
233
234 <xsl:template match="d:label">
235   <xsl:apply-templates/>
236 </xsl:template>
237
238 <!-- ==================================================================== -->
239
240 <xsl:template name="process.qanda.toc">
241   <!-- * if user wants nested qandaset and qandaentry in main Qandaset TOC, -->
242   <!-- * then don't also include the nested stuff in the sub TOCs -->
243   <dl>
244     <xsl:apply-templates select="d:qandadiv" mode="qandatoc.mode"/>
245     <xsl:apply-templates select="d:qandaset|d:qandaentry" mode="qandatoc.mode"/>
246   </dl>
247 </xsl:template>
248
249 <xsl:template match="d:qandadiv" mode="qandatoc.mode">
250   <dt><xsl:apply-templates select="d:title" mode="qandatoc.mode"/></dt>
251   <dd><xsl:call-template name="process.qanda.toc"/></dd>
252 </xsl:template>
253
254 <xsl:template match="d:qandadiv/d:blockinfo/d:title|                      d:qandadiv/d:info/d:title|                      d:qandadiv/d:title" mode="qandatoc.mode">
255   <xsl:variable name="qalevel">
256     <xsl:call-template name="qandadiv.section.level"/>
257   </xsl:variable>
258   <xsl:variable name="id">
259     <xsl:call-template name="object.id">
260       <xsl:with-param name="object" select="parent::*"/>
261     </xsl:call-template>
262   </xsl:variable>
263
264   <xsl:variable name="div.label">
265     <xsl:apply-templates select="parent::d:qandadiv" mode="label.markup"/>
266   </xsl:variable>
267   <xsl:if test="string-length($div.label) != 0">
268     <xsl:copy-of select="$div.label"/>
269     <xsl:value-of select="$autotoc.label.separator"/>
270   </xsl:if>
271   <xsl:text> </xsl:text>
272   <a>
273     <xsl:attribute name="href">
274       <xsl:call-template name="href.target">
275         <xsl:with-param name="object" select="parent::*"/>
276       </xsl:call-template>
277     </xsl:attribute>
278     <xsl:apply-templates/>
279   </a>
280 </xsl:template>
281
282 <xsl:template match="d:qandaset" mode="qandatoc.mode">
283   <xsl:for-each select="d:qandaentry">
284     <xsl:apply-templates select="." mode="qandatoc.mode"/>
285   </xsl:for-each>
286 </xsl:template>
287
288 <xsl:template match="d:qandaentry" mode="qandatoc.mode">
289   <xsl:apply-templates select="d:question" mode="qandatoc.mode"/>
290 </xsl:template>
291
292 <xsl:template match="d:question" mode="qandatoc.mode">
293   <xsl:variable name="firstch">
294     <!-- Use a titleabbrev or title if available -->
295     <xsl:choose>
296       <xsl:when test="../d:blockinfo/d:titleabbrev">
297         <xsl:apply-templates select="../d:blockinfo/d:titleabbrev[1]/node()"/>
298       </xsl:when>
299       <xsl:when test="../d:blockinfo/d:title">
300         <xsl:apply-templates select="../d:blockinfo/d:title[1]/node()"/>
301       </xsl:when>
302       <xsl:when test="../d:info/d:titleabbrev">
303         <xsl:apply-templates select="../d:info/d:titleabbrev[1]/node()"/>
304       </xsl:when>
305       <xsl:when test="../d:titleabbrev">
306         <xsl:apply-templates select="../d:titleabbrev[1]/node()"/>
307       </xsl:when>
308       <xsl:when test="../d:info/d:title">
309         <xsl:apply-templates select="../d:info/d:title[1]/node()"/>
310       </xsl:when>
311       <xsl:when test="../d:title">
312         <xsl:apply-templates select="../d:title[1]/node()"/>
313       </xsl:when>
314       <xsl:otherwise>
315         <xsl:apply-templates select="(*[local-name(.)!='label'])[1]/node()"/>
316       </xsl:otherwise>
317     </xsl:choose>
318   </xsl:variable>
319   <xsl:variable name="deflabel">
320     <xsl:choose>
321       <xsl:when test="ancestor-or-self::*[@defaultlabel]">
322         <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]                               /@defaultlabel"/>
323       </xsl:when>
324       <xsl:otherwise>
325         <xsl:value-of select="$qanda.defaultlabel"/>
326       </xsl:otherwise>
327     </xsl:choose>
328   </xsl:variable>
329
330   <dt>
331     <xsl:apply-templates select="." mode="label.markup"/>
332     <xsl:if test="contains($deflabel,'number') and not(d:label)">
333       <xsl:apply-templates select="." mode="intralabel.punctuation"/>
334     </xsl:if>
335     <xsl:text> </xsl:text>
336     <a>
337       <xsl:attribute name="href">
338         <xsl:call-template name="href.target">
339           <xsl:with-param name="object" select=".."/>
340         </xsl:call-template>
341       </xsl:attribute>
342       <xsl:value-of select="$firstch"/>
343     </a>
344   </dt>
345   <!-- * include nested qandaset/qandaentry in TOC if user wants it -->
346   <xsl:if test="not($qanda.nested.in.toc = 0)">
347     <xsl:apply-templates select="following-sibling::d:answer" mode="qandatoc.mode"/>
348   </xsl:if>
349 </xsl:template>
350
351 <xsl:template match="d:answer" mode="qandatoc.mode">
352   <xsl:if test="descendant::d:question">
353     <dd>
354       <xsl:call-template name="process.qanda.toc"/>
355     </dd>
356   </xsl:if>
357 </xsl:template>
358
359 <!-- ==================================================================== -->
360
361 <xsl:template name="process.qandaset">
362
363   <xsl:variable name="deflabel">
364     <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
365   </xsl:variable>
366
367   <xsl:variable name="label-width">
368     <xsl:call-template name="pi.dbhtml_label-width"/>
369   </xsl:variable>
370
371   <xsl:variable name="table-summary">
372     <xsl:call-template name="pi.dbhtml_table-summary"/>
373   </xsl:variable>
374
375   <xsl:variable name="cellpadding">
376     <xsl:call-template name="pi.dbhtml_cellpadding"/>
377   </xsl:variable>
378
379   <xsl:variable name="cellspacing">
380     <xsl:call-template name="pi.dbhtml_cellspacing"/>
381   </xsl:variable>
382
383   <table border="{$table.border.off}">
384     <xsl:if test="$css.decoration != 0">
385       <xsl:attribute name="style">width: 100%;</xsl:attribute>
386     </xsl:if>
387     <xsl:if test="$table-summary != ''">
388       <xsl:attribute name="summary">
389         <xsl:value-of select="$table-summary"/>
390       </xsl:attribute>
391     </xsl:if>
392
393     <xsl:if test="$cellpadding != ''">
394       <xsl:attribute name="cellpadding">
395         <xsl:value-of select="$cellpadding"/>
396       </xsl:attribute>
397     </xsl:if>
398
399     <xsl:if test="$cellspacing != ''">
400       <xsl:attribute name="cellspacing">
401         <xsl:value-of select="$cellspacing"/>
402       </xsl:attribute>
403     </xsl:if>
404
405     <colgroup>
406       <col align="{$direction.align.start}">
407         <xsl:attribute name="width">
408           <xsl:choose>
409             <xsl:when test="$label-width != ''">
410               <xsl:value-of select="$label-width"/>
411             </xsl:when>
412             <xsl:otherwise>
413               <xsl:text>1%</xsl:text>
414             </xsl:otherwise>
415           </xsl:choose>
416         </xsl:attribute>
417       </col>
418       <col/>
419     </colgroup>
420     <tbody>
421       <xsl:apply-templates select="d:qandaentry|d:qandadiv"/>
422     </tbody>
423   </table>
424 </xsl:template>
425
426 <!-- ==================================================================== -->
427
428 <xsl:template match="*" mode="no.wrapper.mode">
429   <xsl:apply-templates/>
430 </xsl:template>
431
432 <!-- ==================================================================== -->
433
434 </xsl:stylesheet>