Statistics
| Revision:

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

History | View | Annotate | Download (17.5 kB)

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

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

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

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

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

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

    
40
This software is provided by the copyright holders and contributors
41
"as is" and any express or implied warranties, including, but not
42
limited to, the implied warranties of merchantability and fitness for
43
a particular purpose are disclaimed. In no event shall the copyright
44
holder or contributors be liable for any direct, indirect, incidental,
45
special, exemplary, or consequential damages (including, but not
46
limited to, procurement of substitute goods or services; loss of use,
47
data, or profits; or business interruption) however caused and on any
48
theory of liability, whether in contract, strict liability, or tort
49
(including negligence or otherwise) arising in any way out of the use
50
of this software, even if advised of the possibility of such damage.
51
</p>
52
         <p>Author: See AUTHORS</p>
53
         <p>Id: $Id: figures.xsl 10042 2012-01-13 15:23:16Z rahtz $</p>
54
         <p>Copyright: 2011, TEI Consortium</p>
55
      </desc>
56
   </doc>
57
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
58
      <desc>Deal with elements in math mode (just copy them)</desc>
59
   </doc>
60
  <xsl:template match="m:*|@*|comment()|processing-instruction()|text()" mode="math">
61
      <xsl:copy>
62
         <xsl:apply-templates mode="math" select="*|@*|processing-instruction()|text()"/>
63
      </xsl:copy>
64
  </xsl:template>
65
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
66
      <desc>Process math elements</desc>
67
   </doc>
68
  <xsl:template match="m:math">
69
      <m:math>
70
         <xsl:copy-of select="@*"/>
71
         <xsl:apply-templates mode="math"/>
72
      </m:math>
73
  </xsl:template>
74
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
75
      <desc/>
76
   </doc>
77
  <xsl:template match="tei:cell">
78
      <table-cell>
79
         <xsl:if test="@cols &gt; 1">
80
            <xsl:attribute name="number-columns-spanned">
81
               <xsl:value-of select="@cols"/>
82
            </xsl:attribute>
83
         </xsl:if>
84
         <xsl:if test="@rows &gt; 1">
85
            <xsl:attribute name="number-rows-spanned">
86
               <xsl:value-of select="@rows"/>
87
            </xsl:attribute>
88
         </xsl:if>
89
         <xsl:call-template name="cellProperties"/>
90
         <block>
91
            <xsl:choose>
92
               <xsl:when test="@role='label' or parent::tei:row[@role='label' or parent::tei:row[@role='header']]">
93
                  <xsl:attribute name="font-weight">bold</xsl:attribute>
94
               </xsl:when>
95
            </xsl:choose>
96
            <xsl:apply-templates/>
97
         </block>
98
      </table-cell>
99
  </xsl:template>
100
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
101
      <desc/>
102
   </doc>
103
  <xsl:template match="tei:figDesc"/>
104
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
105
      <desc/>
106
   </doc>
107
  <xsl:template match="tei:figure">
108
      <xsl:choose>
109
         <xsl:when test="@rend='display' or tei:head or tei:p">
110
            <float>
111
               <xsl:call-template name="addID"/>
112
               <block text-align="center">
113
                  <xsl:choose>
114
                     <xsl:when test="@url or @entity">
115
                        <xsl:call-template name="makePic"/>
116
                     </xsl:when>
117
                     <xsl:otherwise>
118
                        <xsl:apply-templates/>
119
                     </xsl:otherwise>
120
                  </xsl:choose>
121
               </block>
122
               <block>
123
                  <xsl:call-template name="figureCaptionstyle"/>
124
                  <xsl:call-template name="calculateFigureNumber"/>
125
                  <xsl:text>. </xsl:text>
126
                  <xsl:apply-templates select="tei:head"/>
127
               </block>
128
            </float>
129
         </xsl:when>
130
         <xsl:otherwise>
131
	           <block>
132
	              <xsl:choose>
133
	                 <xsl:when test="@url or @entity">
134
	                    <xsl:call-template name="makePic"/>
135
	                 </xsl:when>
136
	                 <xsl:otherwise>
137
	                    <xsl:apply-templates/>
138
	                 </xsl:otherwise>
139
	              </xsl:choose>
140
	           </block>
141
            <xsl:choose>
142
               <xsl:when test="$captionInlineFigures='true'">
143
                  <block>
144
                     <xsl:call-template name="figureCaptionstyle"/>
145
                     <xsl:call-template name="calculateFigureNumber"/>
146
                     <xsl:text>. </xsl:text>
