Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / docx / utils / functions.xsl @ 187

History | View | Annotate | Download (11.1 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
                xmlns:cals="http://www.oasis-open.org/specs/tm9901"
4
                xmlns:tei="http://www.tei-c.org/ns/1.0"
5
                xmlns:iso="http://www.iso.org/ns/1.0"
6
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
7
                xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006"
8
                xmlns:o="urn:schemas-microsoft-com:office:office"
9
                xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
10
                xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
11
                xmlns:v="urn:schemas-microsoft-com:vml"
12
                xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
13
                xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
14
                xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
15
                xmlns:w10="urn:schemas-microsoft-com:office:word"
16
                xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
17
                xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
18
                xmlns:mml="http://www.w3.org/1998/Math/MathML"
19
                xmlns:tbx="http://www.lisa.org/TBX-Specification.33.0.html"
20
                xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
21
		xmlns:teidocx="http://www.tei-c.org/ns/teidocx/1.0"
22
                version="2.0"
23
                exclude-result-prefixes="cals ve o r m v wp w10 w wne mml tbx iso tei a xs pic fn">
24
    
25
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
26
      <desc>
27
         <p> TEI Utility stylesheet for making Word docx files
28
        from TEI XML (see docx-tei.xsl)</p>
29
         <p>This software is dual-licensed:
30

    
31
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
32
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
33

    
34
2. http://www.opensource.org/licenses/BSD-2-Clause
35
		
36
All rights reserved.
37

    
38
Redistribution and use in source and binary forms, with or without
39
modification, are permitted provided that the following conditions are
40
met:
41

    
42
* Redistributions of source code must retain the above copyright
43
notice, this list of conditions and the following disclaimer.
44

    
45
* Redistributions in binary form must reproduce the above copyright
46
notice, this list of conditions and the following disclaimer in the
47
documentation and/or other materials provided with the distribution.
48

    
49
This software is provided by the copyright holders and contributors
50
"as is" and any express or implied warranties, including, but not
51
limited to, the implied warranties of merchantability and fitness for
52
a particular purpose are disclaimed. In no event shall the copyright
53
holder or contributors be liable for any direct, indirect, incidental,
54
special, exemplary, or consequential damages (including, but not
55
limited to, procurement of substitute goods or services; loss of use,
56
data, or profits; or business interruption) however caused and on any
57
theory of liability, whether in contract, strict liability, or tort
58
(including negligence or otherwise) arising in any way out of the use
59
of this software, even if advised of the possibility of such damage.
60
</p>
61
         <p>Author: See AUTHORS</p>
62
         <p>Id: $Id: functions.xsl 9998 2012-01-02 18:27:15Z rahtz $</p>
63
         <p>Copyright: 2008, TEI Consortium</p>
64
      </desc></doc>
65

    
66
    
67
      <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
68
      <desc>Converts a dimension into the 20th of a point.</desc></doc>
69
      <xsl:function name="tei:convert-dim-pt20" as="xs:integer">
70
        <xsl:param name="dim"/>
71
	<xsl:value-of select="tei:convert-dim-pt($dim) * 20"/>
72
      </xsl:function>
73
    
74
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
75
      <desc>Convert a dimension into point.</desc></doc>
76
      <xsl:function name="tei:convert-dim-pt" as="xs:integer">
77
        <xsl:param name="dim"/>
78
        <xsl:choose>
79
	  <xsl:when test="ends-with($dim,'%')">
80
	    <xsl:value-of select="number($pageWidth * number(substring($dim,0,string-length($dim)))) cast as xs:integer"/>
81
	  </xsl:when>
82
	  <xsl:when test="ends-with($dim,'cm')">
83
	    <xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*28.3464567) cast as xs:integer"/>
84
	  </xsl:when>
85
	  <xsl:when test="ends-with($dim,'in')">
86
	    <xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*72) cast as xs:integer"/>
87
	  </xsl:when>
88
	  <xsl:when test="ends-with($dim,'mm')">
89
	    <xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*2.83464567) cast as xs:integer"/>
90
	  </xsl:when>
91
	  <xsl:when test="ends-with($dim,'pt')">
92
	    <xsl:value-of select="number(substring($dim,0,string-length($dim)-1)) cast as xs:integer"/>
93
	  </xsl:when>
94
	  <xsl:when test="ends-with($dim,'px')">
95
	    <xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*0.75) cast as xs:integer"/>
96
	  </xsl:when>            
97
	  <xsl:otherwise>
98
	    -1
99
	  </xsl:otherwise>
100
        </xsl:choose>
101
    </xsl:function>
102
    
103
        <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
104
      <desc>Convert a dimension into english metric unit.</desc></doc>
105
    <xsl:function name="tei:convert-dim-emu" as="xs:integer">
106
        <xsl:param name="dim"/>
107
	<xsl:variable name="result">
108
	  <xsl:choose>
109
            <xsl:when test="ends-with($dim,'cm')">
110
	      <xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*3600) cast as xs:integer"/>
111
            </xsl:when>
112
            <xsl:when test="ends-with($dim,'in')">
113
	      <xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*9144) cast as xs:integer"/>
114
            </xsl:when>
115
            <xsl:when test="ends-with($dim,'mm')">
116
                <xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*360) cast as xs:integer"/>
117
            </xsl:when>
118
            <xsl:when test="ends-with($dim,'pt')">
119
                <xsl:value-of select="number(number(number(substring($dim,0,string-length($dim)-1)) div 72) * 9144) cast as xs:integer"/>
120
            </xsl:when>
121
            <xsl:when test="ends-with($dim,'px')">
122
                <xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*95.25) cast as xs:integer"/>
