Update ooo320-m1
[ooovba.git] / filter / source / xslt / common / math.xsl
blob166e715d5d9628f801e5aef0fe85d919cefbe6f3
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 Copyright 2008 by Sun Microsystems, Inc.
8 OpenOffice.org - a multi-platform office productivity suite
10 $RCSfile: math.xsl,v $
12 $Revision: 1.8 $
14 This file is part of OpenOffice.org.
16 OpenOffice.org is free software: you can redistribute it and/or modify
17 it under the terms of the GNU Lesser General Public License version 3
18 only, as published by the Free Software Foundation.
20 OpenOffice.org is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU Lesser General Public License version 3 for more details
24 (a copy is included in the LICENSE file that accompanied this code).
26 You should have received a copy of the GNU Lesser General Public License
27 version 3 along with OpenOffice.org. If not, see
28 <http://www.openoffice.org/license.html>
29 for a copy of the LGPLv3 License.
31 -->
32 <!--
33 xslt math lib by Wind Li
34 Public Functions
35 sin(x,rounding-factor=100)
36 cos(x,rounding-factor=100)
37 tan(x,rounding-factor=100)
38 ctan(x,rounding-factor=100)
39 atan2(x, y ,rounding-factor=100)
40 atan(x,rounding-factor=100)
41 acos(x,rounding-factor=100)
42 asin(x,rounding-factor=100)
43 abs(x)
44 max(x1,x2)
45 min(x1,x2)
46 power(x,power(interger only), rounding-factor=100)
47 sqrt(x, rounding-factor=100)
48 convert2radian(x,rounding-factor=100)
49 convert2degree(x,rounding-factor=100)
50 convert2fd(x,rounding-factor=100)
51 -->
52 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:text="http://openoffice.org/2000/text" xmlns:style="http://openoffice.org/2000/style" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:office="http://openoffice.org/2000/office" exclude-result-prefixes="draw svg style office fo text">
53 <xsl:variable name="pi" select="3.1416"/>
54 <xsl:template name="math-test">
55 sin(34.8)
56 <xsl:call-template name="sin">
57 <xsl:with-param name="x" select="34.8"/>
58 <xsl:with-param name="rounding-factor" select="100000"/>
59 </xsl:call-template>
60 cos(34.8)
61 <xsl:call-template name="cos">
62 <xsl:with-param name="x" select="34.8"/>
63 <xsl:with-param name="rounding-factor" select="100000"/>
64 </xsl:call-template>
65 atan(2.74)
66 <xsl:call-template name="atan">
67 <xsl:with-param name="x" select="2.74"/>
68 <xsl:with-param name="rounding-factor" select="100000"/>
69 </xsl:call-template>
70 acos(0.5)
71 <xsl:call-template name="acos">
72 <xsl:with-param name="x" select="0.5"/>
73 <xsl:with-param name="rounding-factor" select="100000"/>
74 </xsl:call-template>
75 asin(0.5)
76 <xsl:call-template name="asin">
77 <xsl:with-param name="x" select="0.5"/>
78 <xsl:with-param name="rounding-factor" select="100000"/>
79 </xsl:call-template>
80 sqrt(1328.3414)
81 <xsl:call-template name="sqrt">
82 <xsl:with-param name="x" select="1328.3414"/>
83 <xsl:with-param name="rounding-factor" select="100000"/>
84 </xsl:call-template>
85 </xsl:template>
86 <!-- public functions start -->
87 <xsl:template name="sin">
88 <xsl:param name="x" select="0"/>
89 <xsl:param name="rounding-factor" select="100"/>
90 <xsl:variable name="angle" select="$x * 180 div $pi "/>
91 <xsl:variable name="mod-angle" select="$angle mod 360"/>
92 <xsl:variable name="sinx">
93 <xsl:call-template name="sin-private">
94 <xsl:with-param name="x" select=" ( $angle mod 360 ) * $pi div 180 "/>
95 </xsl:call-template>
96 </xsl:variable>
97 <xsl:value-of select=" round ( number($sinx) * $rounding-factor ) div $rounding-factor"/>
98 </xsl:template>
99 <xsl:template name="cos">
100 <xsl:param name="x" select="0"/>
101 <xsl:param name="rounding-factor" select="100"/>
102 <xsl:variable name="angle" select="$x * 180 div $pi "/>
103 <xsl:variable name="mod-angle" select="$angle mod 360"/>
104 <xsl:variable name="cosx">
105 <xsl:call-template name="cos-private">
106 <xsl:with-param name="x" select=" ( $angle mod 360 ) * $pi div 180 "/>
107 </xsl:call-template>
108 </xsl:variable>
109 <xsl:value-of select=" round ( number($cosx) * $rounding-factor ) div $rounding-factor"/>
110 </xsl:template>
111 <xsl:template name="tan">
112 <xsl:param name="x" select="0"/>
113 <xsl:param name="rounding-factor" select="100"/>
114 <xsl:variable name="sinx">
115 <xsl:call-template name="sin">
116 <xsl:with-param name="x" select="$x"/>
117 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
118 </xsl:call-template>
119 </xsl:variable>
120 <xsl:variable name="cosx">
121 <xsl:call-template name="cos">
122 <xsl:with-param name="x" select="$x"/>
123 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
124 </xsl:call-template>
125 </xsl:variable>
126 <xsl:choose>
127 <xsl:when test=" $cosx = 0 ">
128 <xsl:message>tan error : tan(<xsl:value-of select="$x"/>) is infinite!</xsl:message>
129 <xsl:value-of select="63535"/>
130 </xsl:when>
131 <xsl:otherwise>
132 <xsl:value-of select=" round( $sinx div $cosx * $rounding-factor) div $rounding-factor"/>
133 </xsl:otherwise>
134 </xsl:choose>
135 </xsl:template>
136 <xsl:template name="ctan">
137 <xsl:param name="x" select="0"/>
138 <xsl:param name="rounding-factor" select="100"/>
139 <xsl:variable name="sinx">
140 <xsl:call-template name="sin">
141 <xsl:with-param name="x" select="$x"/>
142 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
143 </xsl:call-template>
144 </xsl:variable>
145 <xsl:variable name="cosx">
146 <xsl:call-template name="cos">
147 <xsl:with-param name="x" select="$x"/>
148 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
149 </xsl:call-template>
150 </xsl:variable>
151 <xsl:choose>
152 <xsl:when test=" $sinx = 0 ">
153 <xsl:message>tan error : tan(<xsl:value-of select="$x"/>) is infinite!</xsl:message>
154 <xsl:value-of select="63535"/>
155 </xsl:when>
156 <xsl:otherwise>
157 <xsl:value-of select=" round( $cosx div $sinx * $rounding-factor) div $rounding-factor"/>
158 </xsl:otherwise>
159 </xsl:choose>
160 </xsl:template>
161 <xsl:template name="atan">
162 <xsl:param name="x" select="0"/>
163 <xsl:param name="rounding-factor" select="100"/>
164 <xsl:choose>
165 <xsl:when test="$x = 0">
166 <xsl:value-of select="0"/>
167 </xsl:when>
168 <xsl:when test="$x &lt; 0">
169 <xsl:variable name="atan-x">
170 <xsl:call-template name="atan">
171 <xsl:with-param name="x" select=" -1 * $x"/>
172 <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
173 </xsl:call-template>
174 </xsl:variable>
175 <xsl:value-of select="-1 * $atan-x"/>
176 </xsl:when>
177 <xsl:when test="$x &gt; 1">
178 <xsl:variable name="atan-div-x">
179 <xsl:call-template name="atan">
180 <xsl:with-param name="x" select="1 div $x "/>
181 <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
182 </xsl:call-template>
183 </xsl:variable>
184 <xsl:value-of select=" $pi div 2 - $atan-div-x"/>
185 </xsl:when>
186 <xsl:otherwise>
187 <xsl:variable name="arctanx">
188 <xsl:call-template name="atan-private">
189 <xsl:with-param name="x" select=" $x "/>
190 </xsl:call-template>
191 </xsl:variable>
192 <xsl:value-of select=" round ( number($arctanx) * $rounding-factor ) div $rounding-factor"/>
193 </xsl:otherwise>
194 </xsl:choose>
195 </xsl:template>
196 <xsl:template name="atan2">
197 <xsl:param name="x"/>
198 <xsl:param name="y"/>
199 <xsl:param name="rounding-factor" select="100"/>
200 <xsl:choose>
201 <xsl:when test="$x = 0">
202 <xsl:value-of select=" $pi div 2"/>
203 </xsl:when>
204 <xsl:otherwise>
205 <xsl:call-template name="atan">
206 <xsl:with-param name="x" select="$y div $x"/>
207 <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
208 </xsl:call-template>
209 </xsl:otherwise>
210 </xsl:choose>
211 </xsl:template>
212 <xsl:template name="acos">
213 <xsl:param name="x"/>
214 <xsl:param name="rounding-factor" select="100"/>
215 <xsl:variable name="abs-x">
216 <xsl:call-template name="abs">
217 <xsl:with-param name="x" select="$x"/>
218 </xsl:call-template>
219 </xsl:variable>
220 <xsl:choose>
221 <xsl:when test="$abs-x &gt; 1">
222 <xsl:message>acos error : abs(<xsl:value-of select="$x"/>) greate then 1 !</xsl:message>
223 </xsl:when>
224 <xsl:otherwise>
225 <xsl:call-template name="atan2">
226 <xsl:with-param name="x" select="$x"/>
227 <xsl:with-param name="y">
228 <xsl:call-template name="sqrt">
229 <xsl:with-param name="x" select="1 - $x * $x"/>
230 <xsl:with-param name="rounding-factor" select=" concat($rounding-factor,'0') "/>
231 </xsl:call-template>
232 </xsl:with-param>
233 </xsl:call-template>
234 </xsl:otherwise>
235 </xsl:choose>
236 </xsl:template>
237 <xsl:template name="asin">
238 <xsl:param name="x"/>
239 <xsl:param name="rounding-factor" select="100"/>
240 <xsl:variable name="abs-x">
241 <xsl:call-template name="abs">
242 <xsl:with-param name="x" select="$x"/>
243 </xsl:call-template>
244 </xsl:variable>
245 <xsl:choose>
246 <xsl:when test="$abs-x &gt; 1">
247 <xsl:message>asin error : abs(<xsl:value-of select="$x"/>) greate then 1 !</xsl:message>
248 </xsl:when>
249 <xsl:otherwise>
250 <xsl:call-template name="atan2">
251 <xsl:with-param name="y" select="$x"/>
252 <xsl:with-param name="x">
253 <xsl:call-template name="sqrt">
254 <xsl:with-param name="x" select="1 - $x * $x"/>
255 <xsl:with-param name="rounding-factor" select=" concat($rounding-factor,'0') "/>
256 </xsl:call-template>
257 </xsl:with-param>
258 </xsl:call-template>
259 </xsl:otherwise>
260 </xsl:choose>
261 </xsl:template>
262 <xsl:template name="abs">
263 <xsl:param name="x"/>
264 <xsl:choose>
265 <xsl:when test="$x &gt; 0">
266 <xsl:value-of select="$x"/>
267 </xsl:when>
268 <xsl:otherwise>
269 <xsl:value-of select="$x * -1"/>
270 </xsl:otherwise>
271 </xsl:choose>
272 </xsl:template>
273 <xsl:template name="max">
274 <xsl:param name="x1"/>
275 <xsl:param name="x2"/>
276 <xsl:choose>
277 <xsl:when test="$x1 &gt; $x2">
278 <xsl:value-of select="$x1"/>
279 </xsl:when>
280 <xsl:otherwise>
281 <xsl:value-of select="$x2"/>
282 </xsl:otherwise>
283 </xsl:choose>
284 </xsl:template>
285 <xsl:template name="min">
286 <xsl:param name="x1"/>
287 <xsl:param name="x2"/>
288 <xsl:choose>
289 <xsl:when test="$x1 &lt; $x2">
290 <xsl:value-of select="$x1"/>
291 </xsl:when>
292 <xsl:otherwise>
293 <xsl:value-of select="$x2"/>
294 </xsl:otherwise>
295 </xsl:choose>
296 </xsl:template>
297 <xsl:template name="power">
298 <xsl:param name="x"/>
299 <xsl:param name="y" select="1"/>
300 <xsl:param name="rounding-factor" select="100"/>
301 <!-- z is a private param -->
302 <xsl:param name="z" select="1"/>
303 <xsl:choose>
304 <xsl:when test="$y &gt; 0">
305 <xsl:call-template name="power">
306 <xsl:with-param name="x" select="$x"/>
307 <xsl:with-param name="y" select="$y - 1"/>
308 <xsl:with-param name="z" select="$z * $x"/>
309 <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
310 </xsl:call-template>
311 </xsl:when>
312 <xsl:otherwise>
313 <xsl:value-of select=" round( $z * $rounding-factor) div $rounding-factor"/>
314 </xsl:otherwise>
315 </xsl:choose>
316 </xsl:template>
317 <xsl:template name="sqrt">
318 <xsl:param name="x"/>
319 <xsl:param name="rounding-factor" select="100"/>
320 <xsl:choose>
321 <xsl:when test="$x = 0">0</xsl:when>
322 <xsl:when test="$x &lt; 0">
323 <xsl:message>sqrt error : <xsl:value-of select="$x"/> less then 0!</xsl:message>
324 </xsl:when>
325 <xsl:otherwise>
326 <xsl:call-template name="sqrt-private">
327 <xsl:with-param name="x" select="$x"/>
328 <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
329 </xsl:call-template>
330 </xsl:otherwise>
331 </xsl:choose>
332 </xsl:template>
333 <!-- public functions end -->
334 <!--
335 Private functions:
336 sin-private
337 cos-private
338 atan-private
339 sqrt-private
340 integer-sqrt
341 Sqrt-GetOneDigit
343 <xsl:template name="sin-private">
344 <xsl:param name="x" select="0"/>
345 <xsl:param name="n" select="0"/>
346 <xsl:param name="nx" select="1"/>
347 <xsl:param name="sign" select="1"/>
348 <xsl:param name="max-n" select="20"/>
349 <xsl:param name="sinx" select="0"/>
350 <xsl:choose>
351 <xsl:when test="not ($max-n &gt; $n) or $nx = 0 ">
352 <xsl:value-of select="$sinx"/>
353 </xsl:when>
354 <xsl:when test="$n = 0">
355 <xsl:call-template name="sin-private">
356 <xsl:with-param name="x" select="$x"/>
357 <xsl:with-param name="n" select="$n + 1"/>
358 <xsl:with-param name="sign" select="$sign * -1"/>
359 <xsl:with-param name="max-n" select="$max-n"/>
360 <xsl:with-param name="nx" select="$x "/>
361 <xsl:with-param name="sinx" select="$sinx + $x"/>
362 </xsl:call-template>
363 </xsl:when>
364 <xsl:otherwise>
365 <xsl:variable name="new-nx" select="($nx * $x * $x) div ( 2 * $n ) div ( 2 * $n + 1) "/>
366 <xsl:call-template name="sin-private">
367 <xsl:with-param name="x" select="$x"/>
368 <xsl:with-param name="n" select="$n + 1"/>
369 <xsl:with-param name="sign" select="$sign * -1"/>
370 <xsl:with-param name="max-n" select="$max-n"/>
371 <xsl:with-param name="nx" select=" $new-nx "/>
372 <xsl:with-param name="sinx" select="$sinx + $new-nx * $sign"/>
373 </xsl:call-template>
374 </xsl:otherwise>
375 </xsl:choose>
376 </xsl:template>
377 <xsl:template name="cos-private">
378 <xsl:param name="x" select="0"/>
379 <xsl:param name="n" select="0"/>
380 <xsl:param name="nx" select="1"/>
381 <xsl:param name="sign" select="1"/>
382 <xsl:param name="max-n" select="20"/>
383 <xsl:param name="cosx" select="0"/>
384 <xsl:choose>
385 <xsl:when test="not ($max-n &gt; $n) or $nx = 0 ">
386 <xsl:value-of select="$cosx"/>
387 </xsl:when>
388 <xsl:when test="$n = 0">
389 <xsl:call-template name="cos-private">
390 <xsl:with-param name="x" select="$x"/>
391 <xsl:with-param name="n" select="$n + 1"/>
392 <xsl:with-param name="sign" select="$sign * -1"/>
393 <xsl:with-param name="max-n" select="$max-n"/>
394 <xsl:with-param name="nx" select=" 1 "/>
395 <xsl:with-param name="cosx" select="1"/>
396 </xsl:call-template>
397 </xsl:when>
398 <xsl:otherwise>
399 <xsl:variable name="new-nx" select="($nx * $x * $x) div ( 2 * $n -1 ) div ( 2 * $n ) "/>
400 <xsl:call-template name="cos-private">
401 <xsl:with-param name="x" select="$x"/>
402 <xsl:with-param name="n" select="$n + 1"/>
403 <xsl:with-param name="sign" select="$sign * -1"/>
404 <xsl:with-param name="max-n" select="$max-n"/>
405 <xsl:with-param name="nx" select=" $new-nx "/>
406 <xsl:with-param name="cosx" select="$cosx + $new-nx * $sign"/>
407 </xsl:call-template>
408 </xsl:otherwise>
409 </xsl:choose>
410 </xsl:template>
411 <xsl:template name="atan-private">
412 <xsl:param name="x" select="0"/>
413 <xsl:param name="n" select="0"/>
414 <xsl:param name="nx" select="1"/>
415 <xsl:param name="sign" select="1"/>
416 <xsl:param name="max-n" select="40"/>
417 <xsl:param name="arctanx" select="0"/>
418 <xsl:choose>
419 <xsl:when test="not ($max-n &gt; $n) or $nx = 0 ">
420 <xsl:value-of select="$arctanx"/>
421 </xsl:when>
422 <xsl:when test="$n = 0">
423 <xsl:call-template name="atan-private">
424 <xsl:with-param name="x" select="$x"/>
425 <xsl:with-param name="n" select="$n + 1"/>
426 <xsl:with-param name="sign" select="$sign * -1"/>
427 <xsl:with-param name="max-n" select="$max-n"/>
428 <xsl:with-param name="nx" select="$x "/>
429 <xsl:with-param name="arctanx" select="$arctanx + $x"/>
430 </xsl:call-template>
431 </xsl:when>
432 <xsl:otherwise>
433 <xsl:variable name="new-nx" select=" $nx * $x * $x "/>
434 <xsl:call-template name="atan-private">
435 <xsl:with-param name="x" select="$x"/>
436 <xsl:with-param name="n" select="$n + 1"/>
437 <xsl:with-param name="sign" select="$sign * -1"/>
438 <xsl:with-param name="max-n" select="$max-n"/>
439 <xsl:with-param name="nx" select=" $new-nx "/>
440 <xsl:with-param name="arctanx" select="$arctanx + $new-nx div (2 * $n +1) * $sign"/>
441 </xsl:call-template>
442 </xsl:otherwise>
443 </xsl:choose>
444 </xsl:template>
445 <xsl:template name="sqrt-private">
446 <xsl:param name="x"/>
447 <xsl:param name="rounding-factor" select="100"/>
448 <xsl:variable name="shift" select="string-length( $rounding-factor)"/>
449 <xsl:variable name="power">
450 <xsl:call-template name="power">
451 <xsl:with-param name="x" select="100"/>
452 <xsl:with-param name="y" select="$shift"/>
453 <xsl:with-param name="rounding-factor" select="1"/>
454 </xsl:call-template>
455 </xsl:variable>
456 <xsl:variable name="integer-x" select=" round( $power * $x )"/>
457 <xsl:variable name="integer-quotient">
458 <xsl:call-template name="integer-sqrt">
459 <xsl:with-param name="x" select="$integer-x"/>
460 <xsl:with-param name="length" select=" string-length( $integer-x ) "/>
461 <xsl:with-param name="curr-pos" select=" 2 - (round (string-length( $integer-x ) div 2 ) * 2 - string-length( $integer-x ) ) "/>
462 </xsl:call-template>
463 </xsl:variable>
464 <xsl:variable name="power-10">
465 <xsl:call-template name="power">
466 <xsl:with-param name="x" select="10"/>
467 <xsl:with-param name="y" select="$shift - 1"/>
468 <xsl:with-param name="rounding-factor" select="1"/>
469 </xsl:call-template>
470 </xsl:variable>
471 <xsl:value-of select=" round( $integer-quotient div 10) div $power-10 "/>
472 </xsl:template>
473 <xsl:template name="integer-sqrt">
474 <xsl:param name="x"/>
475 <xsl:param name="length"/>
476 <xsl:param name="curr-pos"/>
477 <xsl:param name="last-quotient" select="0"/>
478 <xsl:choose>
479 <xsl:when test="$curr-pos &gt; $length">
480 <xsl:value-of select="$last-quotient"/>
481 </xsl:when>
482 <xsl:otherwise>
483 <xsl:variable name="curr-x" select="substring( $x, 1, $curr-pos )"/>
484 <xsl:variable name="new-quotient">
485 <xsl:call-template name="get-one-sqrt-digit">
486 <xsl:with-param name="x" select="$curr-x"/>
487 <xsl:with-param name="last-quotient" select="$last-quotient"/>
488 <xsl:with-param name="n" select="5"/>
489 <xsl:with-param name="direct" select="0"/>
490 </xsl:call-template>
491 </xsl:variable>
492 <xsl:call-template name="integer-sqrt">
493 <xsl:with-param name="x" select="$x"/>
494 <xsl:with-param name="length" select="$length"/>
495 <xsl:with-param name="curr-pos" select="$curr-pos + 2"/>
496 <xsl:with-param name="last-quotient" select="number($new-quotient)"/>
497 </xsl:call-template>
498 </xsl:otherwise>
499 </xsl:choose>
500 </xsl:template>
501 <xsl:template name="get-one-sqrt-digit">
502 <xsl:param name="x"/>
503 <xsl:param name="last-quotient"/>
504 <xsl:param name="n"/>
505 <xsl:param name="direct" select="1"/>
506 <xsl:variable name="quotient" select=" concat( $last-quotient, $n) "/>
507 <xsl:variable name="accumulate" select="$quotient * $quotient "/>
508 <xsl:choose>
509 <xsl:when test="$accumulate = $x">
510 <xsl:value-of select="concat($last-quotient , $n )"/>
511 </xsl:when>
512 <xsl:when test="$direct = 0 and $accumulate &lt; $x">
513 <xsl:call-template name="get-one-sqrt-digit">
514 <xsl:with-param name="x" select="$x"/>
515 <xsl:with-param name="last-quotient" select="$last-quotient"/>
516 <xsl:with-param name="n" select="$n + 1"/>
517 <xsl:with-param name="direct" select="1"/>
518 </xsl:call-template>
519 </xsl:when>
520 <xsl:when test="$direct = 0 and $accumulate &gt; $x">
521 <xsl:call-template name="get-one-sqrt-digit">
522 <xsl:with-param name="x" select="$x"/>
523 <xsl:with-param name="last-quotient" select="$last-quotient"/>
524 <xsl:with-param name="n" select="$n - 1"/>
525 <xsl:with-param name="direct" select="-1"/>
526 </xsl:call-template>
527 </xsl:when>
528 <xsl:when test=" $accumulate * $direct &lt; $x * $direct ">
529 <xsl:call-template name="get-one-sqrt-digit">
530 <xsl:with-param name="x" select="$x"/>
531 <xsl:with-param name="last-quotient" select="$last-quotient"/>
532 <xsl:with-param name="n" select="$n+ $direct"/>
533 <xsl:with-param name="direct" select="$direct"/>
534 </xsl:call-template>
535 </xsl:when>
536 <xsl:when test="not($n &lt; 9) or $n = -1">
537 <xsl:value-of select="concat($last-quotient , $n - $direct) "/>
538 </xsl:when>
539 <xsl:when test="$direct = 1">
540 <xsl:value-of select="concat($last-quotient , $n - 1) "/>
541 </xsl:when>
542 <xsl:otherwise>
543 <xsl:value-of select="concat($last-quotient , $n) "/>
544 </xsl:otherwise>
545 </xsl:choose>
546 </xsl:template>
547 <xsl:template name="convert2redian">
548 <xsl:param name="x" select="'0'"/>
549 <xsl:param name="rounding-factor" select="100"/>
550 <xsl:choose>
551 <xsl:when test="contains($x,'deg')">
552 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'deg') div 180 * $pi)) div $rounding-factor"/>
553 </xsl:when>
554 <xsl:when test="contains($x,'fd')">
555 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd') div 180 div 65536 * $pi)) div $rounding-factor"/>
556 </xsl:when>
557 <xsl:otherwise>
558 <xsl:value-of select="round($rounding-factor * number($x) div 180 * $pi) div $rounding-factor"/>
559 </xsl:otherwise>
560 </xsl:choose>
561 </xsl:template>
562 <xsl:template name="convert2degree">
563 <xsl:param name="x" select="'0'"/>
564 <xsl:param name="rounding-factor" select="100"/>
565 <xsl:choose>
566 <xsl:when test="contains($x,'deg')">
567 <xsl:value-of select="round($rounding-factor * substring-before($x,'deg')) div $rounding-factor"/>
568 </xsl:when>
569 <xsl:when test="contains($x,'fd')">
570 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd')) div 65536 ) div $rounding-factor"/>
571 </xsl:when>
572 <xsl:otherwise>
573 <xsl:value-of select="round($rounding-factor * number($x) * 180 div $pi) div $rounding-factor"/>
574 </xsl:otherwise>
575 </xsl:choose>
576 </xsl:template>
577 <xsl:template name="convert2fd">
578 <xsl:param name="x" select="'0'"/>
579 <xsl:param name="rounding-factor" select="100"/>
580 <xsl:choose>
581 <xsl:when test="contains($x,'deg')">
582 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'deg') * 65535)) div $rounding-factor"/>
583 </xsl:when>
584 <xsl:when test="contains($x,'fd')">
585 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd'))) div $rounding-factor"/>
586 </xsl:when>
587 <xsl:otherwise>
588 <xsl:value-of select="round($rounding-factor * number($x) * 180 div $pi * 65535) div $rounding-factor"/>
589 </xsl:otherwise>
590 </xsl:choose>
591 </xsl:template>
593 </xsl:stylesheet>