Imported Upstream version 1.79.2
[platform/upstream/docbook-xsl-stylesheets.git] / fo / qandaset.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet exclude-result-prefixes="d"
3                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4                 xmlns:d="http://docbook.org/ns/docbook"
5                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
6                 version='1.0'>
7
8 <!-- ********************************************************************
9
10      This file is part of the XSL DocBook Stylesheet distribution.
11      See ../README or http://cdn.docbook.org/release/xsl/current/ for
12      copyright and other information.
13
14      ******************************************************************** -->
15
16 <!-- ==================================================================== -->
17
18 <xsl:template match="d:qandaset" name="process.qandaset">
19   <xsl:variable name="id">
20     <xsl:call-template name="object.id"/>
21   </xsl:variable>
22
23   <xsl:variable name="label-length">
24     <xsl:call-template name="qandaset.label.length"/>
25   </xsl:variable>
26   
27   <xsl:variable name="toc">
28     <xsl:call-template name="pi.dbfo_toc"/>
29   </xsl:variable>
30
31   <xsl:variable name="toc.params">
32     <xsl:call-template name="find.path.params">
33       <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
34     </xsl:call-template>
35   </xsl:variable>
36
37   <xsl:variable name="content">
38     <fo:block id="{$id}">
39       <xsl:choose>
40         <xsl:when test="parent::*">
41           <xsl:if test="d:blockinfo/d:title|d:info/d:title|d:title">
42             <xsl:apply-templates select="(d:blockinfo/d:title|
43                                           d:info/d:title|d:title)[1]"/>
44           </xsl:if>
45         </xsl:when>
46         <!-- If it is the root element -->
47         <xsl:otherwise>
48           <xsl:call-template name="qandaset.titlepage"/>
49         </xsl:otherwise>
50       </xsl:choose>
51   
52       <xsl:if test="(contains($toc.params, 'toc') and $toc != '0') 
53                     or $toc = '1'">
54         <xsl:call-template name="qandaset.toc">
55           <xsl:with-param name="toc.title.p"
56                           select="contains($toc.params, 'title')"/>
57         </xsl:call-template>
58       </xsl:if>
59
60       <xsl:call-template name="qandaset.toc.separator"/>
61
62       <xsl:apply-templates select="*[local-name(.) != 'title'
63                                    and local-name(.) != 'titleabbrev'
64                                    and local-name(.) != 'qandadiv'
65                                    and local-name(.) != 'qandaentry']"/>
66       <xsl:apply-templates select="d:qandadiv"/>
67   
68       <xsl:if test="d:qandaentry">
69         <fo:list-block xsl:use-attribute-sets="list.block.spacing"
70                        provisional-label-separation="0.2em">
71           <xsl:attribute name="provisional-distance-between-starts">
72             <xsl:choose>
73               <xsl:when test="$label-length != ''">
74                 <xsl:value-of select="$label-length"/>
75               </xsl:when>
76               <xsl:otherwise>2.5em</xsl:otherwise>
77             </xsl:choose>
78           </xsl:attribute>
79           <xsl:apply-templates select="d:qandaentry"/>
80         </fo:list-block>
81       </xsl:if>
82     </fo:block>
83   </xsl:variable>
84
85   <xsl:choose>
86     <xsl:when test="parent::*">
87       <xsl:copy-of select="$content"/>
88     </xsl:when>
89     <!-- Otherwise create a page sequence -->
90     <xsl:otherwise>
91       <xsl:apply-templates select="." mode="page.sequence">
92         <xsl:with-param name="content" select="$content"/>
93         <xsl:with-param name="master-reference" select="'body'"/>
94       </xsl:apply-templates>
95     </xsl:otherwise>
96   </xsl:choose>
97   
98 </xsl:template>
99
100 <xsl:template name="qandaset.label.length">
101   <xsl:param name="deflabel">
102     <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
103   </xsl:param>
104
105   <xsl:variable name="label-width">
106     <xsl:call-template name="pi.dbfo_label-width"/>
107   </xsl:variable>
108
109   <xsl:choose>
110     <xsl:when test="$label-width != ''">
111       <xsl:value-of select="$label-width"/>
112     </xsl:when>
113     <xsl:when test="descendant::d:label">
114       <xsl:call-template name="longest.term">
115         <xsl:with-param name="terms" select="descendant::d:label"/>
116         <xsl:with-param name="maxlength" select="20"/>
117       </xsl:call-template>
118       <xsl:text>em * 0.50</xsl:text>
119     </xsl:when>
120     <xsl:when test="contains($deflabel, 'qnumber') and
121                     $qandadiv.autolabel != 0 and
122                     $qanda.inherit.numeration != 0">
123       <xsl:text>5em</xsl:text>
124     </xsl:when>
125     <xsl:when test="$deflabel ='qnumber' and
126                     $qandadiv.autolabel != 0 and
127                     $qanda.inherit.numeration != 0">
128       <xsl:text>4em</xsl:text>
129     </xsl:when>
130     <xsl:when test="$deflabel = 'number'">
131       <xsl:text>3em</xsl:text>
132     </xsl:when>
133     <xsl:otherwise>2.5em</xsl:otherwise>
134   </xsl:choose>
135 </xsl:template>
136
137 <xsl:template match="d:qandaset/d:blockinfo/d:title|d:qandset/d:info/d:title|d:qandaset/d:title">
138   <xsl:variable name="enclsect" select="(ancestor::d:section
139                                         | ancestor::d:simplesect
140                                         | ancestor::d:sect5
141                                         | ancestor::d:sect4
142                                         | ancestor::d:sect3
143                                         | ancestor::d:sect2
144                                         | ancestor::d:sect1
145                                         | ancestor::d:refsect3
146                                         | ancestor::d:refsect2
147                                         | ancestor::d:refsect1)[last()]"/>
148   <xsl:variable name="sectlvl">
149     <xsl:call-template name="section.level">
150       <xsl:with-param name="node" select="$enclsect"/>
151     </xsl:call-template>
152   </xsl:variable>
153
154   <xsl:call-template name="qanda.heading">
155     <xsl:with-param name="level" select="$sectlvl + 1"/>
156     <xsl:with-param name="marker" select="0"/>
157     <xsl:with-param name="title">
158       <xsl:apply-templates/>
159     </xsl:with-param>
160   </xsl:call-template>
161 </xsl:template>
162
163 <xsl:template match="d:qandaset/d:blockinfo|d:qandaset/d:info">
164   <!-- what should this template really do? -->
165   <xsl:apply-templates select="d:legalnotice" mode="titlepage.mode"/>
166 </xsl:template>
167
168 <xsl:template match="d:qandadiv">
169   <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
170
171
172   <xsl:variable name="label-length">
173     <xsl:call-template name="qandaset.label.length"/>
174   </xsl:variable>
175   
176   <fo:block id="{$id}">
177     <xsl:apply-templates select="(d:blockinfo/d:title|d:info/d:title|d:title)[1]"/>
178     <xsl:apply-templates select="*[local-name(.) != 'title'
179                                  and local-name(.) != 'titleabbrev'
180                                  and local-name(.) != 'qandadiv'
181                                  and local-name(.) != 'qandaentry']"/>
182     <fo:block>
183       <xsl:apply-templates select="d:qandadiv"/>
184
185       <xsl:if test="d:qandaentry">
186         <fo:list-block xsl:use-attribute-sets="list.block.spacing"
187                        provisional-label-separation="0.2em">
188           <xsl:attribute name="provisional-distance-between-starts">
189             <xsl:choose>
190               <xsl:when test="$label-length != ''">
191                 <xsl:value-of select="$label-length"/>
192               </xsl:when>
193               <xsl:otherwise>2.5em</xsl:otherwise>
194             </xsl:choose>
195           </xsl:attribute>
196           <xsl:apply-templates select="d:qandaentry"/>
197         </fo:list-block>
198       </xsl:if>
199     </fo:block>
200   </fo:block>
201 </xsl:template>
202
203 <xsl:template match="d:qandadiv/d:blockinfo/d:title|d:qandadiv/d:info/d:title|d:qandadiv/d:title">
204   <xsl:variable name="enclsect" select="(ancestor::d:section
205                                         | ancestor::d:simplesect
206                                         | ancestor::d:sect5
207                                         | ancestor::d:sect4
208                                         | ancestor::d:sect3
209                                         | ancestor::d:sect2
210                                         | ancestor::d:sect1
211                                         | ancestor::d:refsect3
212                                         | ancestor::d:refsect2
213                                         | ancestor::d:refsect1)[last()]"/>
214   <xsl:variable name="sectlvl">
215     <xsl:call-template name="section.level">
216       <xsl:with-param name="node" select="$enclsect"/>
217     </xsl:call-template>
218   </xsl:variable>
219
220   <xsl:call-template name="qanda.heading">
221     <xsl:with-param name="level"  select="$sectlvl + 1 + count(ancestor::d:qandadiv)"/>
222     <xsl:with-param name="marker" select="0"/>
223     <xsl:with-param name="title">
224       <xsl:apply-templates select="parent::d:qandadiv" mode="label.markup"/>
225       <xsl:if test="$qandadiv.autolabel != 0">
226         <xsl:apply-templates select="." mode="intralabel.punctuation"/>
227         <xsl:text> </xsl:text>
228       </xsl:if>
229       <xsl:apply-templates/>
230     </xsl:with-param>
231   </xsl:call-template>
232 </xsl:template>
233
234 <xsl:template match="d:qandaentry">
235   <!-- Omit revhistory from fo:list-block because it is a table -->
236   <xsl:apply-templates select="d:question|d:answer"/>
237 </xsl:template>
238
239 <xsl:template match="d:question">
240   <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
241
242   <xsl:variable name="entry.id">
243     <xsl:call-template name="object.id">
244       <xsl:with-param name="object" select="parent::*"/>
245     </xsl:call-template>
246   </xsl:variable>
247
248   <xsl:variable name="deflabel">
249     <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
250   </xsl:variable>
251
252
253   <xsl:variable name="label.content">
254     <xsl:apply-templates select="." mode="label.markup"/>
255     <xsl:if test="contains($deflabel, 'number') and not(d:label)">
256       <xsl:apply-templates select="." mode="intralabel.punctuation"/>
257     </xsl:if>
258   </xsl:variable>
259
260   <fo:list-item id="{$entry.id}" xsl:use-attribute-sets="list.item.spacing">
261     <fo:list-item-label id="{$id}" end-indent="label-end()">
262       <xsl:choose>
263         <xsl:when test="string-length($label.content) &gt; 0">
264           <fo:block font-weight="bold">
265             <xsl:copy-of select="$label.content"/>          
266           </fo:block>
267         </xsl:when>
268         <xsl:otherwise>
269           <fo:block/>
270         </xsl:otherwise>
271       </xsl:choose>
272     </fo:list-item-label>
273     <fo:list-item-body start-indent="body-start()">
274       <xsl:choose>
275         <xsl:when test="$deflabel = 'none' and not(d:label)">
276           <fo:block font-weight="bold">
277             <xsl:apply-templates select="*[local-name(.)!='label']"/>
278           </fo:block>
279         </xsl:when>
280         <xsl:otherwise>
281           <xsl:apply-templates select="*[local-name(.)!='label']"/>
282         </xsl:otherwise>
283       </xsl:choose>
284       <!-- Uncomment this line to get revhistory output in the question -->
285       <!-- <xsl:apply-templates select="preceding-sibling::d:revhistory"/> -->
286     </fo:list-item-body>
287   </fo:list-item>
288 </xsl:template>
289
290 <xsl:template match="d:answer">
291   <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
292   <xsl:variable name="entry.id">
293     <xsl:call-template name="object.id">
294       <xsl:with-param name="object" select="parent::*"/>
295     </xsl:call-template>
296   </xsl:variable>
297
298   <xsl:variable name="deflabel">
299     <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
300   </xsl:variable>
301
302       <xsl:variable name="answer.label">
303         <xsl:apply-templates select="." mode="label.markup"/>
304       </xsl:variable>
305
306   <fo:list-item xsl:use-attribute-sets="list.item.spacing">
307     <fo:list-item-label id="{$id}" end-indent="label-end()">
308       <xsl:choose>
309         <xsl:when test="string-length($answer.label) &gt; 0">
310           <fo:block font-weight="bold">
311             <xsl:copy-of select="$answer.label"/>
312           </fo:block>
313         </xsl:when>
314         <xsl:otherwise>
315           <fo:block/>
316         </xsl:otherwise>
317       </xsl:choose>
318     </fo:list-item-label>
319     <fo:list-item-body start-indent="body-start()">
320       <xsl:apply-templates select="*[local-name(.)!='label' and local-name(.) != 'qandaentry']"/>
321       <!-- * handle nested answer/qandaentry instances -->
322       <!-- * (bug 1509043 from Daniel Leidert) -->
323       <xsl:if test="descendant::d:question">
324         <xsl:call-template name="process.qandaset"/>
325       </xsl:if>
326     </fo:list-item-body>
327   </fo:list-item>
328 </xsl:template>
329
330 <xsl:template match="*" mode="qanda.defaultlabel">
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:template>
341
342 <xsl:template match="d:label">
343   <xsl:apply-templates/>
344 </xsl:template>
345
346 <xsl:template name="qanda.heading">
347   <xsl:param name="level" select="1"/>
348   <xsl:param name="marker" select="0"/>
349   <xsl:param name="title"/>
350   <xsl:param name="titleabbrev"/>
351
352   <fo:block xsl:use-attribute-sets="qanda.title.properties">
353     <xsl:if test="$marker != 0">
354       <fo:marker marker-class-name="section.head.marker">
355         <xsl:choose>
356           <xsl:when test="$titleabbrev = ''">
357             <xsl:value-of select="$title"/>
358           </xsl:when>
359           <xsl:otherwise>
360             <xsl:value-of select="$titleabbrev"/>
361           </xsl:otherwise>
362         </xsl:choose>
363       </fo:marker>
364     </xsl:if>
365     <xsl:choose>
366       <xsl:when test="$level=1">
367         <fo:block xsl:use-attribute-sets="qanda.title.level1.properties">
368           <xsl:copy-of select="$title"/>
369         </fo:block>
370       </xsl:when>
371       <xsl:when test="$level=2">
372         <fo:block xsl:use-attribute-sets="qanda.title.level2.properties">
373           <xsl:copy-of select="$title"/>
374         </fo:block>
375       </xsl:when>
376       <xsl:when test="$level=3">
377         <fo:block xsl:use-attribute-sets="qanda.title.level3.properties">
378           <xsl:copy-of select="$title"/>
379         </fo:block>
380       </xsl:when>
381       <xsl:when test="$level=4">
382         <fo:block xsl:use-attribute-sets="qanda.title.level4.properties">
383           <xsl:copy-of select="$title"/>
384         </fo:block>
385       </xsl:when>
386       <xsl:when test="$level=5">
387         <fo:block xsl:use-attribute-sets="qanda.title.level5.properties">
388           <xsl:copy-of select="$title"/>
389         </fo:block>
390       </xsl:when>
391       <xsl:otherwise>
392         <fo:block xsl:use-attribute-sets="qanda.title.level6.properties">
393           <xsl:copy-of select="$title"/>
394         </fo:block>
395       </xsl:otherwise>
396     </xsl:choose>
397   </fo:block>
398 </xsl:template>
399
400 </xsl:stylesheet>