123
            </xsl:when>            
124
            <xsl:otherwise>
125
                -1
126
            </xsl:otherwise>
127
	  </xsl:choose>
128
	</xsl:variable>
129
	<xsl:value-of select="$result"/>
130
    </xsl:function>
131
    
132
        <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
133
      <desc>Returns a listtype for a given stylename (return empty string to figure it out dynamically).</desc></doc>
134
    <xsl:function name="tei:get-listtype" as="xs:string">
135
        <xsl:param name="style"/>
136
        <xsl:text/>
137
    </xsl:function>
138
    
139
        <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
140
      <desc>Returns the correct heading style (return empty string to figure it out dynamically).</desc></doc>
141
    <xsl:function name="tei:get-headingstyle" as="xs:string">
142
        <xsl:param name="element"/>
143
        <xsl:param name="level"/>
144

    
145
        <xsl:text/>
146
    </xsl:function>    
147
    
148
        <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
149
      <desc>Defines whether or not a word paragraph is a first level heading.</desc></doc>
150
    <xsl:function name="tei:is-firstlevel-heading" as="xs:boolean">
151
        <xsl:param name="p"/>
152
        
153
        <xsl:choose>
154
            <xsl:when test="$p[w:pPr/w:pStyle/@w:val='heading 1']">true</xsl:when>
155
            <xsl:when test="$p[w:pPr/w:pStyle/@w:val='Heading 1']">true</xsl:when>
156
            <xsl:otherwise>false</xsl:otherwise>
157
        </xsl:choose>
158
    </xsl:function>
159
    
160
        <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
161
      <desc>Defines whether or not a word paragraph is a  heading.</desc></doc>
162
    <xsl:function name="tei:is-heading" as="xs:boolean">
163
        <xsl:param name="p"/>
164
	<xsl:variable name="s" select="$p/w:pPr/w:pStyle/@w:val"/>
165
      
166
        <xsl:choose>
167
            <xsl:when test="starts-with($s,'Heading')">true</xsl:when>
168
            <xsl:when test="starts-with($s,'heading')">true</xsl:when>
169
            <xsl:otherwise>false</xsl:otherwise>
170
        </xsl:choose>
171
    </xsl:function>
172

    
173
        <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
174
      <desc>Defines whether or not a word paragraph is a list element.</desc></doc>
175
    <xsl:function name="tei:is-list" as="xs:boolean">
176
        <xsl:param name="p"/>        
177
        <xsl:choose>
178
            <xsl:when test="$p[contains(w:pPr/w:pStyle/@w:val,'List')]">true</xsl:when>
179
            <xsl:when test="$p[w:pPr/w:pStyle/@w:val='dl']">true</xsl:when>
180
            <xsl:otherwise>false</xsl:otherwise>
181
        </xsl:choose>
182
    </xsl:function>
183

    
184
        <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
185
      <desc>Defines whether or not a word paragraph is a table of contents.</desc></doc>
186
    <xsl:function name="tei:is-toc" as="xs:boolean">
187
        <xsl:param name="p"/>        
188
        <xsl:choose>
189
            <xsl:when test="$p[contains(w:pPr/w:pStyle/@w:val,'toc')]">true</xsl:when>
190
            <xsl:otherwise>false</xsl:otherwise>
191
        </xsl:choose>
192
    </xsl:function>
193

    
194
        <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
195
      <desc>Defines whether or not a word paragraph is a figure element.</desc></doc>
196
    <xsl:function name="tei:is-figure" as="xs:boolean">
197
        <xsl:param name="p"/>        
198
        <xsl:choose>
199
            <xsl:when test="$p[contains(w:pPr/w:pStyle/@w:val,'Figure')]">true</xsl:when>
200
            <xsl:when test="$p[contains(w:pPr/w:pStyle/@w:val,'Caption')]">true</xsl:when>
201
            <xsl:otherwise>false</xsl:otherwise>
202
        </xsl:choose>
203
    </xsl:function>
204
    
205

    
206
        <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
207
      <desc>Defines whether or not a word paragraph is a line of poetry.</desc></doc>
208
    <xsl:function name="tei:is-line" as="xs:boolean">
209
        <xsl:param name="p"/>        
210
        <xsl:choose>
211
            <xsl:when test="$p[w:pPr/w:pStyle/@w:val='tei_l']">true</xsl:when>
212
            <xsl:otherwise>false</xsl:otherwise>
213
        </xsl:choose>
214
    </xsl:function>
215

    
216
        <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
217
      <desc>Defines whether or not a word paragraph is gloss list.</desc></doc>
218
    <xsl:function name="tei:is-glosslist" as="xs:boolean">
219
        <xsl:param name="p"/>        
220
        <xsl:choose>
221
            <xsl:when test="$p[w:pPr/w:pStyle/@w:val='dl']">true</xsl:when>
222
            <xsl:otherwise>false</xsl:otherwise>
223
        </xsl:choose>
224
    </xsl:function>
225
    
226
        <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
227
      <desc>Is given a header style and returns the style for the next level header.</desc></doc>
228
    <xsl:function name="tei:get-nextlevel-header" as="xs:string">
229
        <xsl:param name="current-header"/>
230
        <xsl:value-of select="translate($current-header,'12345678','23456789')"/>
231
    </xsl:function>
232
    
233

    
234
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
235
      <desc>
236
		Returns the current date.</desc></doc>
237

    
238
	  <xsl:function name="tei:whatsTheDate">
239
        <xsl:value-of select="format-dateTime(current-dateTime(),'[Y]-[M02]-[D02]T[H02]:[m02]:[s02]Z')"/>
240
    </xsl:function>
241

    
242
</xsl:stylesheet>