147
                     <xsl:apply-templates select="tei:head"/>
148
                  </block>
149
               </xsl:when>
150
               <xsl:otherwise>
151
                  <xsl:if test="tei:head">
152
                     <block text-align="center">
153
                        <xsl:apply-templates select="tei:head"/>
154
                     </block>
155
                  </xsl:if>
156
               </xsl:otherwise>
157
            </xsl:choose>
158
         </xsl:otherwise>
159
      </xsl:choose>
160
  </xsl:template>
161
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
162
      <desc/>
163
   </doc>
164
  <xsl:template match="tei:figure" mode="xref">
165
      <xsl:if test="$showFloatLabel">
166
         <xsl:call-template name="i18n">
167
            <xsl:with-param name="word">figureWord</xsl:with-param>
168
         </xsl:call-template>
169
         <xsl:text> </xsl:text>
170
      </xsl:if>
171
      <xsl:call-template name="calculateFigureNumber"/>
172
      <xsl:if test="$showFloatHead='true' and tei:head">
173
         <xsl:text> (</xsl:text>
174
         <xsl:apply-templates select="tei:head"/>
175
         <xsl:text>)</xsl:text>
176
      </xsl:if>
177
      <xsl:if test="$xrefShowPage='true'">
178
    on page
179
    <page-number-citation>
180
            <xsl:attribute name="ref-id">
181
               <xsl:choose>
182
                  <xsl:when test="@xml:id">
183
                     <xsl:value-of select="@xml:id"/>
184
                  </xsl:when>
185
                  <xsl:otherwise>
186
                     <xsl:value-of select="generate-id()"/>
187
                  </xsl:otherwise>
188
               </xsl:choose>
189
            </xsl:attribute>
190
         </page-number-citation> 
191
      </xsl:if>
192
  </xsl:template>
193
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
194
      <desc/>
195
   </doc>
196
  <xsl:template match="tei:formula">
197
      <wrapper>
198
         <xsl:if test="@xml:id">
199
            <xsl:attribute name="id">
200
               <xsl:value-of select="@xml:id"/>
201
            </xsl:attribute>
202
         </xsl:if>
203
         <xsl:apply-templates/>
204
      </wrapper>
205
  </xsl:template>
206
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
207
      <desc/>
208
   </doc>
209
  <xsl:template match="tei:formula" mode="xref">
210
      <xsl:number/>
211
  </xsl:template>
212
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
213
      <desc/>
214
   </doc>
215
  <xsl:template match="tei:formula[@type='display']/m:math">
216
      <m:math display="block">
217
         <xsl:copy-of select="@*"/>
218
         <xsl:apply-templates mode="math"/>
219
      </m:math>
220
  </xsl:template>
221
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
222
      <desc/>
223
   </doc>
224
  <xsl:template match="tei:formula[@type='subeqn']/m:math">
225
      <xsl:apply-templates mode="math"/>
226
  </xsl:template>
227
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
228
      <desc/>
229
   </doc>
230
  <xsl:template match="tei:graphic">
231
      <xsl:call-template name="makePic"/>
232
  </xsl:template>
233
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
234
      <desc/>
235
   </doc>
236
  <xsl:template match="tei:row[@role='header']">
237
      <xsl:text>&#10;</xsl:text>
238
      <table-header>
239
         <xsl:apply-templates select="tei:cell"/>
240
      </table-header>
241
  </xsl:template>
242
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
243
      <desc/>
244
   </doc>
245
  <xsl:template match="tei:table" mode="xref">
246
      <xsl:if test="$showFloatLabel">
247
         <xsl:call-template name="i18n">
248
            <xsl:with-param name="word">tableWord</xsl:with-param>
249
         </xsl:call-template>
250
         <xsl:text> </xsl:text>
251
      </xsl:if>
252
      <xsl:if test="$showFloatHead='true' and tei:head">
253
         <xsl:text> (</xsl:text>
254
         <xsl:apply-templates select="tei:head"/>
255
         <xsl:text>)</xsl:text>
256
      </xsl:if>
257
      <xsl:call-template name="calculateTableNumber"/>
258
  </xsl:template>
259
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
260
      <desc/>
261
   </doc>
262
  <xsl:template match="tei:table">
263
      <xsl:choose>
264
         <xsl:when test="@rend='eqnarray' and $foEngine='passivetex'">
265
            <fotex:eqnarray>
266
               <xsl:apply-templates select=".//tei:formula"/>
267
            </fotex:eqnarray>
268
         </xsl:when>
