]> git.stg.codes - stg.git/blob - doc/xslt/fo/qandaset.xsl
Added ability to list authorizers for user.
[stg.git] / doc / xslt / fo / qandaset.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
4                 version='1.0'>
5
6 <!-- ********************************************************************
7      $Id: qandaset.xsl 8350 2009-03-17 07:24:29Z bobstayton $
8      ********************************************************************
9
10      This file is part of the XSL DocBook Stylesheet distribution.
11      See ../README or http://docbook.sf.net/release/xsl/current/ for
12      copyright and other information.
13
14      ******************************************************************** -->
15
16 <!-- ==================================================================== -->
17
18 <xsl:template match="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="blockinfo/title|info/title|title">
42             <xsl:apply-templates select="(blockinfo/title|
43                                           info/title|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="qandadiv"/>
67   
68       <xsl:if test="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="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::label">
114       <xsl:call-template name="longest.term">
115         <xsl:with-param name="terms" select="descendant::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="qandaset/blockinfo/title|qandset/info/title|qandaset/title">
138   <xsl:variable name="enclsect" select="(ancestor::section
139                                         | ancestor::simplesect
140                                         | ancestor::sect5
141                                         | ancestor::sect4
142                                         | ancestor::sect3
143                                         | ancestor::sect2
144                                         | ancestor::sect1
145                                         | ancestor::refsect3
146                                         | ancestor::refsect2
147                                         | ancestor::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="qandaset/blockinfo|qandaset/info">
164   <!-- what should this template really do? -->
165   <xsl:apply-templates select="legalnotice" mode="titlepage.mode"/>
166 </xsl:template>
167
168 <xsl:template match="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="(blockinfo/title|info/title|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="qandadiv"/>
184
185       <xsl:if test="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="qandaentry"/>
197         </fo:list-block>
198       </xsl:if>
199     </fo:block>
200   </fo:block>
201 </xsl:template>
202
203 <xsl:template match="qandadiv/blockinfo/title|qandadiv/info/title|qandadiv/title">
204   <xsl:variable name="enclsect" select="(ancestor::section
205                                         | ancestor::simplesect
206                                         | ancestor::sect5
207                                         | ancestor::sect4
208                                         | ancestor::sect3
209                                         | ancestor::sect2
210                                         | ancestor::sect1
211                                         | ancestor::refsect3
212                                         | ancestor::refsect2
213                                         | ancestor::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::qandadiv)"/>
222     <xsl:with-param name="marker" select="0"/>
223     <xsl:with-param name="title">
224       <xsl:apply-templates select="parent::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="qandaentry">
235   <!-- Omit revhistory from fo:list-block because it is a table -->
236   <xsl:apply-templates select="question|answer"/>
237 </xsl:template>
238
239 <xsl:template match="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(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:if test="string-length($label.content) &gt; 0">
263                         <fo:block font-weight="bold">
264                           <xsl:copy-of select="$label.content"/>          
265                         </fo:block>
266         </xsl:if>
267     </fo:list-item-label>
268     <fo:list-item-body start-indent="body-start()">
269       <xsl:choose>
270         <xsl:when test="$deflabel = 'none' and not(label)">
271           <fo:block font-weight="bold">
272             <xsl:apply-templates select="*[local-name(.)!='label']"/>
273           </fo:block>
274         </xsl:when>
275         <xsl:otherwise>
276           <xsl:apply-templates select="*[local-name(.)!='label']"/>
277         </xsl:otherwise>
278       </xsl:choose>
279       <!-- Uncomment this line to get revhistory output in the question -->
280       <!-- <xsl:apply-templates select="preceding-sibling::revhistory"/> -->
281     </fo:list-item-body>
282   </fo:list-item>
283 </xsl:template>
284
285 <xsl:template match="answer">
286   <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
287   <xsl:variable name="entry.id">
288     <xsl:call-template name="object.id">
289       <xsl:with-param name="object" select="parent::*"/>
290     </xsl:call-template>
291   </xsl:variable>
292
293   <xsl:variable name="deflabel">
294     <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
295   </xsl:variable>
296
297       <xsl:variable name="answer.label">
298         <xsl:apply-templates select="." mode="label.markup"/>
299       </xsl:variable>
300
301   <fo:list-item xsl:use-attribute-sets="list.item.spacing">
302     <fo:list-item-label id="{$id}" end-indent="label-end()">
303       <xsl:choose>
304         <xsl:when test="string-length($answer.label) &gt; 0">
305                         <fo:block font-weight="bold">
306                           <xsl:copy-of select="$answer.label"/>
307                         </fo:block>
308         </xsl:when>
309         <xsl:otherwise>
310                         <fo:block/>
311         </xsl:otherwise>
312       </xsl:choose>
313     </fo:list-item-label>
314     <fo:list-item-body start-indent="body-start()">
315       <xsl:apply-templates select="*[local-name(.)!='label' and local-name(.) != 'qandaentry']"/>
316       <!-- * handle nested answer/qandaentry instances -->
317       <!-- * (bug 1509043 from Daniel Leidert) -->
318       <xsl:if test="descendant::question">
319         <xsl:call-template name="process.qandaset"/>
320       </xsl:if>
321     </fo:list-item-body>
322   </fo:list-item>
323 </xsl:template>
324
325 <xsl:template match="*" mode="qanda.defaultlabel">
326   <xsl:choose>
327     <xsl:when test="ancestor-or-self::*[@defaultlabel]">
328       <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
329                             /@defaultlabel"/>
330     </xsl:when>
331     <xsl:otherwise>
332       <xsl:value-of select="$qanda.defaultlabel"/>
333     </xsl:otherwise>
334   </xsl:choose>
335 </xsl:template>
336
337 <xsl:template match="label">
338   <xsl:apply-templates/>
339 </xsl:template>
340
341 <xsl:template name="qanda.heading">
342   <xsl:param name="level" select="1"/>
343   <xsl:param name="marker" select="0"/>
344   <xsl:param name="title"/>
345   <xsl:param name="titleabbrev"/>
346
347   <fo:block xsl:use-attribute-sets="qanda.title.properties">
348     <xsl:if test="$marker != 0">
349       <fo:marker marker-class-name="section.head.marker">
350         <xsl:choose>
351           <xsl:when test="$titleabbrev = ''">
352             <xsl:value-of select="$title"/>
353           </xsl:when>
354           <xsl:otherwise>
355             <xsl:value-of select="$titleabbrev"/>
356           </xsl:otherwise>
357         </xsl:choose>
358       </fo:marker>
359     </xsl:if>
360     <xsl:choose>
361       <xsl:when test="$level=1">
362         <fo:block xsl:use-attribute-sets="qanda.title.level1.properties">
363           <xsl:copy-of select="$title"/>
364         </fo:block>
365       </xsl:when>
366       <xsl:when test="$level=2">
367         <fo:block xsl:use-attribute-sets="qanda.title.level2.properties">
368           <xsl:copy-of select="$title"/>
369         </fo:block>
370       </xsl:when>
371       <xsl:when test="$level=3">
372         <fo:block xsl:use-attribute-sets="qanda.title.level3.properties">
373           <xsl:copy-of select="$title"/>
374         </fo:block>
375       </xsl:when>
376       <xsl:when test="$level=4">
377         <fo:block xsl:use-attribute-sets="qanda.title.level4.properties">
378           <xsl:copy-of select="$title"/>
379         </fo:block>
380       </xsl:when>
381       <xsl:when test="$level=5">
382         <fo:block xsl:use-attribute-sets="qanda.title.level5.properties">
383           <xsl:copy-of select="$title"/>
384         </fo:block>
385       </xsl:when>
386       <xsl:otherwise>
387         <fo:block xsl:use-attribute-sets="qanda.title.level6.properties">
388           <xsl:copy-of select="$title"/>
389         </fo:block>
390       </xsl:otherwise>
391     </xsl:choose>
392   </fo:block>
393 </xsl:template>
394
395 </xsl:stylesheet>