Debian Codegraph @

xsl/callout.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 <!-- Callout parameters -->
9 <xsl:param name="co.tagout" select="'&lt;/t&gt;'"/>
10 <xsl:param name="co.linkends.show" select="'1'"/>
11 <xsl:param name="callout.markup.circled" select="'1'"/>
12 <xsl:param name="callout.linkends.hot" select="'1'"/>
13 <xsl:param name="calloutlist.style" select="'leftmargin=1cm,style=sameline'"/>
14
15 <!-- Prerequesite: the following latex macros are defined:
16 * \co{text}
17 * \coref{text}{label}
18 * \colabel{label}
19 * \collabel{label}
20 -->
21
22
23 <!-- Generate the enter TeX escape sequence for <co>. The principle is to
24 find the first sequence of the form "<[try]" that is not contained in
25 the listing, to ensure that no conflict will occur with lstlisting -->
26
27 <xsl:template name="co-tagin-gen">
28 <xsl:param name="text" select="."/>
29 <xsl:param name="try" select="'0'"/>
30 <xsl:variable name="tag">
31 <xsl:text>&lt;</xsl:text>
32 <xsl:if test="$try &gt; 0">
33 <xsl:value-of select="$try"/>
34 </xsl:if>
35 </xsl:variable>
36
37 <xsl:choose>
38 <xsl:when test="contains($text, $tag)">
39 <!-- <xsl:message>Try another escape sequence in verbatim</xsl:message> -->
40 <xsl:call-template name="co-tagin-gen">
41 <xsl:with-param name="text" select="$text"/>
42 <xsl:with-param name="try" select="$try+1"/>
43 </xsl:call-template>
44 </xsl:when>
45 <xsl:otherwise>
46 <!-- Ok, this sequence can be used safely -->
47 <xsl:value-of select="$tag"/>
48 </xsl:otherwise>
49 </xsl:choose>
50 </xsl:template>
51
52
53 <!-- Create the link to the referenced element -->
54 <xsl:template name="coref.link.create">
55 <xsl:param name="ref"/>
56 <xsl:param name="rnode" select="/"/>
57 <xsl:param name="circled" select="0"/>
58
59 <!-- Cannot use directly id() because it must work on several RTF -->
60 <!-- The element is also searched in the root tree for things stripped
61 in the RTF, like <areaset>s -->
62 <xsl:variable name="coitem"
63 select="($rnode//*[@id=$ref or @xml:id=$ref]|
64 //*[@id=$ref or @xml:id=$ref])[1]"/>
65 <xsl:apply-templates select="$coitem" mode="coref.link">
66 <xsl:with-param name="circled" select="$circled"/>
67 <xsl:with-param name="from" select="local-name(.)"/>
68 </xsl:apply-templates>
69 </xsl:template>
70
71
72 <!-- Create the link to a <co> (maybe via <area>) or a <callout> -->
73 <xsl:template match="co|area|callout" mode="coref.link">
74 <xsl:param name="circled" select="0"/>
75 <xsl:param name="from"/>
76 <xsl:variable name="coval">
77 <xsl:apply-templates select="." mode="conumber"/>
78 </xsl:variable>
79
80 <!-- The markup can be a bubble or a simple number -->
81 <xsl:variable name="markup">
82 <xsl:choose>
83 <xsl:when test="$circled != 0">
84 <xsl:text>\conum{</xsl:text>
85 <xsl:value-of select="$coval"/>
86 <xsl:text>}</xsl:text>
87 </xsl:when>
88 <xsl:when test="$from='callout' and $callout.markup.circled='1'">
89 <xsl:text>\conum{</xsl:text>
90 <xsl:value-of select="$coval"/>
91 <xsl:text>}</xsl:text>
92 </xsl:when>
93 <xsl:otherwise>
94 <xsl:value-of select="$coval"/>
95 </xsl:otherwise>
96 </xsl:choose>
97 </xsl:variable>
98
99 <!-- In <callout> the markup can be not hot -->
100 <xsl:choose>
101 <xsl:when test="$callout.linkends.hot='0' and $from='callout'">
102 <xsl:value-of select="$markup"/>
103 </xsl:when>
104 <xsl:otherwise>
105 <xsl:text>\hyperref[</xsl:text>
106 <xsl:call-template name="id-encode"/>
107 <xsl:text>]{</xsl:text>
108 <xsl:value-of select="$markup"/>
109 <xsl:text>}</xsl:text>
110 </xsl:otherwise>
111 </xsl:choose>
112 </xsl:template>
113
114 <!-- A link to an areaset means linking to each contained <area> -->
115 <xsl:template match="areaset" mode="coref.link">
116 <xsl:param name="circled" select="0"/>
117 <xsl:param name="from"/>
118 <xsl:for-each select="area">
119 <xsl:apply-templates select="." mode="coref.link">
120 <xsl:with-param name="circled" select="$circled"/>
121 <xsl:with-param name="from" select="$from"/>
122 </xsl:apply-templates>
123 <xsl:if test="position()!=last()">
124 <xsl:text>, </xsl:text>
125 </xsl:if>
126 </xsl:for-each>
127 </xsl:template>
128
129
130 <!-- Split and make the references of the arearefs/linkends list -->
131 <xsl:template name="corefs.split">
132 <xsl:param name="refs"/>
133 <xsl:param name="rnode" select="/"/>
134 <xsl:choose>
135 <xsl:when test="contains($refs, ' ')">
136 <xsl:call-template name="coref.link.create">
137 <xsl:with-param name="ref" select="substring-before($refs, ' ')"/>
138 <xsl:with-param name="rnode" select="$rnode"/>
139 </xsl:call-template>
140 <xsl:text>, </xsl:text>
141 <xsl:call-template name="corefs.split">
142 <xsl:with-param name="refs" select="substring-after($refs, ' ')"/>
143 <xsl:with-param name="rnode" select="$rnode"/>
144 </xsl:call-template>
145 </xsl:when>
146 <xsl:otherwise>
147 <xsl:call-template name="coref.link.create">
148 <xsl:with-param name="ref" select="$refs"/>
149 <xsl:with-param name="rnode" select="$rnode"/>
150 </xsl:call-template>
151 </xsl:otherwise>
152 </xsl:choose>
153 </xsl:template>
154
155
156 <xsl:template match="co|area" mode="linkends.create">
157 <xsl:param name="rnode" select="/"/>
158 <xsl:if test="@linkends and $co.linkends.show='1'">
159 <xsl:text>[</xsl:text>
160 <xsl:call-template name="corefs.split">
161 <xsl:with-param name="refs" select="normalize-space(@linkends)"/>
162 <xsl:with-param name="rnode" select="$rnode"/>
163 </xsl:call-template>
164 <xsl:text>]</xsl:text>
165 </xsl:if>
166 </xsl:template>
167
168
169 <xsl:template match="co|area" mode="latex.programlisting">
170 <xsl:param name="rnode" select="/"/>
171 <xsl:param name="co-tagin" select="'&lt;'"/>
172 <xsl:param name="co-tagout" select="$co.tagout"/>
173 <xsl:param name="co-hide" select="0"/>
174 <xsl:variable name="conum">
175 <xsl:apply-templates select="." mode="conumber"/>
176 </xsl:variable>
177 <xsl:variable name="id" select="(@id|@xml:id)[1]"/>
178 <xsl:variable name="idx">
179 <xsl:call-template name="id-encode">
180 <xsl:with-param name="string" select="$id"/>
181 </xsl:call-template>
182 </xsl:variable>
183
184 <xsl:if test="$co-tagin != ''">
185 <xsl:value-of select="concat($co-tagin, 't>')"/>
186 </xsl:if>
187 <xsl:choose>
188 <xsl:when test="$co-hide != 0">
189 <xsl:if test="$id">
190 <xsl:text>\colabel{</xsl:text>
191 <xsl:value-of select="$idx"/>
192 <xsl:text>}</xsl:text>
193 </xsl:if>
194 </xsl:when>
195 <xsl:when test="$id">
196 <xsl:text>\coref{</xsl:text>
197 <xsl:value-of select="$conum"/>
198 <xsl:text>}{</xsl:text>
199 <xsl:value-of select="$idx"/>
200 <xsl:text>}</xsl:text>
201 </xsl:when>
202 <xsl:otherwise>
203 <xsl:text>\co{</xsl:text>
204 <xsl:value-of select="$conum"/>
205 <xsl:text>}</xsl:text>
206 </xsl:otherwise>
207 </xsl:choose>
208 <xsl:apply-templates select="." mode="linkends.create">
209 <xsl:with-param name="rnode" select="$rnode"/>
210 </xsl:apply-templates>
211 <xsl:value-of select="$co-tagout"/>
212 </xsl:template>
213
214
215 <!-- Print the markup of the co referenced by coref -->
216 <xsl:template match="coref" mode="latex.programlisting">
217 <xsl:param name="rnode" select="/"/>
218 <xsl:param name="co-tagin" select="'&lt;'"/>
219 <xsl:param name="co-tagout" select="$co.tagout"/>
220 <xsl:variable name="linkend" select="@linkend"/>
221 <xsl:variable name="co" select="$rnode//*[@id=$linkend or @xml:id=$linkend]"/>
222
223 <xsl:choose>
224 <xsl:when test="$co">
225 <xsl:variable name="conum">
226 <xsl:apply-templates select="$co" mode="conumber"/>
227 </xsl:variable>
228 <!-- Entry tex sequence -->
229 <xsl:value-of select="concat($co-tagin, 't>')"/>
230 <!-- The same number mark than the pointed <co> -->
231 <xsl:text>\conum{</xsl:text>
232 <xsl:value-of select="$conum"/>
233 <xsl:text>}</xsl:text>
234 <!-- Display also the <co> linkends -->
235 <xsl:apply-templates select="$co" mode="linkends.create">
236 <xsl:with-param name="rnode" select="$rnode"/>
237 </xsl:apply-templates>
238 <!-- Exit tex sequence -->
239 <xsl:value-of select="$co-tagout"/>
240 </xsl:when>
241 <xsl:otherwise>
242 <xsl:message>
243 <xsl:text>*** Invalid coref/@linkend='</xsl:text>
244 <xsl:value-of select="@linkend"/>
245 <xsl:text>'</xsl:text>
246 </xsl:message>
247 </xsl:otherwise>
248 </xsl:choose>
249 </xsl:template>
250
251
252 <!-- List of the callouts descriptions -->
253 <xsl:template match="calloutlist">
254 <xsl:param name="rnode" select="/"/>
255 <xsl:apply-templates select="title"/>
256 <xsl:text>&#10;\begin{description}&#10;</xsl:text>
257 <xsl:if test="$calloutlist.style != ''">
258 <xsl:text>[</xsl:text>
259 <xsl:value-of select="$calloutlist.style"/>
260 <xsl:text>]</xsl:text>
261 </xsl:if>
262 <xsl:text>&#10;</xsl:text>
263 <xsl:apply-templates select="callout" mode="item">
264 <xsl:with-param name="rnode" select="$rnode"/>
265 </xsl:apply-templates>
266 <xsl:text>\end{description}&#10;</xsl:text>
267 </xsl:template>
268
269 <!-- Callout Description -->
270 <xsl:template match="callout" mode="item">
271 <xsl:param name="rnode" select="/"/>
272 <xsl:text>\item[{</xsl:text>
273 <xsl:call-template name="corefs.split">
274 <xsl:with-param name="refs" select="normalize-space(@arearefs)"/>
275 <xsl:with-param name="rnode" select="$rnode"/>
276 </xsl:call-template>
277 <xsl:text>}]</xsl:text>
278 <xsl:if test="(@id|@xml:id) and $co.linkends.show='1'">
279 <xsl:text>\collabel{</xsl:text>
280 <xsl:call-template name="id-encode"/>
281 <xsl:text>}</xsl:text>
282 </xsl:if>
283 <xsl:apply-templates/>
284 </xsl:template>
285
286 <!-- Callout list title -->
287 <xsl:template match="calloutlist/title">
288 <xsl:text>&#10;{\bf </xsl:text>
289 <xsl:apply-templates/>
290 <xsl:text>}&#10;</xsl:text>
291 <xsl:call-template name="label.id">
292 <xsl:with-param name="object" select=".."/>
293 </xsl:call-template>
294 <!-- Ask to latex to let the title with its list -->
295 <xsl:text>\nopagebreak&#10;</xsl:text>
296 </xsl:template>
297
298
299 <!-- Callout numbering -->
300 <xsl:template match="co|callout" mode="conumber">
301 <xsl:number from="literallayout|programlisting|screen|synopsis|calloutlist"
302 level="any"
303 format="1"/>
304 </xsl:template>
305
306 <xsl:template match="area" mode="conumber">
307 <xsl:number from="areaspec"
308 level="any"
309 format="1"/>
310 </xsl:template>
311
312 </xsl:stylesheet>