269
         <xsl:when test=".//tei:formula[@type='subeqn'] and $foEngine='passivetex'">
270
            <fotex:eqnarray>
271
               <xsl:apply-templates select=".//tei:formula"/>
272
            </fotex:eqnarray>
273
         </xsl:when>
274
         <xsl:when test="$inlineTables or @rend='inline'">
275
            <xsl:if test="tei:head">
276
               <block>
277
                  <xsl:call-template name="tableCaptionstyle"/>
278
                  <xsl:call-template name="addID"/>
279
                  <xsl:if test="$makeTableCaption='true'">
280
		    <xsl:call-template name="calculateTableNumber"/>
281
                     <xsl:text>. </xsl:text>
282
                  </xsl:if>
283
                  <xsl:apply-templates select="tei:head"/>
284
               </block>
285
            </xsl:if>
286
            <xsl:call-template name="blockTable"/>
287
         </xsl:when>
288
         <xsl:otherwise>
289
            <xsl:call-template name="floatTable"/>
290
         </xsl:otherwise>
291
      </xsl:choose>
292
  </xsl:template>
293
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
294
      <desc/>
295
   </doc>
296
  <xsl:template match="tei:table[@rend='eqnarray']">
297
      <xsl:choose>
298
         <xsl:when test="$foEngine='passivetex'">
299
            <fotex:eqnarray>
300
               <xsl:for-each select="tei:row">
301
                  <xsl:apply-templates select=".//tei:formula"/>
302
                  <xsl:if test="following-sibling::tei:row">
303
<!--        <character character="&#x2028;"/>-->
304
              <xsl:processing-instruction name="xmltex">\\</xsl:processing-instruction>
305
                  </xsl:if>
306
               </xsl:for-each>
307
            </fotex:eqnarray>
308
         </xsl:when>
309
         <xsl:otherwise>
310
            <xsl:apply-templates/>
311
         </xsl:otherwise>
312
      </xsl:choose>
313
  </xsl:template>
314
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
315
      <desc>[fo] </desc>
316
   </doc>
317
  <xsl:template name="blockTable">
318
      <table text-align="{$tableAlign}" font-size="{$tableSize}">
319
         <xsl:call-template name="addID"/>
320
         <xsl:call-template name="deriveColSpecs"/>
321
         <xsl:apply-templates select="tei:row[@role='header']"/>
322
         <table-body text-indent="0pt">
323
            <xsl:for-each select="tei:row[not(@role='header')]">
324
               <xsl:text>&#10;</xsl:text>
325
               <table-row>
326
                  <xsl:apply-templates select="tei:cell"/>
327
               </table-row>
328
            </xsl:for-each>
329
         </table-body>
330
      </table>
331
  </xsl:template>
332
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
333
      <desc>[fo] table cell properties</desc>
334
   </doc>
335
  <xsl:template name="cellProperties">
336
      <xsl:if test="@role='hi' or @role='label' or   parent::tei:row/@role='label'  or parent::tei:row/@role='header'">
337
         <xsl:attribute name="background-color">
338
            <xsl:value-of select="$defaultCellLabelBackground"/>
339
         </xsl:attribute>
340
      </xsl:if>
341
      <xsl:choose>
342
         <xsl:when test="ancestor::tei:table[1][@rend='frame']">
343
            <xsl:if test="not(parent::tei:row/preceding-sibling::tei:row)">
344
               <xsl:attribute name="border-before-style">solid</xsl:attribute>
345
            </xsl:if>
346
            <xsl:attribute name="border-after-style">solid</xsl:attribute>
347
            <xsl:if test="not(following-sibling::tei:cell)">
348
               <xsl:attribute name="border-end-style">solid</xsl:attribute>
349
            </xsl:if>
350
            <xsl:attribute name="border-start-style">solid</xsl:attribute>
351
         </xsl:when>
352
         <xsl:otherwise>
353
  </xsl:otherwise>
354
      </xsl:choose>
355
      <xsl:if test="not(ancestor::tei:table/@rend='tight')">
356
         <xsl:attribute name="padding">
357
            <xsl:value-of select="$tableCellPadding"/>
358
         </xsl:attribute>
359
      </xsl:if>
360
      <xsl:choose>
361
         <xsl:when test="@align">
362
            <xsl:attribute name="text-align">
363
               <xsl:value-of select="@align"/>
364
            </xsl:attribute>
365
         </xsl:when>
366
         <xsl:otherwise>
367
            <xsl:variable name="thiscol">
368
               <xsl:value-of select="position()"/>
369
            </xsl:variable>
