Project

General

Profile

1
<?xml version='1.0'?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
                version='1.0'>
4

    
5
<!-- ********************************************************************
6
     $Id: html.xsl 8421 2009-05-04 07:49:49Z bobstayton $
7
     ********************************************************************
8

    
9
     This file is part of the XSL DocBook Stylesheet distribution.
10
     See ../README or http://docbook.sf.net/release/xsl/current/ for
11
     copyright and other information.
12

    
13
     ******************************************************************** -->
14

    
15
<!-- These variables set the align attribute value for HTML output based on
16
     the writing-mode specified in the gentext file for the document's lang. -->
17

    
18
<xsl:variable name="direction.align.start">
19
  <xsl:choose>
20
    <xsl:when test="starts-with($writing.mode, 'lr')">left</xsl:when>
21
    <xsl:when test="starts-with($writing.mode, 'rl')">right</xsl:when>
22
    <xsl:otherwise>left</xsl:otherwise>
23
  </xsl:choose>
24
</xsl:variable>
25

    
26
<xsl:variable name="direction.align.end">
27
  <xsl:choose>
28
    <xsl:when test="starts-with($writing.mode, 'lr')">right</xsl:when>
29
    <xsl:when test="starts-with($writing.mode, 'rl')">left</xsl:when>
30
    <xsl:otherwise>right</xsl:otherwise>
31
  </xsl:choose>
32
</xsl:variable>
33

    
34
<xsl:variable name="direction.mode">
35
  <xsl:choose>
36
    <xsl:when test="starts-with($writing.mode, 'lr')">ltr</xsl:when>
37
    <xsl:when test="starts-with($writing.mode, 'rl')">rtl</xsl:when>
38
    <xsl:otherwise>ltr</xsl:otherwise>
39
  </xsl:choose>
40
</xsl:variable>
41

    
42
<!-- The generate.html.title template is currently used for generating HTML -->
43
<!-- "title" attributes for some inline elements only, but not for any -->
44
<!-- block elements. It is called in eleven places in the inline.xsl -->
45
<!-- file. But it's called by all the inline.* templates (e.g., -->
46
<!-- inline.boldseq), which in turn are called by other (element) -->
47
<!-- templates, so it results, currently, in supporting generation of the -->
48
<!-- HTML "title" attribute for a total of about 92 elements. -->
49
<!-- You can use mode="html.title.attribute" to get a title for -->
50
<!-- an element specified by a param, including targets of cross references. -->
51
<xsl:template name="generate.html.title">
52
  <xsl:apply-templates select="." mode="html.title.attribute"/>
53
</xsl:template>
54

    
55
<!-- Generate a title attribute for the context node -->
56
<xsl:template match="*" mode="html.title.attribute">
57
  <xsl:variable name="is.title">
58
    <xsl:call-template name="gentext.template.exists">
59
      <xsl:with-param name="context" select="'title'"/>
60
      <xsl:with-param name="name" select="local-name(.)"/>
61
      <xsl:with-param name="lang">
62
        <xsl:call-template name="l10n.language"/>
63
      </xsl:with-param>
64
    </xsl:call-template>
65
  </xsl:variable>
66

    
67
  <xsl:variable name="is.title-numbered">
68
    <xsl:call-template name="gentext.template.exists">
69
      <xsl:with-param name="context" select="'title-numbered'"/>
70
      <xsl:with-param name="name" select="local-name(.)"/>
71
      <xsl:with-param name="lang">
72
        <xsl:call-template name="l10n.language"/>
73
      </xsl:with-param>
74
    </xsl:call-template>
75
  </xsl:variable>
76

    
77
  <xsl:variable name="is.title-unnumbered">
78
    <xsl:call-template name="gentext.template.exists">
79
      <xsl:with-param name="context" select="'title-unnumbered'"/>
80
      <xsl:with-param name="name" select="local-name(.)"/>
81
      <xsl:with-param name="lang">
82
        <xsl:call-template name="l10n.language"/>
83
      </xsl:with-param>
84
    </xsl:call-template>
85
  </xsl:variable>
86

    
87
  <xsl:variable name="has.title.markup">
88
    <xsl:apply-templates select="." mode="title.markup">
