Debian Codegraph @

xsl/qandaset.xsl

raw
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
3
4 <!--############################################################################
5 XSLT Stylesheet DocBook -> LaTeX
6 ############################################################################ -->
7
8 <!-- qandaset parameters -->
9 <xsl:param name="qanda.defaultlabel">number</xsl:param>
10
11
12 <xsl:template match="qandaset">
13 <!-- is it displayed as a section? -->
14 <xsl:variable name="title"
15 select="(title|blockinfo/title|info/title)[1]"/>
16
17 <xsl:if test="$title">
18 <xsl:call-template name="makeheading">
19 <xsl:with-param name="level">
20 <xsl:call-template name="get.sect.level"/>
21 </xsl:with-param>
22 <xsl:with-param name="num" select="'0'"/>
23 <xsl:with-param name="title" select="$title"/>
24 </xsl:call-template>
25 </xsl:if>
26
27 <xsl:apply-templates/>
28 </xsl:template>
29
30 <xsl:template match="qandaset/title"/>
31 <xsl:template match="qandaset/blockinfo"/>
32
33
34 <!-- ############
35 # qandadiv #
36 ############ -->
37
38 <xsl:template match="qandadiv/title"/>
39
40 <xsl:template match="qandadiv">
41 <!-- display the title according the section depth -->
42 <xsl:variable name="l">
43 <xsl:value-of select="count(ancestor::qandadiv)"/>
44 </xsl:variable>
45 <xsl:variable name="lset">
46 <xsl:call-template name="get.sect.level">
47 <xsl:with-param name="n" select="ancestor::qandaset"/>
48 </xsl:call-template>
49 </xsl:variable>
50
51 <xsl:if test="blockinfo/title|info/title|title">
52 <xsl:call-template name="makeheading">
53 <xsl:with-param name="level">
54 <xsl:choose>
55 <xsl:when test="ancestor::qandaset[title|blockinfo/title|info/title]">
56 <xsl:value-of select="$l+$lset+1"/>
57 </xsl:when>
58 <xsl:otherwise>
59 <xsl:value-of select="$l+$lset"/>
60 </xsl:otherwise>
61 </xsl:choose>
62 </xsl:with-param>
63 </xsl:call-template>
64 </xsl:if>
65
66 <xsl:apply-templates/>
67 </xsl:template>
68
69
70 <!-- ##############
71 # qandaentry #
72 ############## -->
73
74 <!-- should be really processed -->
75 <xsl:template match="label"/>
76
77 <xsl:template match="qandaentry">
78 <xsl:variable name="defaultlabel">
79 <xsl:choose>
80 <xsl:when test="ancestor::qandaset[@defaultlabel]">
81 <xsl:value-of select="ancestor::qandaset/@defaultlabel"/>
82 </xsl:when>
83 <xsl:otherwise>
84 <xsl:value-of select="$qanda.defaultlabel"/>
85 </xsl:otherwise>
86 </xsl:choose>
87 </xsl:variable>
88
89 <!-- if default label is a number, display the quandaentries
90 like an enumerate list
91 -->
92 <xsl:if test="not(preceding-sibling::qandaentry) and
93 $defaultlabel='number'">
94 <xsl:text>&#10;\begin{enumerate}&#10;</xsl:text>
95 </xsl:if>
96
97 <xsl:apply-templates select="question" mode="wp">
98 <xsl:with-param name="defaultlabel" select="$defaultlabel"/>
99 </xsl:apply-templates>
100 <xsl:apply-templates select="answer" mode="wp">
101 <xsl:with-param name="defaultlabel" select="$defaultlabel"/>
102 </xsl:apply-templates>
103
104 <xsl:if test="not(following-sibling::qandaentry) and
105 $defaultlabel='number'">
106 <xsl:text>&#10;\end{enumerate}</xsl:text>
107 </xsl:if>
108 </xsl:template>
109
110 <xsl:template match="question" mode="wp">
111 <xsl:param name="defaultlabel"/>
112
113 <xsl:choose>
114 <xsl:when test="$defaultlabel='number'">
115 <xsl:text>\item</xsl:text>
116 <xsl:if test="label">
117 <!-- label has priority on defaultlabel -->
118 <xsl:text>[\textbf{</xsl:text>
119 <xsl:value-of select="label"/>
120 <xsl:text>}]</xsl:text>
121 </xsl:if>
122 <xsl:text>{}</xsl:text>
123 </xsl:when>
124 <xsl:when test="label">
125 <xsl:text>\textbf{</xsl:text>
126 <xsl:value-of select="label"/>
127 <xsl:text>}~</xsl:text>
128 </xsl:when>
129 <xsl:when test="$defaultlabel='qanda'">
130 <xsl:text>\textbf{</xsl:text>
131 <xsl:call-template name="gentext">
132 <xsl:with-param name="key" select="'question'"/>
133 </xsl:call-template>
134 <xsl:text>}~</xsl:text>
135 </xsl:when>
136 <xsl:otherwise>
137 <xsl:text>&#10;</xsl:text>
138 </xsl:otherwise>
139 </xsl:choose>
140
141 <!-- don't use textit since we can have several paragraphs -->
142 <xsl:text>{\it </xsl:text>
143 <xsl:apply-templates/>
144 <xsl:text>}&#10;</xsl:text>
145 </xsl:template>
146
147 <xsl:template match="answer" mode="wp">
148 <xsl:param name="defaultlabel"/>
149
150 <xsl:choose>
151 <xsl:when test="$defaultlabel='number'">
152 <!-- answers are other paragraphs of the enumerated entry -->
153 <xsl:text>&#10;</xsl:text>
154 </xsl:when>
155 <xsl:when test="label">
156 <xsl:text>&#10;\noindent\textbf{</xsl:text>
157 <xsl:value-of select="label"/>
158 <xsl:text>}~</xsl:text>
159 </xsl:when>
160 <xsl:when test="$defaultlabel='qanda'">
161 <xsl:text>&#10;\noindent\textbf{</xsl:text>
162 <xsl:call-template name="gentext">
163 <xsl:with-param name="key" select="'answer'"/>
164 </xsl:call-template>
165 <xsl:text>}~</xsl:text>
166 </xsl:when>
167 <xsl:otherwise>
168 <xsl:text>&#10;</xsl:text>
169 </xsl:otherwise>
170 </xsl:choose>
171
172 <xsl:apply-templates/>
173 <xsl:text>&#10;&#10;</xsl:text>
174 </xsl:template>
175
176
177 </xsl:stylesheet>