1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4                exclude-result-prefixes="doc"
5                version='1.0'>
6
7<!-- ********************************************************************
8     $Id: qandaset.xsl,v 1.22 2005/09/25 20:36:07 bobstayton Exp $
9     ********************************************************************
10
11     This file is part of the XSL DocBook Stylesheet distribution.
12     See ../README or http://nwalsh.com/docbook/xsl/ for copyright
13     and other information.
14
15     ******************************************************************** -->
16
17<!-- ==================================================================== -->
18
19<xsl:template match="qandaset">
20  <xsl:variable name="title" select="(blockinfo/title|title)[1]"/>
21  <xsl:variable name="preamble" select="*[name(.) != 'title'
22                                          and name(.) != 'titleabbrev'
23                                          and name(.) != 'qandadiv'
24                                          and name(.) != 'qandaentry']"/>
25  <xsl:variable name="label-width">
26    <xsl:call-template name="dbhtml-attribute">
27      <xsl:with-param name="pis"
28                      select="processing-instruction('dbhtml')"/>
29      <xsl:with-param name="attribute" select="'label-width'"/>
30    </xsl:call-template>
31  </xsl:variable>
32
33  <xsl:variable name="table-summary">
34    <xsl:call-template name="dbhtml-attribute">
35      <xsl:with-param name="pis"
36                      select="processing-instruction('dbhtml')"/>
37      <xsl:with-param name="attribute" select="'table-summary'"/>
38    </xsl:call-template>
39  </xsl:variable>
40
41  <xsl:variable name="cellpadding">
42    <xsl:call-template name="dbhtml-attribute">
43      <xsl:with-param name="pis"
44                      select="processing-instruction('dbhtml')"/>
45      <xsl:with-param name="attribute" select="'cellpadding'"/>
46    </xsl:call-template>
47  </xsl:variable>
48
49  <xsl:variable name="cellspacing">
50    <xsl:call-template name="dbhtml-attribute">
51      <xsl:with-param name="pis"
52                      select="processing-instruction('dbhtml')"/>
53      <xsl:with-param name="attribute" select="'cellspacing'"/>
54    </xsl:call-template>
55  </xsl:variable>
56
57  <xsl:variable name="toc">
58    <xsl:call-template name="dbhtml-attribute">
59      <xsl:with-param name="pis"
60                      select="processing-instruction('dbhtml')"/>
61      <xsl:with-param name="attribute" select="'toc'"/>
62    </xsl:call-template>
63  </xsl:variable>
64
65  <xsl:variable name="toc.params">
66    <xsl:call-template name="find.path.params">
67      <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
68    </xsl:call-template>
69  </xsl:variable>
70
71  <div class="{name(.)}">
72    <xsl:apply-templates select="$title"/>
73    <xsl:if test="(contains($toc.params, 'toc') and $toc != '0') or $toc = '1'">
74      <xsl:call-template name="process.qanda.toc"/>
75    </xsl:if>
76    <xsl:apply-templates select="$preamble"/>
77    <table border="0" summary="Q and A Set">
78      <xsl:if test="$table-summary != ''">
79        <xsl:attribute name="summary">
80          <xsl:value-of select="$table-summary"/>
81        </xsl:attribute>
82      </xsl:if>
83
84      <xsl:if test="$cellpadding != ''">
85        <xsl:attribute name="cellpadding">
86          <xsl:value-of select="$cellpadding"/>
87        </xsl:attribute>
88      </xsl:if>
89
90      <xsl:if test="$cellspacing != ''">
91        <xsl:attribute name="cellspacing">
92          <xsl:value-of select="$cellspacing"/>
93        </xsl:attribute>
94      </xsl:if>
95
96      <col align="left">
97        <xsl:attribute name="width">
98          <xsl:choose>
99            <xsl:when test="$label-width != ''">
100              <xsl:value-of select="$label-width"/>
101            </xsl:when>
102            <xsl:otherwise>1%</xsl:otherwise>
103          </xsl:choose>
104        </xsl:attribute>
105      </col>
106      <tbody>
107        <xsl:apply-templates select="qandaentry|qandadiv"/>
108      </tbody>
109    </table>
110  </div>
111</xsl:template>
112
113<xsl:template match="qandaset/blockinfo/title|qandaset/title">
114  <xsl:variable name="qalevel">
115    <xsl:call-template name="qanda.section.level"/>
116  </xsl:variable>
117  <xsl:element name="h{string(number($qalevel)+1)}">
118    <xsl:attribute name="class">
119      <xsl:value-of select="name(.)"/>
120    </xsl:attribute>
121    <xsl:apply-templates/>
122  </xsl:element>
123</xsl:template>
124
125<xsl:template match="qandaset/blockinfo">
126  <!-- what should this template really do? -->
127  <xsl:apply-templates select="legalnotice" mode="titlepage.mode"/>
128</xsl:template>
129
130<xsl:template match="qandadiv">
131  <xsl:variable name="preamble" select="*[name(.) != 'title'
132                                          and name(.) != 'titleabbrev'
133                                          and name(.) != 'qandadiv'
134                                          and name(.) != 'qandaentry']"/>
135
136  <xsl:if test="blockinfo/title|title">
137    <tr class="qandadiv">
138      <td align="left" valign="top" colspan="2">
139        <xsl:apply-templates select="(blockinfo/title|title)[1]"/>
140      </td>
141    </tr>
142  </xsl:if>
143
144  <xsl:variable name="toc">
145    <xsl:call-template name="dbhtml-attribute">
146      <xsl:with-param name="pis"
147                      select="processing-instruction('dbhtml')"/>
148      <xsl:with-param name="attribute" select="'toc'"/>
149    </xsl:call-template>
150  </xsl:variable>
151
152  <xsl:variable name="toc.params">
153    <xsl:call-template name="find.path.params">
154      <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
155    </xsl:call-template>
156  </xsl:variable>
157
158  <xsl:if test="(contains($toc.params, 'toc') and $toc != '0') or $toc = '1'">
159    <tr class="toc">
160      <td align="left" valign="top" colspan="2">
161        <xsl:call-template name="process.qanda.toc"/>
162      </td>
163    </tr>
164  </xsl:if>
165  <xsl:if test="$preamble">
166    <tr class="toc">
167      <td align="left" valign="top" colspan="2">
168        <xsl:apply-templates select="$preamble"/>
169      </td>
170    </tr>
171  </xsl:if>
172  <xsl:apply-templates select="qandadiv|qandaentry"/>
173</xsl:template>
174
175<xsl:template match="qandadiv/blockinfo/title|qandadiv/title">
176  <xsl:variable name="qalevel">
177    <xsl:call-template name="qandadiv.section.level"/>
178  </xsl:variable>
179
180  <xsl:element name="h{string(number($qalevel)+1)}">
181    <xsl:attribute name="class">
182      <xsl:value-of select="name(.)"/>
183    </xsl:attribute>
184    <xsl:call-template name="anchor">
185      <xsl:with-param name="node" select=".."/>
186      <xsl:with-param name="conditional" select="0"/>
187    </xsl:call-template>
188    <xsl:apply-templates select="parent::qandadiv" mode="label.markup"/>
189    <xsl:if test="$qandadiv.autolabel != 0">
190      <xsl:apply-templates select="." mode="intralabel.punctuation"/>
191      <xsl:text> </xsl:text>
192    </xsl:if>
193    <xsl:apply-templates/>
194  </xsl:element>
195</xsl:template>
196
197<xsl:template match="qandaentry">
198  <xsl:apply-templates/>
199</xsl:template>
200
201<xsl:template match="question">
202  <xsl:variable name="deflabel">
203    <xsl:choose>
204      <xsl:when test="ancestor-or-self::*[@defaultlabel]">
205        <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
206                              /@defaultlabel"/>
207      </xsl:when>
208      <xsl:otherwise>
209        <xsl:value-of select="$qanda.defaultlabel"/>
210      </xsl:otherwise>
211    </xsl:choose>
212  </xsl:variable>
213
214  <tr class="{name(.)}">
215    <td align="left" valign="top">
216      <xsl:call-template name="anchor">
217        <xsl:with-param name="node" select=".."/>
218        <xsl:with-param name="conditional" select="0"/>
219      </xsl:call-template>
220      <xsl:call-template name="anchor">
221        <xsl:with-param name="conditional" select="0"/>
222      </xsl:call-template>
223
224      <xsl:variable name="label.content">
225        <xsl:apply-templates select="." mode="label.markup"/>
226        <xsl:if test="$deflabel = 'number' and not(label)">
227          <xsl:apply-templates select="." mode="intralabel.punctuation"/>
228        </xsl:if>
229      </xsl:variable>
230
231      <xsl:if test="string-length($label.content) &gt; 0">
232        <b>
233          <xsl:copy-of select="$label.content"/>
234        </b>
235      </xsl:if>
236    </td>
237    <td align="left" valign="top">
238      <xsl:choose>
239        <xsl:when test="$deflabel = 'none' and not(label)">
240          <b><xsl:apply-templates select="*[name(.) != 'label']"/></b>
241        </xsl:when>
242        <xsl:otherwise>
243          <xsl:apply-templates select="*[name(.) != 'label']"/>
244        </xsl:otherwise>
245      </xsl:choose>
246    </td>
247  </tr>
248</xsl:template>
249
250<xsl:template match="answer">
251  <xsl:variable name="deflabel">
252    <xsl:choose>
253      <xsl:when test="ancestor-or-self::*[@defaultlabel]">
254        <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
255                              /@defaultlabel"/>
256      </xsl:when>
257      <xsl:otherwise>
258        <xsl:value-of select="$qanda.defaultlabel"/>
259      </xsl:otherwise>
260    </xsl:choose>
261  </xsl:variable>
262
263  <tr class="{name(.)}">
264    <td align="left" valign="top">
265      <xsl:call-template name="anchor"/>
266      <xsl:variable name="answer.label">
267        <xsl:apply-templates select="." mode="label.markup"/>
268      </xsl:variable>
269      <xsl:if test="string-length($answer.label) &gt; 0">
270        <b>
271          <xsl:copy-of select="$answer.label"/>
272        </b>
273      </xsl:if>
274    </td>
275    <td align="left" valign="top">
276      <xsl:apply-templates select="*[name(.) != 'label']"/>
277    </td>
278  </tr>
279</xsl:template>
280
281<xsl:template match="label">
282  <xsl:apply-templates/>
283</xsl:template>
284
285<!-- ==================================================================== -->
286
287<xsl:template name="process.qanda.toc">
288  <dl>
289    <xsl:apply-templates select="qandadiv" mode="qandatoc.mode"/>
290    <xsl:apply-templates select="qandaentry" mode="qandatoc.mode"/>
291  </dl>
292</xsl:template>
293
294<xsl:template match="qandadiv" mode="qandatoc.mode">
295  <dt><xsl:apply-templates select="title" mode="qandatoc.mode"/></dt>
296  <dd><xsl:call-template name="process.qanda.toc"/></dd>
297</xsl:template>
298
299<xsl:template match="qandadiv/blockinfo/title|qandadiv/title" mode="qandatoc.mode">
300  <xsl:variable name="qalevel">
301    <xsl:call-template name="qandadiv.section.level"/>
302  </xsl:variable>
303  <xsl:variable name="id">
304    <xsl:call-template name="object.id">
305      <xsl:with-param name="object" select="parent::*"/>
306    </xsl:call-template>
307  </xsl:variable>
308
309  <xsl:apply-templates select="parent::qandadiv" mode="label.markup"/>
310  <xsl:value-of select="$autotoc.label.separator"/>
311  <xsl:text> </xsl:text>
312  <a>
313    <xsl:attribute name="href">
314      <xsl:call-template name="href.target">
315        <xsl:with-param name="object" select="parent::*"/>
316      </xsl:call-template>
317    </xsl:attribute>
318    <xsl:apply-templates/>
319  </a>
320</xsl:template>
321
322<xsl:template match="qandaentry" mode="qandatoc.mode">
323  <xsl:apply-templates select="question" mode="qandatoc.mode"/>
324</xsl:template>
325
326<xsl:template match="question" mode="qandatoc.mode">
327  <xsl:variable name="firstch">
328    <xsl:apply-templates select="(*[name(.)!='label'])[1]"/>
329  </xsl:variable>
330  <xsl:variable name="deflabel">
331    <xsl:choose>
332      <xsl:when test="ancestor-or-self::*[@defaultlabel]">
333        <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
334                              /@defaultlabel"/>
335      </xsl:when>
336      <xsl:otherwise>
337        <xsl:value-of select="$qanda.defaultlabel"/>
338      </xsl:otherwise>
339    </xsl:choose>
340  </xsl:variable>
341
342  <dt>
343    <xsl:apply-templates select="." mode="label.markup"/>
344    <xsl:if test="$deflabel = 'number' and not(label)">
345      <xsl:apply-templates select="." mode="intralabel.punctuation"/>
346    </xsl:if>
347    <xsl:text> </xsl:text>
348    <a>
349      <xsl:attribute name="href">
350        <xsl:call-template name="href.target">
351          <xsl:with-param name="object" select=".."/>
352        </xsl:call-template>
353      </xsl:attribute>
354      <xsl:value-of select="$firstch"/>
355    </a>
356  </dt>
357</xsl:template>
358
359<!-- ==================================================================== -->
360
361<xsl:template match="*" mode="no.wrapper.mode">
362  <xsl:apply-templates/>
363</xsl:template>
364
365<!-- ==================================================================== -->
366
367</xsl:stylesheet>
368