89
      <xsl:with-param name="verbose" select="0"/>
90
    </xsl:apply-templates>
91
  </xsl:variable>
92

    
93
  <xsl:variable name="gentext.title">
94
    <xsl:if test="$has.title.markup != '???TITLE???' and
95
                  ($is.title != 0 or
96
                  $is.title-numbered != 0 or
97
                  $is.title-unnumbered != 0)">
98
      <xsl:apply-templates select="."
99
                           mode="object.title.markup.textonly"/>
100
    </xsl:if>
101
  </xsl:variable>
102

    
103
  <xsl:choose>
104
    <xsl:when test="string-length($gentext.title) != 0">
105
      <xsl:attribute name="title">
106
        <xsl:value-of select="$gentext.title"/>
107
      </xsl:attribute>
108
    </xsl:when>
109
    <!-- Fall back to alt if available -->
110
    <xsl:when test="alt">
111
      <xsl:attribute name="title">
112
        <xsl:value-of select="normalize-space(alt)"/>
113
      </xsl:attribute>
114
    </xsl:when>
115
  </xsl:choose>
116
</xsl:template>
117

    
118
<xsl:template match="qandaentry" mode="html.title.attribute">
119
  <xsl:apply-templates select="question" mode="html.title.attribute"/>
120
</xsl:template>
121

    
122
<xsl:template match="question" mode="html.title.attribute">
123
  <xsl:variable name="label.text">
124
    <xsl:apply-templates select="." mode="qanda.label"/>
125
  </xsl:variable>
126

    
127
  <xsl:choose>
128
    <xsl:when test="string-length($label.text) != 0">
129
      <xsl:attribute name="title">
130
        <xsl:value-of select="$label.text"/>
131
      </xsl:attribute>
132
    </xsl:when>
133
    <!-- Fall back to alt if available -->
134
    <xsl:when test="alt">
135
      <xsl:attribute name="title">
136
        <xsl:value-of select="normalize-space(alt)"/>
137
      </xsl:attribute>
138
    </xsl:when>
139
  </xsl:choose>
140
</xsl:template>
141

    
142
<xsl:template name="dir">
143
  <xsl:param name="inherit" select="0"/>
144

    
145
  <xsl:variable name="dir">
146
    <xsl:choose>
147
      <xsl:when test="@dir">
148
        <xsl:value-of select="@dir"/>
149
      </xsl:when>
150
      <xsl:when test="$inherit != 0">
151
        <xsl:value-of select="ancestor::*/@dir[1]"/>
152
      </xsl:when>
153
    </xsl:choose>
154
  </xsl:variable>
155

    
156
  <xsl:if test="$dir != ''">
157
    <xsl:attribute name="dir">
158
      <xsl:value-of select="$dir"/>
159
    </xsl:attribute>
160
  </xsl:if>
161
</xsl:template>
162

    
163
<xsl:template name="anchor">
164
  <xsl:param name="node" select="."/>
165
  <xsl:param name="conditional" select="1"/>
166
  <xsl:variable name="id">
167
    <xsl:call-template name="object.id">
168
      <xsl:with-param name="object" select="$node"/>
169
    </xsl:call-template>
170
  </xsl:variable>
171
  <xsl:if test="$conditional = 0 or $node/@id or $node/@xml:id">
172
    <a name="{$id}"/>
173
  </xsl:if>
174
</xsl:template>
175

    
176
<xsl:template name="href.target.uri">
177
  <xsl:param name="context" select="."/>
178
  <xsl:param name="object" select="."/>
179
  <xsl:text>#</xsl:text>
180
  <xsl:call-template name="object.id">
181
    <xsl:with-param name="object" select="$object"/>
182
  </xsl:call-template>
183
</xsl:template>
184

    
185
<xsl:template name="href.target">
186
  <xsl:param name="context" select="."/>
187
  <xsl:param name="object" select="."/>
188
  <xsl:text>#</xsl:text>
189
  <xsl:call-template name="object.id">
190
    <xsl:with-param name="object" select="$object"/>
191
  </xsl:call-template>
192
</xsl:template>
193

    
194
<xsl:template name="href.target.with.base.dir">
195
  <xsl:param name="context" select="."/>
196
  <xsl:param name="object" select="."/>
