Debian Codegraph @

xslt/mallard/html/mal2html-inline.xsl

raw
1 <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
2 <!--
3 This program is free software; you can redistribute it and/or modify it under
4 the terms of the GNU Lesser General Public License as published by the Free
5 Software Foundation; either version 2 of the License, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 details.
12
13 You should have received a copy of the GNU Lesser General Public License
14 along with this program; see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/>.
15 -->
16
17 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
18 xmlns:mal="http://projectmallard.org/1.0/"
19 xmlns:e="http://projectmallard.org/experimental/"
20 xmlns="http://www.w3.org/1999/xhtml"
21 exclude-result-prefixes="mal e"
22 version="1.0">
23
24 <!--!!==========================================================================
25 Mallard to HTML - Inlines
26 Handle simple Mallard inline elements.
27 @revision[version=3.8 date=2012-11-13 status=final]
28
29 This stylesheet contains templates to handle most Mallard inline elements.
30 It also maps {mal.link.content.mode} to {mal2html.inline.mode}.
31 -->
32
33 <xsl:template mode="mal.link.content.mode" match="*">
34 <xsl:apply-templates mode="mal2html.inline.mode" select="."/>
35 </xsl:template>
36
37
38 <!--%%==========================================================================
39 mal2html.inline.mode
40 Process Mallard elements in inline mode.
41 @revision[version=3.8 date=2012-11-13 status=final]
42
43 This mode is applied to elements in inline context. It is be called by certain
44 block elements and inline elements to process child content. Certain elements
45 may appear in both block and inline mode, and the processing expectations for
46 those elements is different depending on context.
47
48 Implementations of this mode should handle ubiquitous linking, text directionality,
49 and other common inline features. Note that the {mal2html.span} template handles
50 these things automatically, and is suitable for most inline elements. You can use
51 the {mal2html.inline.content.mode} to output special content for the child
52 elements.
53 -->
54 <xsl:template mode="mal2html.inline.mode" match="*">
55 <xsl:message>
56 <xsl:text>Unmatched inline element: </xsl:text>
57 <xsl:value-of select="local-name(.)"/>
58 </xsl:message>
59 <xsl:apply-templates mode="mal2html.inline.mode"/>
60 </xsl:template>
61
62
63 <!--%%==========================================================================
64 mal2html.inline.content.mode
65 Output the contents of an inline element.
66 @revision[version=1.0 date=2010-06-03 status=final]
67
68 This template outputs the contents of the inline element it matches. It is
69 usually called by {mal2html.span} to allow elements like `guiseq`, `keyseq`,
70 and `link` output special inner contents while still using the generic wrapper
71 template.
72 -->
73 <xsl:template mode="mal2html.inline.content.mode" match="node()">
74 <xsl:apply-templates mode="mal2html.inline.mode"/>
75 </xsl:template>
76
77
78 <!--**==========================================================================
79 mal2html.span
80 Output an HTML `span` element.
81 @revision[version=3.10 date=2013-07-10 status=final]
82
83 [xsl:params]
84 $node: The source element to output a `span` for.
85 $class: An additional string to prepend to the `class` attribute.
86
87 This template outputs an HTML `span` element for a source element. It creates
88 a `class` attribute automatically by passing the local name of $node and the
89 $class parameter to {html.class.attr}. To output the contents of $node, it
90 applies the mode {mal2html.inline.content.mode} to $node.
91
92 This template automatically handles ubiquitous linking if $node contains
93 an `xref` or `href` attribute.
94 -->
95 <xsl:template name="mal2html.span">
96 <xsl:param name="node" select="."/>
97 <xsl:param name="class" select="''"/>
98 <span>
99 <xsl:call-template name="html.class.attr">
100 <xsl:with-param name="node" select="$node"/>
101 <xsl:with-param name="class" select="concat($class, ' ', local-name($node))"/>
102 </xsl:call-template>
103 <xsl:call-template name="html.lang.attrs">
104 <xsl:with-param name="node" select="$node"/>
105 </xsl:call-template>
106 <xsl:variable name="href">
107 <xsl:if test="$node/@action | $node/@xref | $node/@href">
108 <xsl:call-template name="mal.link.target">
109 <xsl:with-param name="node" select="$node"/>
110 </xsl:call-template>
111 </xsl:if>
112 </xsl:variable>
113 <xsl:choose>
114 <xsl:when test="normalize-space($href) != ''">
115 <a>
116 <xsl:attribute name="href">
117 <xsl:value-of select="$href"/>
118 </xsl:attribute>
119 <xsl:attribute name="title">
120 <xsl:call-template name="mal.link.tooltip">
121 <xsl:with-param name="node" select="$node"/>
122 <xsl:with-param name="role" select="$node/@role"/>
123 </xsl:call-template>
124 </xsl:attribute>
125 <xsl:apply-templates mode="mal2html.inline.content.mode" select="$node"/>
126 </a>
127 </xsl:when>
128 <xsl:otherwise>
129 <xsl:apply-templates mode="mal2html.inline.content.mode" select="$node"/>
130 </xsl:otherwise>
131 </xsl:choose>
132 </span>
133 </xsl:template>
134
135
136 <!-- == Matched Templates == -->
137
138 <!-- = app = -->
139 <xsl:template mode="mal2html.inline.mode" match="mal:app">
140 <xsl:call-template name="mal2html.span"/>
141 </xsl:template>
142
143 <!-- = cmd = -->
144 <xsl:template mode="mal2html.inline.mode" match="mal:cmd">
145 <xsl:call-template name="mal2html.span"/>
146 </xsl:template>
147
148 <!-- = code = -->
149 <xsl:template mode="mal2html.inline.mode" match="mal:code">
150 <xsl:call-template name="mal2html.span"/>
151 </xsl:template>
152
153 <!-- = date = -->
154 <xsl:template mode="mal2html.inline.mode" match="mal:date">
155 <xsl:call-template name="mal2html.span"/>
156 </xsl:template>
157
158 <!-- = em = -->
159 <xsl:template mode="mal2html.inline.mode" match="mal:em">
160 <xsl:call-template name="mal2html.span">
161 <xsl:with-param name="class">
162 <xsl:if test="contains(concat(' ', @style, ' '), ' strong ')">
163 <xsl:text>em-bold</xsl:text>
164 </xsl:if>
165 </xsl:with-param>
166 </xsl:call-template>
167 </xsl:template>
168
169 <!-- = file = -->
170 <xsl:template mode="mal2html.inline.mode" match="mal:file">
171 <xsl:call-template name="mal2html.span"/>
172 </xsl:template>
173
174 <!-- = gui = -->
175 <xsl:template mode="mal2html.inline.mode" match="mal:gui">
176 <xsl:call-template name="mal2html.span"/>
177 </xsl:template>
178
179 <!-- = guiseq = -->
180 <xsl:template mode="mal2html.inline.mode" match="mal:guiseq">
181 <xsl:call-template name="mal2html.span"/>
182 </xsl:template>
183
184 <!-- = guiseq % mal2html.inline.content.mode = -->
185 <xsl:template mode="mal2html.inline.content.mode" match="mal:guiseq">
186 <xsl:variable name="arrow">
187 <xsl:variable name="dir">
188 <xsl:call-template name="l10n.direction"/>
189 </xsl:variable>
190 <xsl:choose>
191 <xsl:when test="$dir = 'rtl'">
192 <xsl:text>&#x00A0;&#x25C2; </xsl:text>
193 </xsl:when>
194 <xsl:otherwise>
195 <xsl:text>&#x00A0;&#x25B8; </xsl:text>
196 </xsl:otherwise>
197 </xsl:choose>
198 </xsl:variable>
199 <xsl:for-each select="mal:gui | text()[normalize-space(.) != '']">
200 <xsl:if test="position() != 1">
201 <xsl:value-of select="$arrow"/>
202 </xsl:if>
203 <xsl:apply-templates mode="mal2html.inline.mode" select="."/>
204 </xsl:for-each>
205 </xsl:template>
206
207 <!-- = input = -->
208 <xsl:template mode="mal2html.inline.mode" match="mal:input">
209 <xsl:call-template name="mal2html.span"/>
210 </xsl:template>
211
212 <!-- = hi = -->
213 <xsl:template mode="mal2html.inline.mode" match="e:hi">
214 <xsl:choose>
215 <xsl:when test="parent::mal:hi">
216 <xsl:apply-templates mode="mal2html.inline.mode"/>
217 </xsl:when>
218 <xsl:otherwise>
219 <xsl:call-template name="mal2html.span"/>
220 </xsl:otherwise>
221 </xsl:choose>
222 </xsl:template>
223
224 <xsl:template mode="mal2html.inline.mode" match="mal:hi">
225 <xsl:variable name="style" select="concat(' ', @style, ' ')"/>
226 <xsl:call-template name="mal2html.span">
227 <xsl:with-param name="class">
228 <xsl:choose>
229 <xsl:when test="contains($style, ' ins ')">
230 <xsl:text>hi-ins</xsl:text>
231 </xsl:when>
232 <xsl:when test="contains($style, ' del ')">
233 <xsl:text>hi-del</xsl:text>
234 </xsl:when>
235 <xsl:when test="contains($style, ' red ')">
236 <xsl:text>hi-red</xsl:text>
237 </xsl:when>
238 <xsl:when test="contains($style, ' orange ')">
239 <xsl:text>hi-orange</xsl:text>
240 </xsl:when>
241 <xsl:when test="contains($style, ' yellow ')">
242 <xsl:text>hi-yellow</xsl:text>
243 </xsl:when>
244 <xsl:when test="contains($style, ' green ')">
245 <xsl:text>hi-green</xsl:text>
246 </xsl:when>
247 <xsl:when test="contains($style, ' blue ')">
248 <xsl:text>hi-blue</xsl:text>
249 </xsl:when>
250 <xsl:when test="contains($style, ' purple ')">
251 <xsl:text>hi-purple</xsl:text>
252 </xsl:when>
253 <xsl:when test="contains($style, ' gray ')">
254 <xsl:text>hi-gray</xsl:text>
255 </xsl:when>
256 </xsl:choose>
257 </xsl:with-param>
258 </xsl:call-template>
259 </xsl:template>
260
261 <xsl:template mode="mal2html.inline.content.mode" match="mal:hi">
262 <xsl:variable name="style" select="concat(' ', @style, ' ')"/>
263 <xsl:choose>
264 <xsl:when test="contains($style, ' ins ')">
265 <ins>
266 <xsl:apply-templates mode="mal2html.inline.mode"/>
267 </ins>
268 </xsl:when>
269 <xsl:when test="contains($style, ' del ')">
270 <del>
271 <xsl:apply-templates mode="mal2html.inline.mode"/>
272 </del>
273 </xsl:when>
274 <xsl:otherwise>
275 <xsl:apply-templates mode="mal2html.inline.mode"/>
276 </xsl:otherwise>
277 </xsl:choose>
278 </xsl:template>
279
280 <!-- = key = -->
281 <xsl:template mode="mal2html.inline.mode" match="mal:key">
282 <xsl:call-template name="mal2html.span"/>
283 </xsl:template>
284
285 <!-- = key % mal2html.inline.content.mode = -->
286 <xsl:template mode="mal2html.inline.content.mode" match="mal:key">
287 <kbd>
288 <xsl:if test=". = 'Fn'">
289 <xsl:attribute name="class">
290 <xsl:text>key-Fn</xsl:text>
291 </xsl:attribute>
292 </xsl:if>
293 <xsl:apply-templates mode="mal2html.inline.mode"/>
294 </kbd>
295 </xsl:template>
296
297 <!-- = keyseq = -->
298 <xsl:template mode="mal2html.inline.mode" match="mal:keyseq">
299 <xsl:call-template name="mal2html.span"/>
300 </xsl:template>
301
302 <!-- = keyseq % mal2html.inline.content.mode = -->
303 <xsl:template mode="mal2html.inline.content.mode" match="mal:keyseq">
304 <xsl:variable name="joinchar">
305 <xsl:choose>
306 <xsl:when test="@type = 'sequence'">
307 <xsl:text> </xsl:text>
308 </xsl:when>
309 <xsl:when test="contains(concat(' ', @style, ' '), ' hyphen ')">
310 <xsl:text>-</xsl:text>
311 </xsl:when>
312 <xsl:otherwise>
313 <xsl:text>+</xsl:text>
314 </xsl:otherwise>
315 </xsl:choose>
316 </xsl:variable>
317 <xsl:for-each select="* | text()[normalize-space(.) != '']">
318 <xsl:if test="position() != 1">
319 <xsl:value-of select="$joinchar"/>
320 </xsl:if>
321 <xsl:choose>
322 <xsl:when test="./self::text()">
323 <xsl:value-of select="normalize-space(.)"/>
324 </xsl:when>
325 <xsl:otherwise>
326 <xsl:apply-templates mode="mal2html.inline.mode" select="."/>
327 </xsl:otherwise>
328 </xsl:choose>
329 </xsl:for-each>
330 </xsl:template>
331
332 <!-- = link = -->
333 <xsl:template mode="mal2html.inline.mode" match="mal:link">
334 <xsl:call-template name="mal2html.span">
335 <xsl:with-param name="class">
336 <xsl:if test="contains(concat(' ', @style, ' '), ' button ')">
337 <xsl:text>link-button</xsl:text>
338 </xsl:if>
339 </xsl:with-param>
340 </xsl:call-template>
341 </xsl:template>
342
343 <!-- = link % mal2html.inline.content.mode = -->
344 <xsl:template mode="mal2html.inline.content.mode" match="mal:link">
345 <xsl:choose>
346 <xsl:when test="* or normalize-space(.) != ''">
347 <xsl:apply-templates mode="mal2html.inline.mode"/>
348 </xsl:when>
349 <xsl:otherwise>
350 <xsl:call-template name="mal.link.content">
351 <xsl:with-param name="role" select="@role"/>
352 </xsl:call-template>
353 </xsl:otherwise>
354 </xsl:choose>
355 </xsl:template>
356
357 <!-- = output = -->
358 <xsl:template mode="mal2html.inline.mode" match="mal:output">
359 <xsl:variable name="style" select="concat(' ', @style, ' ')"/>
360 <xsl:call-template name="mal2html.span">
361 <xsl:with-param name="class">
362 <xsl:choose>
363 <xsl:when test="contains($style, ' error ')">
364 <xsl:text>error</xsl:text>
365 </xsl:when>
366 <xsl:when test="contains($style, ' prompt ')">
367 <xsl:text>prompt</xsl:text>
368 </xsl:when>
369 </xsl:choose>
370 </xsl:with-param>
371 </xsl:call-template>
372 </xsl:template>
373
374 <!-- = span = -->
375 <xsl:template mode="mal2html.inline.mode" match="mal:span">
376 <xsl:call-template name="mal2html.span"/>
377 </xsl:template>
378
379 <!-- = sys = -->
380 <xsl:template mode="mal2html.inline.mode" match="mal:sys">
381 <xsl:call-template name="mal2html.span"/>
382 </xsl:template>
383
384 <!-- = var = -->
385 <xsl:template mode="mal2html.inline.mode" match="mal:var">
386 <xsl:call-template name="mal2html.span"/>
387 </xsl:template>
388
389 <!-- = text() = -->
390 <xsl:template mode="mal2html.inline.mode" match="text()">
391 <xsl:value-of select="."/>
392 </xsl:template>
393
394 </xsl:stylesheet>