summaryrefslogtreecommitdiff
path: root/docs/xslt/db2latex-xsl/xsl/qandaset.mod.xsl
blob: 3cf6fb9de4c5c95b8857cd9ddf07dfbfda192a5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY % xsldoc.ent SYSTEM "./xsldoc.ent"> %xsldoc.ent; ]>
<!--############################################################################# 
|	$Id: qandaset.mod.xsl,v 1.13 2004/01/04 13:22:27 j-devenish Exp $
|- #############################################################################
|	$Author: j-devenish $
|   PURPOSE:
|   Portions (c) Norman Walsh, official DocBook XSL stylesheets.
|                See docbook.sf.net
+ ############################################################################## -->

<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" 
	exclude-result-prefixes="doc" version="1.0">

	<doc:reference id="qandaset" xmlns="">
		<referenceinfo>
			<releaseinfo role="meta">
				$Id: qandaset.mod.xsl,v 1.13 2004/01/04 13:22:27 j-devenish Exp $
			</releaseinfo>
			<authorgroup>
				&ramon;
				&james;
			</authorgroup>
			<copyright>
				<year>2000</year><year>2001</year><year>2002</year><year>2003</year><year>2004</year>
				<holder>Ramon Casellas</holder>
			</copyright>
			<revhistory>
				<doc:revision rcasver="1.11">&rev_2003_05;</doc:revision>
			</revhistory>
		</referenceinfo>
		<title>QandaSet <filename>qandaset.mod.xsl</filename></title>
		<partintro>
			<para>
			
				Portions (c) Norman Walsh, official DocBook XSL stylesheets. See docbook.sf.net
			
			</para>
		</partintro>
	</doc:reference>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>qandadiv</doc:db> elements</refpurpose>
		<doc:description>
			<para><doc:todo>Undocumented.</doc:todo></para>
		</doc:description>
	</doc:template>
