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