Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / xhtml2 / figures.xsl @ 187

History | View | Annotate | Download (18.1 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" 
3
                xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
4
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
5
                xmlns:svg="http://www.w3.org/2000/svg"
6
                xmlns:html="http://www.w3.org/1999/xhtml"
7
                xmlns:teidocx="http://www.tei-c.org/ns/teidocx/1.0"
8
                xmlns:m="http://www.w3.org/1998/Math/MathML"
9
                xmlns:rng="http://relaxng.org/ns/structure/1.0"
10
                xmlns:tei="http://www.tei-c.org/ns/1.0"
11
                xmlns:teix="http://www.tei-c.org/ns/"                
12
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
13
                exclude-result-prefixes="svg a fo html rng tei teidocx teix m"
14
                version="2.0">
15
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
16
      <desc>
17
         <p> TEI stylesheet dealing with elements from the figures module,
18
      making HTML output. </p>
19
         <p>This software is dual-licensed:
20

    
21
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
22
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
23

    
24
2. http://www.opensource.org/licenses/BSD-2-Clause
25
		
26
All rights reserved.
27

    
28
Redistribution and use in source and binary forms, with or without
29
modification, are permitted provided that the following conditions are
30
met:
31

    
32
* Redistributions of source code must retain the above copyright
33
notice, this list of conditions and the following disclaimer.
34

    
35
* Redistributions in binary form must reproduce the above copyright
36
notice, this list of conditions and the following disclaimer in the
37
documentation and/or other materials provided with the distribution.
38

    
39
This software is provided by the copyright holders and contributors
40
"as is" and any express or implied warranties, including, but not
41
limited to, the implied warranties of merchantability and fitness for
42
a particular purpose are disclaimed. In no event shall the copyright
43
holder or contributors be liable for any direct, indirect, incidental,
44
special, exemplary, or consequential damages (including, but not
45
limited to, procurement of substitute goods or services; loss of use,
46
data, or profits; or business interruption) however caused and on any
47
theory of liability, whether in contract, strict liability, or tort
48
(including negligence or otherwise) arising in any way out of the use
49
of this software, even if advised of the possibility of such damage.
50
</p>
51
         <p>Author: See AUTHORS</p>
52
         <p>Id: $Id: figures.xsl 10057 2012-01-21 16:57:14Z rahtz $</p>
53
         <p>Copyright: 2011, TEI Consortium</p>
54
      </desc>
55
   </doc>
56
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
57
      <desc>Process elements m:*|@*|comment()|processing-instruction()|text()</desc>
58
   </doc>
59
  <xsl:template match="m:*|@*|comment()|processing-instruction()|text()" mode="math">
60
      <xsl:copy>
61
         <xsl:apply-templates mode="math" select="*|@*|processing-instruction()|text()"/>
62
      </xsl:copy>
63
  </xsl:template>
64
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
65
      <desc>Process elements m:math</desc>
66
   </doc>
67
  <xsl:template match="m:math">
68
      <m:math>
69
         <xsl:copy-of select="@*"/>
70
         <xsl:apply-templates mode="math"/>
71
      </m:math>
72
  </xsl:template>
73
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
74
      <desc>Process element cell</desc>
75
   </doc>
76
  <xsl:template match="tei:cell">
77
    <xsl:variable name="cellname">
78
      <xsl:choose>
79
	<xsl:when test="parent::tei:row[@rend='thead']">th</xsl:when>
80
	<xsl:otherwise>td</xsl:otherwise>
81
      </xsl:choose>
82
    </xsl:variable>
83
    <xsl:element name="{$cellname}">
84
      <xsl:for-each select="@*">
85
	<xsl:choose>
86
	  <xsl:when test="name(.) = 'width' or name(.) =
87
			  'border' or name(.) = 'cellspacing'
88
			  or name(.) = 'cellpadding'">
89
	    <xsl:copy-of select="."/>
90
	  </xsl:when>
91
	  <xsl:when test="name(.)='rend' and starts-with(.,'width:')">
92
	    <xsl:attribute name="width">
93
	      <xsl:value-of select="substring-after(.,'width:')"/>
94
	    </xsl:attribute>
95
	  </xsl:when>
96
	  <xsl:when test="name(.)='rend' and starts-with(.,'class:')">
97
	    <xsl:attribute name="class">
98
	      <xsl:value-of select="substring-after(.,'class:')"/>
99
	    </xsl:attribute>
100
	  </xsl:when>
101
	  <xsl:when test="name(.)='rend' and starts-with(.,'style=')">
102
	    <xsl:attribute name="style">
103
	      <xsl:value-of select="substring-after(.,'style=')"/>
104
	    </xsl:attribute>
105
	  </xsl:when>
106
	  <xsl:when test="name(.)='rend'">
107
	    <xsl:attribute name="class">
108
	      <xsl:value-of select="."/>
109
	    </xsl:attribute>
110
	  </xsl:when>
111
	  <xsl:when test="name(.)='cols'">
112
	    <xsl:attribute name="colspan">
113
	      <xsl:value-of select="."/>
114
	    </xsl:attribute>
115
	  </xsl:when>
116
	  <xsl:when test="name(.)='rows'">
117
	    <xsl:attribute name="rowspan">
118
	      <xsl:value-of select="."/>
119
	    </xsl:attribute>
120
	  </xsl:when>
121
	  <xsl:when test="name(.)='align'">
122
	    <xsl:attribute name="align">
123
	      <xsl:value-of select="."/>
124
	    </xsl:attribute>
125
	  </xsl:when>
126
	</xsl:choose>
127
      </xsl:for-each>
128
      <xsl:choose>
129
	<xsl:when test="@teidocx:align">
130
	  <xsl:attribute name="align">
131
	    <xsl:value-of select="@teidocx:align"/>
132
	  </xsl:attribute>
133
	</xsl:when>
134
	<xsl:when test="@align"/>
135
	<xsl:when test="not($cellAlign='left')">
136
	  <xsl:attribute name="align">
137
	    <xsl:value-of select="$cellAlign"/>
138
	  </xsl:attribute>
139
	</xsl:when>
140
      </xsl:choose>
141
      <xsl:if test="@role and not (@rend)">
142
	<xsl:attribute name="class">
143
	  <xsl:value-of select="@role"/>
144
	</xsl:attribute>
145
      </xsl:if>
146
      <xsl:if test="@xml:id">	   
147
	<xsl:call-template name="makeAnchor"/>
148
      </xsl:if>
149
      <xsl:apply-templates/>
150
    </xsl:element>
151
  </xsl:template>
152
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
153
      <desc>Process element figDesc</desc>
154
   </doc>
155
  <xsl:template match="tei:figDesc"/>
156
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
157
      <desc>Process element figure</desc>
158
   </doc>
159
  <xsl:template match="tei:figure">
160
    <xsl:variable name="container">
161
      <xsl:choose>
162
	<xsl:when test="$outputTarget='html5'">figure</xsl:when>
163
	<xsl:otherwise>div</xsl:otherwise>
164
      </xsl:choose>
165
    </xsl:variable>
166
    <xsl:choose>
167
      <xsl:when test="parent::tei:head or @rend='inline' or @place='inline'">
168
	<xsl:apply-templates/>
169
      </xsl:when>
170
      <xsl:when test="parent::tei:ref">
171
	<xsl:apply-templates/>
172
      </xsl:when>
173
      <xsl:otherwise>
174
	<xsl:element name="{$container}">
175
	  <xsl:choose>
176
	    <xsl:when test="@rend">
177
	      <xsl:attribute name="class">
178
		<xsl:text>figure </xsl:text>
179
		<xsl:value-of select="@rend"/>
180
	      </xsl:attribute>
181
	    </xsl:when>
182
	    <xsl:when test="@rendition">
183
	      <xsl:call-template name="applyRendition"/>
184
	    </xsl:when>
185
	    <xsl:otherwise>
186
	      <xsl:attribute name="class">
187
		<xsl:text>figure</xsl:text>
188
	      </xsl:attribute>
189
	    </xsl:otherwise>
190
	  </xsl:choose>
191
	  <xsl:if test="@xml:id">
192
	    <xsl:attribute name="id">
193
	      <xsl:value-of select="@xml:id"/>
194
	    </xsl:attribute>
195
	  </xsl:if>
196
	  <xsl:call-template name="figureHook"/>
197
	  <xsl:apply-templates/>
198
	</xsl:element>
199
      </xsl:otherwise>
200
    </xsl:choose>
201
  </xsl:template>
202
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
203
    <desc>Process element figure/tei:head</desc>
204
  </doc>
205
  <xsl:template match="tei:figure/tei:head">
206
    <xsl:variable name="captionlabel">
207
      <xsl:for-each select="..">
208
	<xsl:call-template name="calculateFigureNumber"/>
209
      </xsl:for-each>
210
    </xsl:variable>
211
    <xsl:choose>
212
      <xsl:when test="$outputTarget='html5'">
213
	<figcaption>
214
	  <xsl:if test="@rend">
215
	    <xsl:attribute name="class" select="@rend"/>
216
	  </xsl:if>
217
	  <xsl:call-template name="rendering"/>
218
	  <xsl:text>. </xsl:text>
219
	  <xsl:copy-of select="$captionlabel"/>
220
	  <xsl:apply-templates/>
221
	</figcaption>
222
      </xsl:when>
223
      <xsl:otherwise>
224
	<span class="caption {@rend}">
225
	  <xsl:copy-of select="$captionlabel"/>
226
	  <xsl:text>. </xsl:text>
227
	  <xsl:apply-templates/>
228
	</span>
229
      </xsl:otherwise>
230
    </xsl:choose>
231
  </xsl:template>
232

    
233
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
234
    <desc>Process element formula</desc>
235
  </doc>
236
  <xsl:template match="tei:formula" mode="xref">
237
    <xsl:number/>
238
  </xsl:template>
239
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
240
      <desc>Process element graphic</desc>
241
   </doc>
242
  <xsl:template match="tei:graphic">
243
      <xsl:call-template name="showGraphic"/>
244
  </xsl:template>
245
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
246
      <desc>Process element row</desc>
247
   </doc>
248
  <xsl:template match="tei:row">
249
      <tr>
250
         <xsl:call-template name="rendToClass">
251
	           <xsl:with-param name="default"/>
252
         </xsl:call-template>
253
         <xsl:if test="@role">
254
            <xsl:attribute name="class">
255
               <xsl:value-of select="@role"/>
256
            </xsl:attribute>
257
         </xsl:if>
258
         <xsl:apply-templates/>
259
      </tr>
260
  </xsl:template>
261
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
262
      <desc>Process element table</desc>
263
   </doc>
264
  <xsl:template match="tei:table">
265
      <div>
266
         <xsl:attribute name="class">
267
	   <xsl:text>table</xsl:text>
268
	   <xsl:if test="@align">
269
	     <xsl:text> </xsl:text>
270
	     <xsl:value-of select="@align"/>
271
	   </xsl:if>
272
	 </xsl:attribute>
273
	 <xsl:if test="@xml:id">	   
274
	   <xsl:call-template name="makeAnchor"/>
275
	 </xsl:if>
276
	 <table>
277
	   <xsl:call-template name="rendToClass">
278
	     <xsl:with-param name="id">false</xsl:with-param>
279
	   </xsl:call-template>
280
	   <xsl:if test="@rend='frame' or @rend='rules'">
281
	     <xsl:attribute name="rules">all</xsl:attribute>
282
	     <xsl:attribute name="border">1</xsl:attribute>
283
	   </xsl:if>
284
	   <xsl:for-each select="@*">
285
	     <xsl:if test="name(.)='summary' or name(.) = 'width' or name(.) = 'border' or name(.) = 'frame' or name(.) = 'rules' or name(.) = 'cellspacing' or name(.) = 'cellpadding'">
286
	       <xsl:copy-of select="."/>
287
	     </xsl:if>
288
	   </xsl:for-each>
289
	   <xsl:if test="tei:head">
290
	     <caption>
291
	       <xsl:apply-templates select="tei:head"/>
292
	     </caption>
293
	   </xsl:if>
294
	   <xsl:choose>
295
	     <xsl:when test="tei:row[@rend='thead']">
296
	       <thead>
297
		 <xsl:apply-templates
298
		     select="tei:row[@rend='thead']"/>
299
	       </thead>
300
	       <tbody>
301
		 <xsl:apply-templates select="tei:row[not(@rend='thead')]"/>
302
	       </tbody>
303
	     </xsl:when>
304
	     <xsl:otherwise>
305
	       <xsl:apply-templates select="tei:row"/>
306
	     </xsl:otherwise>
307
	   </xsl:choose>
308
	 </table>
309
	 <xsl:apply-templates select="tei:note"/>
310
      </div>
311
  </xsl:template>
312
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
313
      <desc>Process element table[@rend='simple']</desc>
314
   </doc>
315
  <xsl:template match="tei:table[@rend='simple']">
316
      <table>
317
         <xsl:choose>
318
	           <xsl:when test="@rend">
319
	              <xsl:attribute name="class">
320
	                 <xsl:value-of select="@rend"/>
321
               </xsl:attribute>
322
	           </xsl:when>
323
	           <xsl:when test="@rendition">
324
	              <xsl:call-template name="applyRendition"/>
325
	           </xsl:when>
326
         </xsl:choose>
327
         <xsl:for-each select="@*">
328
            <xsl:if test="name(.)='summary'    or name(.) = 'width'    or name(.) = 'border'    or name(.) = 'frame'    or name(.) = 'rules'    or name(.) = 'cellspacing'    or name(.) = 'cellpadding'">
329
               <xsl:copy-of select="."/>
330
            </xsl:if>
331
         </xsl:for-each>
332
	 <xsl:if test="@xml:id">
333
	   <xsl:call-template name="makeAnchor"/>
334
	 </xsl:if>
335
         <xsl:apply-templates/>
336
      </table>
337
  </xsl:template>
338
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
339
      <desc>[html] <param name="name">name</param>
340
         <param name="value">value</param>
341
      </desc>
342
   </doc>
343
  <xsl:template name="setDimension">
344
      <xsl:param name="name"/>
345
      <xsl:param name="value"/>
346

    
347
      <xsl:variable name="calcvalue">
348
         <xsl:choose>
349
            <xsl:when test="contains($value,'in')">
350
               <xsl:value-of select="round($dpi * number(substring-before($value,'in')))"/>
351
            </xsl:when>
352
            <xsl:when test="contains($value,'pt')">
353
               <xsl:value-of select="round($dpi * (number(substring-before($value,'pt')) div 72))"/>
354
            </xsl:when>
355
            <xsl:when test="contains($value,'cm')">
356
               <xsl:value-of select="round($dpi * (number(substring-before($value,'cm')) div 2.54 ))"/>
357
            </xsl:when>
358
            <xsl:when test="contains($value,'px')">
359
               <xsl:value-of select="substring-before($value,'px')"/>
360
            </xsl:when>
361
            <xsl:otherwise>
362
               <xsl:value-of select="$value"/>
363
            </xsl:otherwise>
364
         </xsl:choose>
365
      </xsl:variable>
366
      <xsl:attribute name="{$name}">
367
         <xsl:value-of select="$calcvalue"/>
368
      </xsl:attribute>
369
  </xsl:template>
370
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
371
      <desc>[html] </desc>
372
   </doc>
373
  <xsl:template name="showGraphic">
374
      <xsl:variable name="File">
375
         <xsl:choose>
376
            <xsl:when test="@url">
377
               <xsl:value-of select="@url"/>
378
               <xsl:if test="not(contains(@url,'.'))">
379
                  <xsl:value-of select="$graphicsSuffix"/>
380
               </xsl:if>
381
            </xsl:when>
382
            <xsl:otherwise>
383
               <xsl:message terminate="yes">Cannot work out how to do a graphic
384
          </xsl:message>
385
            </xsl:otherwise>
386
         </xsl:choose>
387
      </xsl:variable>
388
      <xsl:variable name="Alt">
389
         <xsl:choose>
390
            <xsl:when test="tei:desc">
391
               <xsl:for-each select="tei:desc">
392
		 <xsl:apply-templates mode="plain"/>
393
	       </xsl:for-each>
394
            </xsl:when>
395
            <xsl:when test="tei:figDesc">
396
               <xsl:for-each select="tei:figDesc">
397
	                 <xsl:apply-templates mode="plain"/>
398
	              </xsl:for-each>
399
            </xsl:when>
400
            <xsl:when test="tei:head">
401
               <xsl:value-of select="tei:head/text()"/>
402
            </xsl:when>
403
            <xsl:when test="parent::tei:figure/tei:figDesc">
404
               <xsl:for-each select="parent::tei:figure/tei:figDesc">
405
	                 <xsl:apply-templates mode="plain"/>
406
	              </xsl:for-each>
407
            </xsl:when>
408
            <xsl:when test="parent::tei:figure/tei:head">
409
               <xsl:value-of select="parent::tei:figure/tei:head/text()"/>
410
            </xsl:when>
411
         </xsl:choose>
412
      </xsl:variable>
413
      <xsl:choose>
414
	<xsl:when test="$showFigures='true'">
415
	  <xsl:choose>
416
	    <xsl:when test="@type='thumbnail'"/>
417
	    <xsl:when test="starts-with(@mimeType, 'video')">
418
	      <video src="{$graphicsPrefix}{$File}"
419
		     controls="controls">
420
		<xsl:if test="../tei:graphic[@type='thumbnail']">
421
		  <xsl:attribute name="poster">
422
		    <xsl:value-of select="../tei:graphic[@type='thumbnail']/@url"/>
423
		  </xsl:attribute>
424
		</xsl:if>
425
	      </video>
426
	    </xsl:when>
427
	    <xsl:otherwise>
428
	      <img src="{$graphicsPrefix}{$File}">
429
		<xsl:attribute name="alt">
430
		  <xsl:value-of select="$Alt"/>
431
		</xsl:attribute>
432
		<xsl:call-template name="imgHook"/>
433
		<xsl:if test="@xml:id">
434
		  <xsl:attribute name="id">
435
		    <xsl:value-of select="@xml:id"/>
436
		  </xsl:attribute>
437
		</xsl:if>
438
		<xsl:call-template name="rendToClass"/>
439
		<xsl:if test="@width">
440
		  <xsl:call-template name="setDimension">
441
		    <xsl:with-param name="value">
442
		      <xsl:value-of select="@width"/>
443
		    </xsl:with-param>
444
		    <xsl:with-param name="name">width</xsl:with-param>
445
		  </xsl:call-template>
446
		</xsl:if>
447
		<xsl:if test="@height">
448
		  <xsl:call-template name="setDimension">
449
		    <xsl:with-param name="value">
450
		      <xsl:value-of select="@height"/>
451
		    </xsl:with-param>
452
		    <xsl:with-param name="name">height</xsl:with-param>
453
		  </xsl:call-template>
454
		</xsl:if>
455
	      </img>
456
	    </xsl:otherwise>
457
	  </xsl:choose>	  
458
         </xsl:when>
459
         <xsl:otherwise>
460
            <div class="altfigure">
461
	      <xsl:call-template name="i18n">
462
		<xsl:with-param name="word">figureWord</xsl:with-param>
463
	      </xsl:call-template>
464
	      <xsl:text> </xsl:text>
465
	      <xsl:for-each select="self::tei:figure|parent::tei:figure">
466
		<xsl:number count="tei:figure[tei:head]" level="any"/>
467
	      </xsl:for-each>
468
	      <xsl:text> </xsl:text>
469
	      <xsl:value-of select="$File"/>
470
	      <xsl:text> [</xsl:text>
471
	      <xsl:value-of select="$Alt"/>
472
	      <xsl:text>] </xsl:text>
473
	    </div>
474
         </xsl:otherwise>
475
      </xsl:choose>
476
  </xsl:template>
477
  <xsl:template match="tei:binaryObject">
478
      <img>
479
         <xsl:attribute name="src">
480
            <xsl:text>data:</xsl:text>
481
            <xsl:value-of select="@mimetype"/>
482
            <xsl:text>;base64,</xsl:text>
483
            <xsl:copy-of select="text()"/>
484
         </xsl:attribute>
485
         <xsl:if test="@width">
486
            <xsl:call-template name="setDimension">
487
               <xsl:with-param name="value">
488
                  <xsl:value-of select="@width"/>
489
               </xsl:with-param>
490
               <xsl:with-param name="name">width</xsl:with-param>
491
            </xsl:call-template>
492
         </xsl:if>
493
         <xsl:if test="@height">
494
            <xsl:call-template name="setDimension">
495
               <xsl:with-param name="value">
496
                  <xsl:value-of select="@height"/>
497
               </xsl:with-param>
498
               <xsl:with-param name="name">height</xsl:with-param>
499
            </xsl:call-template>
500
         </xsl:if>
501
      </img>
502
      <!-- also alt -->
503
    <!-- this is what we'll need for IE:
504
<style type="text/css">
505
   img {behavior: expression(fixBase64(this));}
506
  </style>
507
  <script type="text/javascript">
508
  	// a regular expression to test for Base64 data
509
	var BASE64_DATA = /^data:.*;base64/i;
510
	// path to the PHP module that will decode the encoded data
511
	var base64Path = "/my/base64.php";
512
	function fixBase64(img) {
513
		// stop the CSS expression from being endlessly evaluated
514
		img.runtimeStyle.behavior = "none";
515
		// check the image src
516
		if (BASE64_DATA.test(img.src)) {
517
		// pass the data to the PHP routine
518
		img.src = base64Path + "?" + img.src.slice(5);
519
		}
520
	};
521
  </script>
522
  Dean Edwards http://dean.edwards.name/weblog/2005/06/base64-sexy/
523
<?php
524
$data = split(";", $_SERVER["REDIRECT_QUERY_STRING"]);
525
$type = $data[0];
526
$data = split(",", $data[1]);
527
header("Content-type: ".$type);
528
echo base64_decode($data[1]);
529
?>
530
-->
531
  </xsl:template>
532

    
533
  <xsl:template match="svg:*">
534
      <xsl:copy-of select="."/>
535
  </xsl:template>
536

    
537
</xsl:stylesheet>