370
            <xsl:variable name="tid">
371
               <xsl:value-of select="ancestor::tei:table/@xml:id"/>
372
            </xsl:variable>
373
            <xsl:variable name="align">
374
               <xsl:value-of select="$tableSpecs/Info/TableSpec[@xml:id=$tid]/table-column[@column-number=$thiscol]/@fotex:column-align"/>
375
            </xsl:variable>
376
            <!--
377
    <xsl:message>    Cell: whats my position: <xsl:value-of select="$thiscol"/>, <xsl:value-of select="$align"/>, <xsl:value-of select="$tid"/>
378
</xsl:message>
379
-->
380
        <xsl:choose>
381
               <xsl:when test="$align='R'">
382
                  <xsl:attribute name="text-align">right</xsl:attribute>
383
               </xsl:when>
384
               <xsl:when test="$align='L'">
385
                  <xsl:attribute name="text-align">left</xsl:attribute>
386
               </xsl:when>
387
               <xsl:when test="$align='C'">
388
                  <xsl:attribute name="text-align">center</xsl:attribute>
389
               </xsl:when>
390
               <xsl:when test="not($align='')">
391
                  <xsl:attribute name="text-align">
392
                     <xsl:value-of select="$align"/>
393
                  </xsl:attribute>
394
               </xsl:when>
395
               <xsl:otherwise>
396
                  <xsl:attribute name="text-align">
397
                     <xsl:value-of select="$cellAlign"/>
398
                  </xsl:attribute>
399
               </xsl:otherwise>
400
            </xsl:choose>
401
         </xsl:otherwise>
402
      </xsl:choose>
403
  </xsl:template>
404
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
405
      <desc>[fo] </desc>
406
   </doc>
407
  <xsl:template name="floatTable">
408
      <table-and-caption>
409
         <xsl:if test="rend='landscape'">
410
            <xsl:attribute name="reference-direction">-90</xsl:attribute>
411
         </xsl:if>
412
         <xsl:call-template name="addID"/>
413
         <table-caption>
414
            <block text-align="{$tableCaptionAlign}" space-after="{$spaceBelowCaption}">
415
               <xsl:call-template name="i18n">
416
                  <xsl:with-param name="word">tableWord</xsl:with-param>
417
               </xsl:call-template>
418
               <xsl:call-template name="calculateTableNumber"/>
419
               <xsl:text>. </xsl:text>
420
               <xsl:apply-templates select="tei:head"/>
421
            </block>
422
         </table-caption>
423
         <xsl:call-template name="blockTable"/>
424
      </table-and-caption>
425
  </xsl:template>
426
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
427
      <desc>[fo] Insert reference to graphics file </desc>
428
   </doc>
429
  <xsl:template name="makePic">
430
      <xsl:variable name="File">
431
         <xsl:choose>
432
            <xsl:when test="@url">
433
               <xsl:value-of select="@url"/>
434
            </xsl:when>
435
            <xsl:when test="@entity">
436
               <xsl:value-of select="unparsed-entity-uri(@entity)"/>
437
            </xsl:when>
438
         </xsl:choose>
439
      </xsl:variable>
440
      <external-graphic>
441
         <xsl:call-template name="addID"/>
442
         <xsl:attribute name="src">
443
            <xsl:text>url(</xsl:text>
444
            <xsl:if test="not(starts-with($File,'./'))">
445
               <xsl:value-of select="$graphicsPrefix"/>
446
            </xsl:if>
447
            <xsl:value-of select="$File"/>
448
            <xsl:if test="not(contains($File,'.'))">
449
               <xsl:value-of select="$graphicsSuffix"/>
450
            </xsl:if>
451
            <xsl:text>)</xsl:text>
452
         </xsl:attribute>
453
         <xsl:call-template name="graphicsAttributes">
454
            <xsl:with-param name="mode">fo</xsl:with-param>
455
         </xsl:call-template>
456
      </external-graphic>
457
  </xsl:template>
458

    
459
  <xsl:template match="tei:binaryObject">
460
    <external-graphic>
461
      <xsl:attribute name="src">
462
	<xsl:text>url('data:image/auto;base64,</xsl:text>
463
	<xsl:value-of select="."/>
464
	<xsl:text>')</xsl:text>
465
      </xsl:attribute>
466
      <xsl:call-template name="graphicsAttributes">
467
	<xsl:with-param name="mode">fo</xsl:with-param>
468
      </xsl:call-template>
469
    </external-graphic>  
470
  </xsl:template>
471

    
472
</xsl:stylesheet>