<xsl:template match="qandaset">
		<!-- get all children that are not the following -->
		<xsl:variable name="preamble" select="*[name(.) != 'title'
									  and name(.) != 'titleabbrev'
									  and name(.) != 'blockinfo'
									  and name(.) != 'qandadiv'
									  and name(.) != 'qandaentry']"/>
		<xsl:variable name="label-width"/>
		<xsl:variable name="table-summary"/>
		<xsl:variable name="cellpadding"/>
		<xsl:variable name="cellspacing"/>
		<xsl:variable name="toc"/>
		<xsl:variable name="toc.params"/>
  		<xsl:variable name="qalevel">
    		<xsl:call-template name="qanda.section.level"/>
  		</xsl:variable>
		<xsl:text>% -------------------------------------------------------------&#10;</xsl:text>
		<xsl:text>% QandASet                                                     &#10;</xsl:text>
		<xsl:text>% -------------------------------------------------------------&#10;</xsl:text>
		<xsl:choose>
      		<xsl:when test="ancestor::sect2">
	    		<xsl:text>\subsubsection*{</xsl:text>
			</xsl:when>
      		<xsl:when test="ancestor::sect1">
	    		<xsl:text>\subsection*{</xsl:text>
			</xsl:when>
      		<xsl:when test="ancestor::article | ancestor::appendix">
	    		<xsl:text>\section*{</xsl:text>
			</xsl:when>
      		<xsl:when test="ancestor::book">
	    		<xsl:text>\chapter*{</xsl:text>
			</xsl:when>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="title">
				<xsl:apply-templates select="title"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>F.A.Q.</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:text>}&#10;</xsl:text>
	    <xsl:call-template name="label.id"/>
		<xsl:text>&#10;</xsl:text>

		<!-- process toc -->
		<xsl:if test="contains($toc.params, 'toc') and $toc != '0'">
			<xsl:call-template name="process.qanda.toc"/>
		</xsl:if>
		<!-- process preamble -->
		<xsl:apply-templates select="$preamble"/>
		<!-- process divs and entries -->
		<xsl:apply-templates select="qandaentry|qandadiv"/>
</xsl:template>

	<doc:template basename="qandaentry" xmlns="">
		<refpurpose>Process <doc:db>qandadiv</doc:db> elements</refpurpose>
		<doc:description>
			<para><doc:todo>Undocumented.</doc:todo></para>
		</doc:description>
	</doc:template>
	<xsl:template match="qandaset/qandaentry">
		<xsl:text>\vspace{1em}&#10;</xsl:text>
		<xsl:text>\noindent{}</xsl:text>
		<xsl:value-of select="position()"/>
		<xsl:text>.~</xsl:text>
		<xsl:apply-templates select="question"/>
		<xsl:text>\newline&#10;</xsl:text>
		<xsl:apply-templates select="answer"/>
		<xsl:text>\vspace{1em}&#10;</xsl:text>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>qandadiv</doc:db> elements</refpurpose>
		<doc:description>
			<para><doc:todo>Undocumented.</doc:todo></para>
		</doc:description>
	</doc:template>
<xsl:template match="qandadiv">
	<!-- get the preamble -->
  <xsl:variable name="preamble" select="*[name(.) != 'title'
                                          and name(.) != 'titleabbrev'
                                          and name(.) != 'qandadiv'
                                          and name(.) != 'qandaentry']"/>
  <xsl:variable name="qalevel">
    <xsl:call-template name="qandadiv.section.level"/>
  </xsl:variable>
	<!-- process the title if it exists -->
		<xsl:text>% -----------&#10;</xsl:text>
		<xsl:text>% QandADiv   &#10;</xsl:text>
		<xsl:text>% -----------&#10;</xsl:text>
		<xsl:text>\noindent\begin{minipage}{\linewidth}&#10;</xsl:text>
		<xsl:text>\vspace{0.25em}\hrule\vspace{0.25em}&#10;</xsl:text>
		<xsl:choose>
      		<xsl:when test="ancestor::sect2">
	    		<xsl:text>\paragraph*{</xsl:text>
			</xsl:when>
      		<xsl:when test="ancestor::sect1">
	    		<xsl:text>\subsubsection*{</xsl:text>
			</xsl:when>
      		<xsl:when test="ancestor::article | ancestor::appendix">
	    		<xsl:text>\subsection*{</xsl:text>
			</xsl:when>
      		<xsl:when test="ancestor::book">
	    		<xsl:text>\section*{</xsl:text>
			</xsl:when>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="title">
				<xsl:apply-templates select="title"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>F.A.Q. Part</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:text>}</xsl:text>
		<xsl:call-template name="label.id"/>
		<xsl:text>&#10;</xsl:text>
		<xsl:text>\hrule\vspace{0.25em}&#10;</xsl:text>
		<xsl:text>\end{minipage}&#10;</xsl:text>

<!--
	<xsl:text>\begin{toc}&#10;</xsl:text>
	<xsl:for-each select="qandaentry">
		<xsl:text>\tocref{</xsl:text>
		<xsl:value-of select="@id"/>
		<xsl:text>}&#10;</xsl:text>
	</xsl:for-each>
	<xsl:text>\end{toc}&#10;</xsl:text>
-->

<!-- pseudo table of contents -->
	<!--
	<xsl:choose>
		<xsl:when test="title">
			<xsl:text>\caption{</xsl:text>
			<xsl:apply-templates select="title"/>
			<xsl:text>}&#10;</xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text>\caption{</xsl:text>
			<xsl:text>F.A.Q. Part</xsl:text>
			<xsl:text>}&#10;</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
	-->
	<xsl:for-each select="qandaentry">
	<xsl:text>\noindent{}</xsl:text>
	<xsl:value-of select="position()"/>
	<xsl:text>.~</xsl:text>
	<xsl:apply-templates select="question"/>
	<xsl:if test="position()!=last()"><xsl:text>\newline&#10;</xsl:text></xsl:if>
	</xsl:for-each>
	<xsl:text>\vspace{0.25em}\hrule&#10;</xsl:text>

	<xsl:for-each select="qandaentry">
	<xsl:text>\vspace{1em}&#10;</xsl:text>
	<xsl:text>\noindent{}</xsl:text>
	<xsl:value-of select="position()"/>
	<xsl:text>.~</xsl:text>
	<xsl:apply-templates select="question"/>
	<xsl:text>\newline&#10;</xsl:text>
	<xsl:apply-templates select="answer"/>
	</xsl:for-each>
	<xsl:text>\vspace{1em}&#10;</xsl:text>
</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>question</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates as a italicised block, preceded by a bold
				letter <quote>Q</quote>.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>defaultlabel attributes are not honoured.</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="question">
		<!-- get the default label
		<xsl:variable name="deflabel">
			<xsl:choose>
				<xsl:when test="ancestor-or-self::*[@defaultlabel]">
					<xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]/@defaultlabel"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="latex.qanda.defaultlabel"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		-->
		<!-- process the question itself 
		<xsl:apply-templates select="." mode="label.markup"/>
		<xsl:choose>
			<xsl:when test="$deflabel = 'none' and not(label)">
				<xsl:apply-templates select="*[name(.) != 'label']"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates select="*[name(.) != 'label']"/>
			</xsl:otherwise>
		</xsl:choose>
		-->
		<xsl:text>\textbf{Q:}~\textit{</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>}&#10;</xsl:text>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>answer</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates as a block, preceded by a bold
				letter <quote>A</quote>.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="answer">
		<xsl:text>\noindent\textbf{A:}~</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>&#10;&#10;</xsl:text>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>label</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="label">
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template name="process.qanda.toc">
		<xsl:apply-templates select="qandadiv" mode="qandatoc.mode"/>
		<xsl:apply-templates select="qandaentry" mode="qandatoc.mode"/>
	</xsl:template>

	<doc:template basename="qandadiv" xmlns="">
		<refpurpose>Process <doc:db>qandadiv</doc:db> elements</refpurpose>
		<doc:description>
			<para><doc:todo>Undocumented.</doc:todo></para>
		</doc:description>
	</doc:template>
	<xsl:template match="qandadiv" mode="qandatoc.mode">
		<xsl:apply-templates select="title" mode="qandatoc.mode"/>
		<xsl:call-template name="process.qanda.toc"/>
	</xsl:template>

	<doc:template basename="title" xmlns="">
		<refpurpose>Process a <doc:db>qandadiv</doc:db>'s <doc:db>title</doc:db> elements</refpurpose>
		<doc:description>
			<para><doc:todo>Undocumented.</doc:todo></para>
		</doc:description>
	</doc:template>
	<xsl:template match="qandadiv/title" mode="qandatoc.mode">
		<xsl:variable name="qalevel">
			<xsl:call-template name="qandadiv.section.level"/>
		</xsl:variable>
		<xsl:call-template name="label.id">
			<xsl:with-param name="object" select="parent::*"/>
		</xsl:call-template>
		<xsl:apply-templates select="parent::qandadiv" mode="label.markup"/>
		<xsl:value-of select="$autotoc.label.separator"/>
		<xsl:apply-templates/>
	</xsl:template>

	<doc:template xmlns="" basename="qandaentry">
		<refpurpose>Process <doc:db>qandaentry</doc:db> elements</refpurpose>
		<doc:description>
			<para><doc:todo>Undocumented.</doc:todo></para>
		</doc:description>
	</doc:template>
	<xsl:template match="qandaentry" mode="qandatoc.mode">
		<xsl:apply-templates mode="qandatoc.mode"/>
	</xsl:template>

	<doc:template basename="question" xmlns="">
		<refpurpose>Process <doc:db>question</doc:db> elements</refpurpose>
		<doc:description>
			<para><doc:todo>Undocumented.</doc:todo></para>
		</doc:description>
	</doc:template>
	<xsl:template match="question" mode="qandatoc.mode">
		<xsl:variable name="firstch" select="(*[name(.)!='label'])[1]"/>
		<xsl:apply-templates select="." mode="label.markup"/>
		<xsl:text> </xsl:text>
	</xsl:template>

	<doc:template xmlns="" basename="answer">
		<refpurpose>Process <doc:db>answer</doc:db> elements</refpurpose>
		<doc:description>
			<para><doc:todo>Undocumented.</doc:todo></para>
		</doc:description>
	</doc:template>
	<xsl:template match="answer" mode="qandatoc.mode"/>

	<doc:template xmlns="" basename="revhistory">
		<refpurpose>Process <doc:db>revhistory</doc:db> elements</refpurpose>
		<doc:description>
			<para><doc:todo>Undocumented.</doc:todo></para>
		</doc:description>
	</doc:template>
	<xsl:template match="revhistory" mode="qandatoc.mode"/>

<xsl:template name="question.answer.label">
	<!-- variable: deflabel -->
  <xsl:variable name="deflabel">
  	<!-- chck whether someone has a defaultlabel attribute -->
    <xsl:choose>
		<xsl:when test="ancestor-or-self::*[@defaultlabel]">
        	<xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]/@defaultlabel"/>
	      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="latex.qanda.defaultlabel"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="label" select="@label"/>
  <xsl:choose>
    <xsl:when test="$deflabel = 'qanda'">
      <xsl:call-template name="gentext">
        <xsl:with-param name="key">
          <xsl:choose>
            <xsl:when test="local-name(.) = 'question'">question</xsl:when>
            <xsl:when test="local-name(.) = 'answer'">answer</xsl:when>
            <xsl:when test="local-name(.) = 'qandadiv'">qandadiv</xsl:when>
            <xsl:otherwise>qandaset</xsl:otherwise>
          </xsl:choose>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="$deflabel = 'label'">
      <xsl:value-of select="$label"/>
    </xsl:when>
    <xsl:when test="$deflabel = 'number' and local-name(.) = 'question'">
      <xsl:apply-templates select="ancestor::qandaset[1]" mode="number"/>
      <xsl:choose>
        <xsl:when test="ancestor::qandadiv">
          <xsl:apply-templates select="ancestor::qandadiv[1]" mode="number"/>
          <xsl:apply-templates select="ancestor::qandaentry" mode="number"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="ancestor::qandaentry" mode="number"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <!-- nothing -->
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>