Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

math.xsl 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
  5. xmlns:math="http://xsltsl.org/math"
  6. exclude-result-prefixes="doc math">
  7. <doc:reference xmlns="">
  8. <referenceinfo>
  9. <releaseinfo role="meta">
  10. $Id: math.xsl,v 1.4 2004/10/08 06:37:25 balls Exp $
  11. </releaseinfo>
  12. <author>
  13. <surname>Ball</surname>
  14. <firstname>Steve</firstname>
  15. </author>
  16. <copyright>
  17. <year>2004</year>
  18. <year>2002</year>
  19. <holder>Steve Ball</holder>
  20. </copyright>
  21. </referenceinfo>
  22. <title>Math Module</title>
  23. <partintro>
  24. <section>
  25. <title>Introduction</title>
  26. <para>This module provides mathematical functions.</para>
  27. </section>
  28. </partintro>
  29. </doc:reference>
  30. <doc:template name="math:power" xmlns="">
  31. <refpurpose>Power</refpurpose>
  32. <refdescription>
  33. <para>Raises a number to a power.</para>
  34. </refdescription>
  35. <refparameter>
  36. <variablelist>
  37. <varlistentry>
  38. <term>base</term>
  39. <listitem>
  40. <para>The base number. Must be a number.</para>
  41. </listitem>
  42. </varlistentry>
  43. <varlistentry>
  44. <term>power</term>
  45. <listitem>
  46. <para>The power to raise the number to. Must be an integer.</para>
  47. </listitem>
  48. </varlistentry>
  49. </variablelist>
  50. </refparameter>
  51. <refreturn>
  52. <para>Returns base multiplied by itself power times. If the base or power are not numbers or if the power is fractional then an empty string is returned.</para>
  53. </refreturn>
  54. </doc:template>
  55. <xsl:template name="math:power">
  56. <xsl:param name="base"/>
  57. <xsl:param name="power"/>
  58. <xsl:choose>
  59. <xsl:when test='$power = "0" and $base = "0"'>
  60. <xsl:text>1</xsl:text>
  61. </xsl:when>
  62. <xsl:when test='$power = "0" and number($base)'>
  63. <xsl:text>1</xsl:text>
  64. </xsl:when>
  65. <xsl:when test='$power = "0" and not(number($base))'/>
  66. <xsl:when test='$base = "0" and number($power)'>
  67. <xsl:text>0</xsl:text>
  68. </xsl:when>
  69. <xsl:when test='not(number($base)) or not(number($power))'/>
  70. <xsl:when test='floor(number($power)) != number($power)'/>
  71. <xsl:when test='number($power) &lt; 0'>
  72. <xsl:variable name='x'>
  73. <xsl:call-template name='math:power'>
  74. <xsl:with-param name='base' select='$base'/>
  75. <xsl:with-param name='power' select='-1 * $power'/>
  76. </xsl:call-template>
  77. </xsl:variable>
  78. <xsl:value-of select='1 div $x'/>
  79. </xsl:when>
  80. <xsl:when test='number($power) = 1'>
  81. <xsl:value-of select='$base'/>
  82. </xsl:when>
  83. <xsl:when test='number($power) &gt; 0'>
  84. <xsl:variable name='x'>
  85. <xsl:call-template name='math:power'>
  86. <xsl:with-param name='base' select='$base'/>
  87. <xsl:with-param name='power' select='$power - 1'/>
  88. </xsl:call-template>
  89. </xsl:variable>
  90. <xsl:value-of select='$base * $x'/>
  91. </xsl:when>
  92. <xsl:otherwise/>
  93. </xsl:choose>
  94. </xsl:template>
  95. <doc:template name="math:cvt-hex-decimal" xmlns="">
  96. <refpurpose>Conversion</refpurpose>
  97. <refdescription>
  98. <para>Converts a hexidecimal value to a decimal value.</para>
  99. </refdescription>
  100. <refparameter>
  101. <variablelist>
  102. <varlistentry>
  103. <term>value</term>
  104. <listitem>
  105. <para>The hexidecimal number. Must be a number in hexidecimal format.</para>
  106. </listitem>
  107. </varlistentry>
  108. </variablelist>
  109. </refparameter>
  110. <refreturn>
  111. <para>Returns the value as a decimal string. If the value is not a number then a NaN value is returned.</para>
  112. </refreturn>
  113. </doc:template>
  114. <xsl:template name="math:cvt-hex-decimal">
  115. <xsl:param name="value"/>
  116. <xsl:choose>
  117. <xsl:when test='$value = ""'/>
  118. <xsl:when test='string-length($value) = 1'>
  119. <xsl:call-template name='math:cvt-hex-decimal-digit'>
  120. <xsl:with-param name='digit' select='$value'/>
  121. </xsl:call-template>
  122. </xsl:when>
  123. <xsl:otherwise>
  124. <xsl:variable name='first-digit'>
  125. <xsl:call-template name='math:cvt-hex-decimal-digit'>
  126. <xsl:with-param name='digit' select='substring($value, 1, 1)'/>
  127. </xsl:call-template>
  128. </xsl:variable>
  129. <xsl:variable name='remainder'>
  130. <xsl:call-template name='math:cvt-hex-decimal'>
  131. <xsl:with-param name='value' select='substring($value, 2)'/>
  132. </xsl:call-template>
  133. </xsl:variable>
  134. <xsl:value-of select='$first-digit * 16 + $remainder'/>
  135. </xsl:otherwise>
  136. </xsl:choose>
  137. </xsl:template>
  138. <xsl:template name='math:cvt-hex-decimal-digit'>
  139. <xsl:param name='digit' select='0'/>
  140. <xsl:choose>
  141. <xsl:when test='$digit &lt;= 9'>
  142. <xsl:value-of select='$digit'/>
  143. </xsl:when>
  144. <xsl:when test='$digit = "a" or $digit = "A"'>10</xsl:when>
  145. <xsl:when test='$digit = "b" or $digit = "B"'>11</xsl:when>
  146. <xsl:when test='$digit = "c" or $digit = "C"'>12</xsl:when>
  147. <xsl:when test='$digit = "d" or $digit = "D"'>13</xsl:when>
  148. <xsl:when test='$digit = "e" or $digit = "E"'>14</xsl:when>
  149. <xsl:when test='$digit = "f" or $digit = "F"'>15</xsl:when>
  150. </xsl:choose>
  151. </xsl:template>
  152. <doc:template name="math:ordinal" xmlns="">
  153. <refpurpose>Ordinal number</refpurpose>
  154. <refdescription>
  155. <para>Gives the ordinal number of a given counting number. For example, 1 becomes "1st".</para>
  156. </refdescription>
  157. <refparameter>
  158. <variablelist>
  159. <varlistentry>
  160. <term>number</term>
  161. <listitem>
  162. <para>An integer number.</para>
  163. </listitem>
  164. </varlistentry>
  165. </variablelist>
  166. </refparameter>
  167. <refreturn>
  168. <para>Returns the number with an ordinal suffix.</para>
  169. </refreturn>
  170. </doc:template>
  171. <xsl:template name="math:ordinal">
  172. <xsl:param name="number"/>
  173. <xsl:choose>
  174. <xsl:when test='$number &lt; 0'/>
  175. <xsl:otherwise>
  176. <xsl:value-of select='$number'/>
  177. <xsl:choose>
  178. <xsl:when test='$number = 11 or $number = 12 or $number = 13'>th</xsl:when>
  179. <xsl:when test='$number mod 10 = 1'>st</xsl:when>
  180. <xsl:when test='$number mod 10 = 2'>nd</xsl:when>
  181. <xsl:when test='$number mod 10 = 3'>rd</xsl:when>
  182. <xsl:otherwise>th</xsl:otherwise>
  183. </xsl:choose>
  184. </xsl:otherwise>
  185. </xsl:choose>
  186. </xsl:template>
  187. <doc:template name="math:ordinal-as-word" xmlns="">
  188. <refpurpose>Returns an ordinal number</refpurpose>
  189. <refdescription>
  190. <para>This template returns the ordinal number for a given counting number as a word. For example "first" for 1.</para>
  191. <para>Only handles numbers less than 10000000 (ten million).</para>
  192. </refdescription>
  193. <refparameter>
  194. <variablelist>
  195. <varlistentry>
  196. <term>number</term>
  197. <listitem>
  198. <para>The counting number.</para>
  199. </listitem>
  200. </varlistentry>
  201. <varlistentry>
  202. <term>conjunctive</term>
  203. <listitem>
  204. <para>Whether to add the word "and" to the result, for example "one hundred and first" rather than "one hundred first". Default is "yes".</para>
  205. </listitem>
  206. </varlistentry>
  207. </variablelist>
  208. </refparameter>
  209. <refreturn>
  210. <para>Returns the ordinal number as a string.</para>
  211. </refreturn>
  212. </doc:template>
  213. <xsl:template name="math:ordinal-as-word">
  214. <xsl:param name="number" select="0"/>
  215. <xsl:param name='conjunctive' select='"yes"'/>
  216. <xsl:param name='preceding' select='0'/>
  217. <xsl:choose>
  218. <xsl:when test='$preceding = 1 and $number = 0'/>
  219. <xsl:when test='$number = 0'>zeroth</xsl:when>
  220. <xsl:when test="$number &lt; 1 or $number != floor($number)"/>
  221. <xsl:when test='$number = 1'>
  222. <xsl:if test='$preceding = 1'> and </xsl:if>
  223. <xsl:text>first</xsl:text>
  224. </xsl:when>
  225. <xsl:when test='$number = 2'>
  226. <xsl:if test='$preceding = 1'> and </xsl:if>
  227. <xsl:text>second</xsl:text>
  228. </xsl:when>
  229. <xsl:when test='$number = 3'>
  230. <xsl:if test='$preceding = 1'> and </xsl:if>
  231. <xsl:text>third</xsl:text>
  232. </xsl:when>
  233. <xsl:when test='$number = 4'>
  234. <xsl:if test='$preceding = 1'> and </xsl:if>
  235. <xsl:text>fourth</xsl:text>
  236. </xsl:when>
  237. <xsl:when test='$number = 5'>
  238. <xsl:if test='$preceding = 1'> and </xsl:if>
  239. <xsl:text>fifth</xsl:text>
  240. </xsl:when>
  241. <xsl:when test='$number = 6'>
  242. <xsl:if test='$preceding = 1'> and </xsl:if>
  243. <xsl:text>sixth</xsl:text>
  244. </xsl:when>
  245. <xsl:when test='$number = 7'>
  246. <xsl:if test='$preceding = 1'> and </xsl:if>
  247. <xsl:text>seventh</xsl:text>
  248. </xsl:when>
  249. <xsl:when test='$number = 8'>
  250. <xsl:if test='$preceding = 1'> and </xsl:if>
  251. <xsl:text>eighth</xsl:text>
  252. </xsl:when>
  253. <xsl:when test='$number = 9'>
  254. <xsl:if test='$preceding = 1'> and </xsl:if>
  255. <xsl:text>ninth</xsl:text>
  256. </xsl:when>
  257. <xsl:when test='$number = 10'>
  258. <xsl:if test='$preceding = 1'> and </xsl:if>
  259. <xsl:text>tenth</xsl:text>
  260. </xsl:when>
  261. <xsl:when test='$number = 11'>
  262. <xsl:if test='$preceding = 1'> and </xsl:if>
  263. <xsl:text>eleventh</xsl:text>
  264. </xsl:when>
  265. <xsl:when test='$number = 12'>
  266. <xsl:if test='$preceding = 1'> and </xsl:if>
  267. <xsl:text>twelveth</xsl:text>
  268. </xsl:when>
  269. <xsl:when test='$number = 13'>
  270. <xsl:if test='$preceding = 1'> and </xsl:if>
  271. <xsl:text>thirteenth</xsl:text>
  272. </xsl:when>
  273. <xsl:when test='$number = 14'>
  274. <xsl:if test='$preceding = 1'> and </xsl:if>
  275. <xsl:text>fourteenth</xsl:text>
  276. </xsl:when>
  277. <xsl:when test='$number = 15'>
  278. <xsl:if test='$preceding = 1'> and </xsl:if>
  279. <xsl:text>fifteenth</xsl:text>
  280. </xsl:when>
  281. <xsl:when test='$number = 16'>
  282. <xsl:if test='$preceding = 1'> and </xsl:if>
  283. <xsl:text>sixteenth</xsl:text>
  284. </xsl:when>
  285. <xsl:when test='$number = 17'>
  286. <xsl:if test='$preceding = 1'> and </xsl:if>
  287. <xsl:text>seventeenth</xsl:text>
  288. </xsl:when>
  289. <xsl:when test='$number = 18'>
  290. <xsl:if test='$preceding = 1'> and </xsl:if>
  291. <xsl:text>eighteenth</xsl:text>
  292. </xsl:when>
  293. <xsl:when test='$number = 19'>
  294. <xsl:if test='$preceding = 1'> and </xsl:if>
  295. <xsl:text>nineteenth</xsl:text>
  296. </xsl:when>
  297. <xsl:when test='$number = 20'>
  298. <xsl:if test='$preceding = 1'> and </xsl:if>
  299. <xsl:text>twentieth</xsl:text>
  300. </xsl:when>
  301. <xsl:when test='$number = 30'>
  302. <xsl:if test='$preceding = 1'> and </xsl:if>
  303. <xsl:text>thirtieth</xsl:text>
  304. </xsl:when>
  305. <xsl:when test='$number = 40'>
  306. <xsl:if test='$preceding = 1'> and </xsl:if>
  307. <xsl:text>fortieth</xsl:text>
  308. </xsl:when>
  309. <xsl:when test='$number = 50'>
  310. <xsl:if test='$preceding = 1'> and </xsl:if>
  311. <xsl:text>fiftieth</xsl:text>
  312. </xsl:when>
  313. <xsl:when test='$number = 60'>
  314. <xsl:if test='$preceding = 1'> and </xsl:if>
  315. <xsl:text>sixtieth</xsl:text>
  316. </xsl:when>
  317. <xsl:when test='$number = 70'>
  318. <xsl:if test='$preceding = 1'> and </xsl:if>
  319. <xsl:text>seventieth</xsl:text>
  320. </xsl:when>
  321. <xsl:when test='$number = 80'>
  322. <xsl:if test='$preceding = 1'> and </xsl:if>
  323. <xsl:text>eightieth</xsl:text>
  324. </xsl:when>
  325. <xsl:when test='$number = 90'>
  326. <xsl:if test='$preceding = 1'> and </xsl:if>
  327. <xsl:text>ninetieth</xsl:text>
  328. </xsl:when>
  329. <xsl:when test='$number mod 1000000 = 0'>
  330. <xsl:call-template name='math:number-as-word'>
  331. <xsl:with-param name='number' select='floor($number div 1000000)'/>
  332. </xsl:call-template>
  333. <xsl:text> millionth</xsl:text>
  334. </xsl:when>
  335. <xsl:when test='$number &lt; 1000000 and $number mod 1000 = 0'>
  336. <xsl:if test='$preceding = 1 and $conjunctive'> and </xsl:if>
  337. <xsl:call-template name='math:number-as-word'>
  338. <xsl:with-param name='number' select='floor($number div 1000)'/>
  339. </xsl:call-template>
  340. <xsl:text> thousandth</xsl:text>
  341. </xsl:when>
  342. <xsl:when test='$number &lt; 1000 and $number mod 100 = 0'>
  343. <xsl:if test='$preceding = 1 and $conjunctive'> and </xsl:if>
  344. <xsl:call-template name='math:number-as-word'>
  345. <xsl:with-param name='number' select='floor($number div 100)'/>
  346. </xsl:call-template>
  347. <xsl:text> hundredth</xsl:text>
  348. </xsl:when>
  349. <xsl:when test='$number &gt; 1000000'>
  350. <xsl:if test='$preceding = 1'>
  351. <xsl:text> </xsl:text>
  352. <xsl:if test='$conjunctive'>and </xsl:if>
  353. </xsl:if>
  354. <xsl:call-template name='math:number-as-word'>
  355. <xsl:with-param name='number' select='floor($number div 1000000) * 1000000'/>
  356. </xsl:call-template>
  357. <xsl:choose>
  358. <xsl:when
  359. test='(floor(floor(($number mod 1000000) + 0.1) div 100000) > 0 and $number mod 100000 > 0) or
  360. (floor(floor(($number mod 100000) + 0.1) div 10000) > 0 and $number mod 10000 > 0) or
  361. (floor(floor(($number mod 10000) + 0.1) div 1000) > 0 and $number mod 1000 > 0) or
  362. (floor(floor(($number mod 1000) + 0.1) div 100) > 0 and $number mod 100 > 0) or
  363. (floor(floor(($number mod 100) + 0.1) div 10) > 0 and $number mod 10 > 0 and $number mod 100 > 20)'>
  364. <xsl:text> </xsl:text>
  365. <xsl:call-template name='math:ordinal-as-word'>
  366. <xsl:with-param name='number' select='floor(($number mod 1000000) + 0.1)'/>
  367. <xsl:with-param name='conjunctive' select='$conjunctive'/>
  368. <xsl:with-param name='preceding' select='0'/>
  369. </xsl:call-template>
  370. </xsl:when>
  371. <xsl:otherwise>
  372. <xsl:call-template name='math:ordinal-as-word'>
  373. <xsl:with-param name='number' select='floor(($number mod 1000000) + 0.1)'/>
  374. <xsl:with-param name='conjunctive' select='$conjunctive'/>
  375. <xsl:with-param name='preceding' select='1'/>
  376. </xsl:call-template>
  377. </xsl:otherwise>
  378. </xsl:choose>
  379. </xsl:when>
  380. <xsl:when test='$number &gt; 1000'>
  381. <xsl:if test='$preceding = 1'>
  382. <xsl:text> </xsl:text>
  383. <xsl:if test='$conjunctive'>and </xsl:if>
  384. </xsl:if>
  385. <xsl:call-template name='math:number-as-word'>
  386. <xsl:with-param name='number' select='floor($number div 1000) * 1000'/>
  387. <xsl:with-param name='conjunctive' select='$conjunctive'/>
  388. </xsl:call-template>
  389. <xsl:choose>
  390. <xsl:when test='floor(floor(($number mod 1000) + 0.1) div 100) > 0'>
  391. <xsl:text> </xsl:text>
  392. <xsl:call-template name='math:ordinal-as-word'>
  393. <xsl:with-param name='number' select='floor(($number mod 1000) + 0.1)'/>
  394. <xsl:with-param name='conjunctive' select='$conjunctive'/>
  395. <xsl:with-param name='preceding' select='0'/>
  396. </xsl:call-template>
  397. </xsl:when>
  398. <xsl:otherwise>
  399. <xsl:call-template name='math:ordinal-as-word'>
  400. <xsl:with-param name='number' select='floor(($number mod 1000) + 0.1)'/>
  401. <xsl:with-param name='conjunctive' select='$conjunctive'/>
  402. <xsl:with-param name='preceding' select='1'/>
  403. </xsl:call-template>
  404. </xsl:otherwise>
  405. </xsl:choose>
  406. </xsl:when>
  407. <xsl:when test='$number &gt; 100'>
  408. <xsl:if test='$preceding = 1'>
  409. <xsl:text> </xsl:text>
  410. <xsl:if test='$conjunctive'>and </xsl:if>
  411. </xsl:if>
  412. <xsl:call-template name='math:number-as-word'>
  413. <xsl:with-param name='number' select='floor($number div 100) * 100'/>
  414. </xsl:call-template>
  415. <xsl:call-template name='math:ordinal-as-word'>
  416. <xsl:with-param name='number' select='floor(($number mod 100) + 0.1)'/>
  417. <xsl:with-param name='conjunctive' select='$conjunctive'/>
  418. <xsl:with-param name='preceding' select='1'/>
  419. </xsl:call-template>
  420. </xsl:when>
  421. <xsl:when test='$number &gt; 20'>
  422. <xsl:if test='$preceding = 1'>
  423. <xsl:text> </xsl:text>
  424. <xsl:if test='$conjunctive'>and </xsl:if>
  425. </xsl:if>
  426. <xsl:call-template name='math:number-as-word'>
  427. <xsl:with-param name='number' select='floor($number div 10) * 10'/>
  428. </xsl:call-template>
  429. <xsl:text> </xsl:text>
  430. <xsl:call-template name='math:ordinal-as-word'>
  431. <xsl:with-param name='number' select='floor(($number mod 10) + 0.1)'/>
  432. <xsl:with-param name='conjunctive' select='$conjunctive'/>
  433. </xsl:call-template>
  434. </xsl:when>
  435. <xsl:otherwise/>
  436. </xsl:choose>
  437. </xsl:template>
  438. <doc:template name="math:number-as-word" xmlns="">
  439. <refpurpose>Returns a number as a word</refpurpose>
  440. <refdescription>
  441. <para>This template returns the word for a given integer number, for example "one" for 1.</para>
  442. <para>Only handles numbers less than 10000000 (ten million).</para>
  443. </refdescription>
  444. <refparameter>
  445. <variablelist>
  446. <varlistentry>
  447. <term>number</term>
  448. <listitem>
  449. <para>The counting number.</para>
  450. </listitem>
  451. </varlistentry>
  452. <varlistentry>
  453. <term>conjunctive</term>
  454. <listitem>
  455. <para>Adds the word "and" where appropriate, for example.</para>
  456. </listitem>
  457. </varlistentry>
  458. </variablelist>
  459. </refparameter>
  460. <refreturn>
  461. <para>Returns the number as a string.</para>
  462. </refreturn>
  463. </doc:template>
  464. <xsl:template name="math:number-as-word">
  465. <xsl:param name="number" select="0"/>
  466. <xsl:param name='conjunctive' select='true()'/>
  467. <xsl:choose>
  468. <xsl:when test='$number = 0'>zero</xsl:when>
  469. <xsl:when test='$number &lt; 0'>
  470. <xsl:text>minus </xsl:text>
  471. <xsl:call-template name='math:number-as-word'>
  472. <xsl:with-param name='number' select='-1 * $number'/>
  473. </xsl:call-template>
  474. </xsl:when>
  475. <xsl:when test="$number != floor($number)"/>
  476. <xsl:when test='$number mod 1000000 = 0'>
  477. <xsl:call-template name='math:number-as-word'>
  478. <xsl:with-param name='number' select='floor($number div 1000000)'/>
  479. </xsl:call-template>
  480. <xsl:text> million</xsl:text>
  481. </xsl:when>
  482. <xsl:when test='$number &gt;= 1000000'>
  483. <xsl:call-template name='math:number-as-word'>
  484. <xsl:with-param name='number' select='floor($number div 1000000)'/>
  485. </xsl:call-template>
  486. <xsl:text> million </xsl:text>
  487. <xsl:call-template name='math:number-as-word'>
  488. <xsl:with-param name='number' select='floor(($number mod 1000000) + 0.1)'/>
  489. </xsl:call-template>
  490. </xsl:when>
  491. <xsl:when test='$number mod 1000 = 0'>
  492. <xsl:call-template name='math:number-as-word'>
  493. <xsl:with-param name='number' select='floor($number div 1000)'/>
  494. </xsl:call-template>
  495. <xsl:text> thousand</xsl:text>
  496. </xsl:when>
  497. <xsl:when test='$number &gt;= 1000'>
  498. <xsl:call-template name='math:number-as-word'>
  499. <xsl:with-param name='number' select='floor($number div 1000)'/>
  500. </xsl:call-template>
  501. <xsl:text> thousand </xsl:text>
  502. <xsl:if test='$conjunctive and floor(floor(($number mod 1000) + 0.1) div 100) = 0'>and </xsl:if>
  503. <xsl:call-template name='math:number-as-word'>
  504. <xsl:with-param name='number' select='floor(($number mod 1000) + 0.1)'/>
  505. </xsl:call-template>
  506. </xsl:when>
  507. <xsl:when test='$number mod 100 = 0'>
  508. <xsl:call-template name='math:number-as-word'>
  509. <xsl:with-param name='number' select='floor($number div 100)'/>
  510. </xsl:call-template>
  511. <xsl:text> hundred</xsl:text>
  512. </xsl:when>
  513. <xsl:when test='$number &gt;= 100'>
  514. <xsl:call-template name='math:number-as-word'>
  515. <xsl:with-param name='number' select='floor($number div 100)'/>
  516. </xsl:call-template>
  517. <xsl:text> hundred </xsl:text>
  518. <xsl:if test='$conjunctive'>and </xsl:if>
  519. <xsl:call-template name='math:number-as-word'>
  520. <xsl:with-param name='number' select='floor(($number mod 100) + 0.1)'/>
  521. </xsl:call-template>
  522. </xsl:when>
  523. <xsl:when test='$number = 1'>one</xsl:when>
  524. <xsl:when test='$number = 2'>two</xsl:when>
  525. <xsl:when test='$number = 3'>three</xsl:when>
  526. <xsl:when test='$number = 4'>four</xsl:when>
  527. <xsl:when test='$number = 5'>five</xsl:when>
  528. <xsl:when test='$number = 6'>six</xsl:when>
  529. <xsl:when test='$number = 7'>seven</xsl:when>
  530. <xsl:when test='$number = 8'>eight</xsl:when>
  531. <xsl:when test='$number = 9'>nine</xsl:when>
  532. <xsl:when test='$number = 10'>ten</xsl:when>
  533. <xsl:when test='$number = 11'>eleven</xsl:when>
  534. <xsl:when test='$number = 12'>twelve</xsl:when>
  535. <xsl:when test='$number = 13'>thirteen</xsl:when>
  536. <xsl:when test='$number = 14'>fourteen</xsl:when>
  537. <xsl:when test='$number = 15'>fifteen</xsl:when>
  538. <xsl:when test='$number = 16'>sixteen</xsl:when>
  539. <xsl:when test='$number = 17'>seventeen</xsl:when>
  540. <xsl:when test='$number = 18'>eighteen</xsl:when>
  541. <xsl:when test='$number = 19'>nineteen</xsl:when>
  542. <xsl:when test='$number = 20'>twenty</xsl:when>
  543. <xsl:when test='$number = 30'>thirty</xsl:when>
  544. <xsl:when test='$number = 40'>forty</xsl:when>
  545. <xsl:when test='$number = 50'>fifty</xsl:when>
  546. <xsl:when test='$number = 60'>sixty</xsl:when>
  547. <xsl:when test='$number = 70'>seventy</xsl:when>
  548. <xsl:when test='$number = 80'>eighty</xsl:when>
  549. <xsl:when test='$number = 90'>ninety</xsl:when>
  550. <xsl:when test='$number &lt; 100'>
  551. <xsl:call-template name='math:number-as-word'>
  552. <xsl:with-param name='number' select='floor($number div 10) * 10'/>
  553. </xsl:call-template>
  554. <xsl:text> </xsl:text>
  555. <xsl:call-template name='math:number-as-word'>
  556. <xsl:with-param name='number' select='floor(($number mod 10) + 0.1)'/>
  557. </xsl:call-template>
  558. </xsl:when>
  559. </xsl:choose>
  560. </xsl:template>
  561. </xsl:stylesheet>