197
  <xsl:if test="$manifest.in.base.dir = 0">
198
    <xsl:value-of select="$base.dir"/>
199
  </xsl:if>
200
  <xsl:call-template name="href.target">
201
    <xsl:with-param name="context" select="$context"/>
202
    <xsl:with-param name="object" select="$object"/>
203
  </xsl:call-template>
204
</xsl:template>
205

    
206
<xsl:template name="dingbat">
207
  <xsl:param name="dingbat">bullet</xsl:param>
208
  <xsl:call-template name="dingbat.characters">
209
    <xsl:with-param name="dingbat" select="$dingbat"/>
210
  </xsl:call-template>
211
</xsl:template>
212

    
213
<xsl:template name="dingbat.characters">
214
  <!-- now that I'm using the real serializer, all that dingbat malarky -->
215
  <!-- isn't necessary anymore... -->
216
  <xsl:param name="dingbat">bullet</xsl:param>
217
  <xsl:choose>
218
    <xsl:when test="$dingbat='bullet'">&#x2022;</xsl:when>
219
    <xsl:when test="$dingbat='copyright'">&#x00A9;</xsl:when>
220
    <xsl:when test="$dingbat='trademark'">&#x2122;</xsl:when>
221
    <xsl:when test="$dingbat='trade'">&#x2122;</xsl:when>
222
    <xsl:when test="$dingbat='registered'">&#x00AE;</xsl:when>
223
    <xsl:when test="$dingbat='service'">(SM)</xsl:when>
224
    <xsl:when test="$dingbat='nbsp'">&#x00A0;</xsl:when>
225
    <xsl:when test="$dingbat='ldquo'">&#x201C;</xsl:when>
226
    <xsl:when test="$dingbat='rdquo'">&#x201D;</xsl:when>
227
    <xsl:when test="$dingbat='lsquo'">&#x2018;</xsl:when>
228
    <xsl:when test="$dingbat='rsquo'">&#x2019;</xsl:when>
229
    <xsl:when test="$dingbat='em-dash'">&#x2014;</xsl:when>
230
    <xsl:when test="$dingbat='mdash'">&#x2014;</xsl:when>
231
    <xsl:when test="$dingbat='en-dash'">&#x2013;</xsl:when>
232
    <xsl:when test="$dingbat='ndash'">&#x2013;</xsl:when>
233
    <xsl:otherwise>
234
      <xsl:text>&#x2022;</xsl:text>
235
    </xsl:otherwise>
236
  </xsl:choose>
237
</xsl:template>
238

    
239
<xsl:template name="id.warning">
240
  <xsl:if test="$id.warnings != 0 and not(@id) and not(@xml:id) and parent::*">
241
    <xsl:variable name="title">
242
      <xsl:choose>
243
        <xsl:when test="title">
244
          <xsl:value-of select="title[1]"/>
245
        </xsl:when>
246
        <xsl:when test="substring(local-name(*[1]),
247
                                  string-length(local-name(*[1])-3) = 'info')
248
                        and *[1]/title">
249
          <xsl:value-of select="*[1]/title[1]"/>
250
        </xsl:when>
251
        <xsl:when test="refmeta/refentrytitle">
252
          <xsl:value-of select="refmeta/refentrytitle"/>
253
        </xsl:when>
254
        <xsl:when test="refnamediv/refname">
255
          <xsl:value-of select="refnamediv/refname[1]"/>
256
        </xsl:when>
257
      </xsl:choose>
258
    </xsl:variable>
259

    
260
    <xsl:message>
261
      <xsl:text>ID recommended on </xsl:text>
262
      <xsl:value-of select="local-name(.)"/>
263
      <xsl:if test="$title != ''">
264
        <xsl:text>: </xsl:text>
265
        <xsl:choose>
266
          <xsl:when test="string-length($title) &gt; 40">
267
            <xsl:value-of select="substring($title,1,40)"/>
268
            <xsl:text>...</xsl:text>
269
          </xsl:when>
270
          <xsl:otherwise>
271
            <xsl:value-of select="$title"/>
272
          </xsl:otherwise>
273
        </xsl:choose>
274
      </xsl:if>
275
    </xsl:message>
276
  </xsl:if>
