Statistics
| Revision:

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

History | View | Annotate | Download (11 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:tei="http://www.tei-c.org/ns/1.0"
3
                
4
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5
                exclude-result-prefixes="tei"
6
                version="2.0">
7
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
8
      <desc>
9
         <p> TEI stylesheet dealing with elements from the figures module. </p>
10
         <p>This software is dual-licensed:
11

    
12
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
13
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
14

    
15
2. http://www.opensource.org/licenses/BSD-2-Clause
16
		
17
All rights reserved.
18

    
19
Redistribution and use in source and binary forms, with or without
20
modification, are permitted provided that the following conditions are
21
met:
22

    
23
* Redistributions of source code must retain the above copyright
24
notice, this list of conditions and the following disclaimer.
25

    
26
* Redistributions in binary form must reproduce the above copyright
27
notice, this list of conditions and the following disclaimer in the
28
documentation and/or other materials provided with the distribution.
29

    
30
This software is provided by the copyright holders and contributors
31
"as is" and any express or implied warranties, including, but not
32
limited to, the implied warranties of merchantability and fitness for
33
a particular purpose are disclaimed. In no event shall the copyright
34
holder or contributors be liable for any direct, indirect, incidental,
35
special, exemplary, or consequential damages (including, but not
36
limited to, procurement of substitute goods or services; loss of use,
37
data, or profits; or business interruption) however caused and on any
38
theory of liability, whether in contract, strict liability, or tort
39
(including negligence or otherwise) arising in any way out of the use
40
of this software, even if advised of the possibility of such damage.
41
</p>
42
         <p>Author: See AUTHORS</p>
43
         <p>Id: $Id: figures.xsl 10042 2012-01-13 15:23:16Z rahtz $</p>
44
         <p>Copyright: 2011, TEI Consortium</p>
45
      </desc>
46
   </doc>
47
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
48
      <desc>Process element figure</desc>
49
   </doc>
50
  <xsl:template match="tei:figure" mode="xref">
51
      <xsl:choose>
52
	<xsl:when test="tei:head">
53
	  <xsl:call-template name="calculateFigureNumber"/>
54
	  <xsl:text>, </xsl:text>
55
	  <xsl:apply-templates mode="plain" select="tei:head"/>
56
	</xsl:when>
57
	<xsl:otherwise>
58
            <xsl:text>this figure</xsl:text>
59
         </xsl:otherwise>
60
      </xsl:choose>
61
  </xsl:template>
62
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
63
      <desc>Process element table</desc>
64
   </doc>
65
  <xsl:template match="tei:table" mode="xref">
66
      <xsl:choose>
67
         <xsl:when test="$numberTables='true'">
68
	   <xsl:call-template name="calculateTableNumber"/>
69
            <xsl:if test="tei:head">
70
               <xsl:text>. </xsl:text>
71
               <xsl:apply-templates mode="plain" select="tei:head"/>
72
            </xsl:if>
73
         </xsl:when>
74
         <xsl:otherwise>
75
	   <xsl:choose>
76
            <xsl:when test="tei:head">
77
               <xsl:apply-templates mode="plain" select="tei:head"/>
78
	    </xsl:when>
79
	    <xsl:otherwise>
80
	      <xsl:text>table</xsl:text>
81
	    </xsl:otherwise>
82
	   </xsl:choose>
83
         </xsl:otherwise>
84
      </xsl:choose>
85
  </xsl:template>
86
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
87
      <desc>[latex] Analyze attributes of graphics inclusion<param name="mode">Type of output (fo, html, latex) being
88
    created</param>
89
      </desc>
90
   </doc>
91
  <xsl:template name="graphicsAttributes">
92
      <xsl:param name="mode">fo</xsl:param>
93
      <xsl:if test="@width">
94
         <xsl:choose>
95
            <xsl:when test="ends-with(@width,'%')">
96
               <xsl:choose>
97
                  <xsl:when test="$mode='fo'">
98
                     <xsl:attribute name="content-width">
99
                        <xsl:value-of select="@width"/>
100
                     </xsl:attribute>
101
                  </xsl:when>
102
                  <xsl:when test="$mode='latex'">
103
                     <xsl:text>width=</xsl:text>
104
                     <xsl:value-of select="number(substring-before(@width,'%')) div 100"/>
105
                     <xsl:text>\textwidth,</xsl:text>
106
                  </xsl:when>
107
                  <xsl:otherwise>
108
                     <xsl:attribute name="width">
109
                        <xsl:value-of select="@width"/>
110
                     </xsl:attribute>
111
                  </xsl:otherwise>
112
               </xsl:choose>
113
            </xsl:when>
114
            <xsl:otherwise>
115
               <xsl:variable name="w">
116
                  <xsl:choose>
117
                     <xsl:when test="ends-with(@width,'pt')">
118
                        <xsl:value-of select="@width"/>
119
                     </xsl:when>
120
                     <xsl:when test="ends-with(@width,'px') and $mode='latex'">
121
                        <xsl:value-of select="substring-before(@width,'px')"/>
122
                        <xsl:text>pt</xsl:text>
123
                     </xsl:when>
124
                     <xsl:when test="ends-with(@width,'in')">
125
                        <xsl:value-of select="@width"/>
126
                     </xsl:when>
127
                     <xsl:when test="ends-with(@width,'px')">
128
                        <xsl:value-of select="@width"/>
129
                     </xsl:when>
130
                     <xsl:when test="ends-with(@width,'cm')">
131
                        <xsl:value-of select="@width"/>
132
                     </xsl:when>
133
                     <xsl:otherwise>
134
                        <xsl:value-of select="@width"/>
135
                        <xsl:text>pt</xsl:text>
136
                     </xsl:otherwise>
137
                  </xsl:choose>
138
               </xsl:variable>
139
               <xsl:choose>
140
                  <xsl:when test="$mode='fo'">
141
                     <xsl:attribute name="content-width">
142
                        <xsl:value-of select="$w"/>
143
                     </xsl:attribute>
144
                  </xsl:when>
145
                  <xsl:when test="$mode='latex'">
146
                     <xsl:text>width=</xsl:text>
147
                     <xsl:value-of select="$w"/>
148
                     <xsl:text>,</xsl:text>
149
                  </xsl:when>
150
               </xsl:choose>
151
            </xsl:otherwise>
152
         </xsl:choose>
153
      </xsl:if>
154
      <xsl:if test="@height">
155
         <xsl:choose>
156
            <xsl:when test="ends-with(@height,'%')">
157
               <xsl:choose>
158
                  <xsl:when test="$mode='fo'">
159
                     <xsl:attribute name="content-height">
160
                        <xsl:value-of select="@height"/>
161
                     </xsl:attribute>
162
                  </xsl:when>
163
                  <xsl:when test="$mode='latex'">
164
                     <xsl:text>height=</xsl:text>
165
                     <xsl:value-of select="number(substring-before(@height,'%')) div 100"/>
166
                     <xsl:text>\textheight,</xsl:text>
167
                  </xsl:when>
168
                  <xsl:otherwise>
169
                     <xsl:attribute name="height">
170
                        <xsl:value-of select="@height"/>
171
                     </xsl:attribute>
172
                  </xsl:otherwise>
173
               </xsl:choose>
174
            </xsl:when>
175
            <xsl:otherwise>
176
               <xsl:variable name="h">
177
                  <xsl:choose>
178
                     <xsl:when test="ends-with(@height,'pt')">
179
                        <xsl:value-of select="@height"/>
180
                     </xsl:when>
181
                     <xsl:when test="ends-with(@height,'px') and $mode='latex'">
182
                        <xsl:value-of select="substring-before(@height,'px')"/>
183
                        <xsl:text>pt</xsl:text>
184
                     </xsl:when>
185
                     <xsl:when test="ends-with(@height,'in')">
186
                        <xsl:value-of select="@height"/>
187
                     </xsl:when>
188
                     <xsl:when test="ends-with(@height,'px')">
189
                        <xsl:value-of select="@height"/>
190
                     </xsl:when>
191
                     <xsl:when test="ends-with(@height,'cm')">
192
                        <xsl:value-of select="@height"/>
193
                     </xsl:when>
194
                     <xsl:otherwise>
195
                        <xsl:value-of select="@height"/>
196
                        <xsl:text>pt</xsl:text>
197
                     </xsl:otherwise>
198
                  </xsl:choose>
199
               </xsl:variable>
200
               <xsl:choose>
201
                  <xsl:when test="$mode='fo'">
202
                     <xsl:attribute name="content-height">
203
                        <xsl:value-of select="$h"/>
204
                     </xsl:attribute>
205
                  </xsl:when>
206
                  <xsl:when test="$mode='latex'">
207
                     <xsl:text>height=</xsl:text>
208
                     <xsl:value-of select="$h"/>
209
                     <xsl:text>,</xsl:text>
210
                  </xsl:when>
211
               </xsl:choose>
212
            </xsl:otherwise>
213
         </xsl:choose>
214
      </xsl:if>
215
      <xsl:variable name="s">
216
         <xsl:choose>
217
            <xsl:when test="@scale and ends-with(@scale,'%')">
218
               <xsl:value-of select="number(substring-before(@scale,'%')) div 100"/>
219
            </xsl:when>
220
            <xsl:when test="@scale">
221
               <xsl:value-of select="@scale"/>
222
            </xsl:when>
223
            <xsl:when test="not(@width) and not(@height) and not($standardScale=1)">
224
               <xsl:value-of select="$standardScale"/>
225
            </xsl:when>
226
         </xsl:choose>
227
      </xsl:variable>
228
      <xsl:if test="not($s='')">
229
         <xsl:choose>
230
            <xsl:when test="$mode='fo'">
231
               <xsl:attribute name="scale">
232
                  <xsl:value-of select="$s"/>
233
               </xsl:attribute>
234
            </xsl:when>
235
            <xsl:when test="$mode='latex'">
236
               <xsl:text>scale=</xsl:text>
237
               <xsl:value-of select="$s"/>
238
               <xsl:text>,</xsl:text>
239
            </xsl:when>
240
         </xsl:choose>
241
      </xsl:if>
242
  </xsl:template>
243

    
244
  <xsl:template name="calculateFigureNumber">
245
    <xsl:choose>
246
      <xsl:when test="ancestor::tei:front and  $numberFrontFigures='true'">
247
	<xsl:call-template name="i18n">
248
	  <xsl:with-param name="word">figureWord</xsl:with-param>
249
	</xsl:call-template>
250
	<xsl:text> </xsl:text>
251
	<xsl:number count="tei:figure[tei:head]" from="tei:front" level="any"/>
252
      </xsl:when>
253
      <xsl:when test="ancestor::tei:back and $numberBackFigures='true'">
254
	<xsl:call-template name="i18n">
255
	  <xsl:with-param name="word">figureWord</xsl:with-param>
256
	</xsl:call-template>
257
	<xsl:text> </xsl:text>
258
	<xsl:number count="tei:figure[tei:head]" from="tei:back" level="any"/>
259
      </xsl:when>
260
      <xsl:when test="ancestor::tei:body and $numberFigures='true'">
261
	<xsl:call-template name="i18n">
262
	  <xsl:with-param name="word">figureWord</xsl:with-param>
263
	</xsl:call-template>
264
	<xsl:text> </xsl:text>
265
	<xsl:number count="tei:figure[tei:head]" from="tei:body" level="any"/>
266
      </xsl:when>
267
    </xsl:choose>    
268
  </xsl:template>
269

    
270

    
271
  <xsl:template name="calculateTableNumber">
272
    <xsl:call-template name="i18n">
273
      <xsl:with-param name="word">tableWord</xsl:with-param>
274
    </xsl:call-template>
275
    <xsl:text> </xsl:text>
276
    <xsl:number level="any"/>
277
  </xsl:template>
278

    
279
</xsl:stylesheet>