277
</xsl:template>
278

    
279
<xsl:template name="generate.class.attribute">
280
  <xsl:param name="class" select="local-name(.)"/>
281
  <xsl:apply-templates select="." mode="class.attribute">
282
    <xsl:with-param name="class" select="$class"/>
283
  </xsl:apply-templates>
284
</xsl:template>
285

    
286
<xsl:template match="*" mode="class.attribute">
287
  <xsl:param name="class" select="local-name(.)"/>
288
  <!-- permit customization of class attributes -->
289
  <!-- Use element name by default -->
290
  <xsl:attribute name="class">
291
    <xsl:apply-templates select="." mode="class.value">
292
      <xsl:with-param name="class" select="$class"/>
293
    </xsl:apply-templates>
294
  </xsl:attribute>
295
</xsl:template>
296

    
297
<xsl:template match="*" mode="class.value">
298
  <xsl:param name="class" select="local-name(.)"/>
299
  <!-- permit customization of class value only -->
300
  <!-- Use element name by default -->
301
  <xsl:value-of select="$class"/>
302
</xsl:template>
303

    
304
<!-- Apply common attributes such as class, lang, dir -->
305
<xsl:template name="common.html.attributes">
306
  <xsl:param name="inherit" select="0"/>
307
  <xsl:param name="class" select="local-name(.)"/>
308
  <xsl:apply-templates select="." mode="common.html.attributes">
309
    <xsl:with-param name="class" select="$class"/>
310
    <xsl:with-param name="inherit" select="$inherit"/>
311
  </xsl:apply-templates>
312
</xsl:template>
313

    
314
<xsl:template match="*" mode="common.html.attributes">
315
  <xsl:param name="class" select="local-name(.)"/>
316
  <xsl:param name="inherit" select="0"/>
317
  <xsl:call-template name="generate.html.lang"/>
318
  <xsl:call-template name="dir">
319
    <xsl:with-param name="inherit" select="$inherit"/>
320
  </xsl:call-template>
321
  <xsl:apply-templates select="." mode="class.attribute">
322
    <xsl:with-param name="class" select="$class"/>
323
  </xsl:apply-templates>
324
  <xsl:call-template name="generate.html.title"/>
325
</xsl:template>
326

    
327
<!-- Apply common attributes not including class -->
328
<xsl:template name="locale.html.attributes">
329
  <xsl:apply-templates select="." mode="locale.html.attributes"/>
330
</xsl:template>
331

    
332
<xsl:template match="*" mode="locale.html.attributes">
333
  <xsl:call-template name="generate.html.lang"/>
334
  <xsl:call-template name="dir"/>
335
  <xsl:call-template name="generate.html.title"/>
336
</xsl:template>
337

    
338
<!-- Pass through any lang attributes -->
339
<xsl:template name="generate.html.lang">
340
  <xsl:apply-templates select="." mode="html.lang.attribute"/>
341
</xsl:template>
342

    
343
<xsl:template match="*" mode="html.lang.attribute">
344
  <!-- match the attribute name to the output type -->
345
  <xsl:choose>
346
    <xsl:when test="@lang and $stylesheet.result.type = 'html'">
347
      <xsl:attribute name="lang">
348
        <xsl:value-of select="@lang"/>
349
      </xsl:attribute>
350
    </xsl:when>
351
    <xsl:when test="@lang and $stylesheet.result.type = 'xhtml'">
352
      <xsl:attribute name="xml:lang">
353
        <xsl:value-of select="@lang"/>
354
      </xsl:attribute>
355
    </xsl:when>
356
    <xsl:when test="@xml:lang and $stylesheet.result.type = 'html'">
357
      <xsl:attribute name="lang">
358
        <xsl:value-of select="@xml:lang"/>
359
      </xsl:attribute>
360
    </xsl:when>
361
    <xsl:when test="@xml:lang and $stylesheet.result.type = 'xhtml'">
362
      <xsl:attribute name="xml:lang">
363
        <xsl:value-of select="@xml:lang"/>
364
      </xsl:attribute>
365
    </xsl:when>
366
  </xsl:choose>
367
</xsl:template>
368

    
369
</xsl:stylesheet>
370

    
(19-19/39)