| 1 |
<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- --> |
| 2 |
<!-- |
| 3 |
This program is free software; you can redistribute it and/or modify it under |
| 4 |
the terms of the GNU Lesser General Public License as published by the Free |
| 5 |
Software Foundation; either version 2 of the License, or (at your option) any |
| 6 |
later version. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 10 |
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 11 |
details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU Lesser General Public License |
| 14 |
along with this program; see the file COPYING.LGPL. If not, see |
| 15 |
<http://www.gnu.org/licenses/>. |
| 16 |
--> |
| 17 |
|
| 18 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 19 |
xmlns:math="http://exslt.org/math" |
| 20 |
extension-element-prefixes="math" |
| 21 |
version="1.0"> |
| 22 |
|
| 23 |
<!--!!========================================================================== |
| 24 |
Localized Numbers |
| 25 |
--> |
| 26 |
|
| 27 |
|
| 28 |
<!--**========================================================================== |
| 29 |
l10n.number |
| 30 |
Formats a number according to a localized numbering system |
| 31 |
|
| 32 |
[xsl:params] |
| 33 |
$value: The numeric value of the number to format |
| 34 |
$format: The numbering system to use |
| 35 |
|
| 36 |
REMARK: Talk about numbering systems |
| 37 |
--> |
| 38 |
<xsl:template name="l10n.number"> |
| 39 |
<xsl:param name="value"/> |
| 40 |
<xsl:param name="format"/> |
| 41 |
<xsl:choose> |
| 42 |
<xsl:when test="$format='decimal' or $format='1'"> |
| 43 |
<xsl:number format="1" value="$value"/> |
| 44 |
</xsl:when> |
| 45 |
<xsl:when test="$format='alpha-lower' or $format='a'"> |
| 46 |
<xsl:number format="a" value="$value"/> |
| 47 |
</xsl:when> |
| 48 |
<xsl:when test="$format='alpha-upper' or $format='A'"> |
| 49 |
<xsl:number format="A" value="$value"/> |
| 50 |
</xsl:when> |
| 51 |
<xsl:when test="$format='roman-lower' or $format='i'"> |
| 52 |
<xsl:number format="i" value="$value"/> |
| 53 |
</xsl:when> |
| 54 |
<xsl:when test="$format='roman-upper' or $format='I'"> |
| 55 |
<xsl:number format="I" value="$value"/> |
| 56 |
</xsl:when> |
| 57 |
|
| 58 |
<xsl:when test="$format='cjk-japanese' or |
| 59 |
$format='cjk-chinese-simp' or |
| 60 |
$format='cjk-chinese-trad' "> |
| 61 |
<xsl:call-template name="l10n.number.cjk-ideographic"> |
| 62 |
<xsl:with-param name="value" select="$value"/> |
| 63 |
<xsl:with-param name="format" select="$format"/> |
| 64 |
</xsl:call-template> |
| 65 |
</xsl:when> |
| 66 |
|
| 67 |
<xsl:when test="$format='ionic-lower' or $format='ionic-upper'"> |
| 68 |
<xsl:call-template name="l10n.number.ionic"> |
| 69 |
<xsl:with-param name="value" select="$value"/> |
| 70 |
<xsl:with-param name="format" select="$format"/> |
| 71 |
</xsl:call-template> |
| 72 |
</xsl:when> |
| 73 |
|
| 74 |
<xsl:when test="$format='decimal-arabic'"> |
| 75 |
<xsl:call-template name="l10n.number.numeric"> |
| 76 |
<xsl:with-param name="value" select="$value"/> |
| 77 |
<xsl:with-param name="digits" select="'٠١٢٣٤٥٦٧٨٩'"/> |
| 78 |
</xsl:call-template> |
| 79 |
</xsl:when> |
| 80 |
<xsl:when test="$format='decimal-persian'"> |
| 81 |
<xsl:call-template name="l10n.number.numeric"> |
| 82 |
<xsl:with-param name="value" select="$value"/> |
| 83 |
<xsl:with-param name="digits" select="'۰۱۲۳۴۵۶۷۸۹'"/> |
| 84 |
</xsl:call-template> |
| 85 |
</xsl:when> |
| 86 |
|
| 87 |
<xsl:when test="$format='alpha-serbian-lower'"> |
| 88 |
<xsl:call-template name="l10n.number.alphabetic"> |
| 89 |
<xsl:with-param name="value" select="$value"/> |
| 90 |
<xsl:with-param name="alphabet" |
| 91 |
select="'абвгдђежзијклљмнњопрстћуфхцчџш'"/> |
| 92 |
</xsl:call-template> |
| 93 |
</xsl:when> |
| 94 |
<xsl:when test="$format='alpha-serbian-upper'"> |
| 95 |
<xsl:call-template name="l10n.number.alphabetic"> |
| 96 |
<xsl:with-param name="value" select="$value"/> |
| 97 |
<xsl:with-param name="alphabet" |
| 98 |
select="'АБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШ'"/> |
| 99 |
</xsl:call-template> |
| 100 |
</xsl:when> |
| 101 |
|
| 102 |
<xsl:when test="$format='alpha-thai'"> |
| 103 |
<xsl:call-template name="l10n.number.alphabetic"> |
| 104 |
<xsl:with-param name="value" select="$value"/> |
| 105 |
<xsl:with-param name="alphabet" |
| 106 |
select="'กขคงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮ'"/> |
| 107 |
</xsl:call-template> |
| 108 |
</xsl:when> |
| 109 |
<xsl:when test="$format='decimal-thai'"> |
| 110 |
<xsl:call-template name="l10n.number.numeric"> |
| 111 |
<xsl:with-param name="value" select="$value"/> |
| 112 |
<xsl:with-param name="digits" select="'๐๑๒๓๔๕๖๗๘๙'"/> |
| 113 |
</xsl:call-template> |
| 114 |
</xsl:when> |
| 115 |
</xsl:choose> |
| 116 |
</xsl:template> |
| 117 |
|
| 118 |
|
| 119 |
<!--**========================================================================== |
| 120 |
l10n.number.alphabetic |
| 121 |
Formats a number using an alphabetic numbering system |
| 122 |
|
| 123 |
[xsl:params] |
| 124 |
$value: The numeric value of the number to format |
| 125 |
$alphabet: A string containing the characters of the alphabet to use |
| 126 |
|
| 127 |
REMARK: Talk about alphabetic numbering systems |
| 128 |
--> |
| 129 |
<xsl:template name="l10n.number.alphabetic"> |
| 130 |
<xsl:param name="value"/> |
| 131 |
<xsl:param name="alphabet"/> |
| 132 |
<xsl:variable name="length" select="string-length($alphabet)"/> |
| 133 |
<xsl:choose> |
| 134 |
<xsl:when test="$value <= 0"> |
| 135 |
<xsl:number format="1" value="$value"/> |
| 136 |
</xsl:when> |
| 137 |
<xsl:otherwise> |
| 138 |
<xsl:variable name="digit"> |
| 139 |
<xsl:choose> |
| 140 |
<xsl:when test="$value mod $length = 0"> |
| 141 |
<xsl:value-of select="$length"/> |
| 142 |
</xsl:when> |
| 143 |
<xsl:otherwise> |
| 144 |
<xsl:value-of select="$value mod $length"/> |
| 145 |
</xsl:otherwise> |
| 146 |
</xsl:choose> |
| 147 |
</xsl:variable> |
| 148 |
<xsl:if test="$value - $digit != 0"> |
| 149 |
<xsl:call-template name="l10n.number.alphabetic"> |
| 150 |
<xsl:with-param name="value" select="($value - $digit) div $length"/> |
| 151 |
<xsl:with-param name="alphabet" select="$alphabet"/> |
| 152 |
</xsl:call-template> |
| 153 |
</xsl:if> |
| 154 |
<xsl:value-of select="substring($alphabet, $digit, 1)"/> |
| 155 |
</xsl:otherwise> |
| 156 |
</xsl:choose> |
| 157 |
</xsl:template> |
| 158 |
|
| 159 |
|
| 160 |
<!--**========================================================================== |
| 161 |
l10n.number.numeric |
| 162 |
Formats a number using a numeric numbering system with any radix |
| 163 |
|
| 164 |
[xsl:params] |
| 165 |
$value: The numeric value of the number to format |
| 166 |
$digits: A string containing the digits to use, starting with zero |
| 167 |
|
| 168 |
REMARK: Talk about numeric numbering systems |
| 169 |
--> |
| 170 |
<xsl:template name="l10n.number.numeric"> |
| 171 |
<xsl:param name="value"/> |
| 172 |
<xsl:param name="digits"/> |
| 173 |
<xsl:param name="length" select="string-length($digits)"/> |
| 174 |
<xsl:choose> |
| 175 |
<xsl:when test="$value < 0"> |
| 176 |
<!-- FIXME: We need to localize the negative sign --> |
| 177 |
<xsl:text>-</xsl:text> |
| 178 |
<xsl:call-template name="l10n.number.numeric"> |
| 179 |
<xsl:with-param name="value" select="math:abs($value)"/> |
| 180 |
<xsl:with-param name="digits" select="$digits"/> |
| 181 |
</xsl:call-template> |
| 182 |
</xsl:when> |
| 183 |
<xsl:otherwise> |
| 184 |
<xsl:variable name="digit" select="$value mod $length"/> |
| 185 |
<xsl:if test="$value - $digit != 0"> |
| 186 |
<xsl:call-template name="l10n.number.numeric"> |
| 187 |
<xsl:with-param name="value" select="($value - $digit) div $length"/> |
| 188 |
<xsl:with-param name="digits" select="$digits"/> |
| 189 |
</xsl:call-template> |
| 190 |
</xsl:if> |
| 191 |
<xsl:value-of select="substring($digits, $digit + 1, 1)"/> |
| 192 |
</xsl:otherwise> |
| 193 |
</xsl:choose> |
| 194 |
</xsl:template> |
| 195 |
|
| 196 |
|
| 197 |
<!--**========================================================================== |
| 198 |
l10n.number.cjk-ideographic |
| 199 |
Formats a number using a CJK ideographic system |
| 200 |
|
| 201 |
[xsl:params] |
| 202 |
$value: The numeric value of the number to format |
| 203 |
$format: Which ideographic system to use |
| 204 |
|
| 205 |
REMARK: Talk about CJK ideographic numbering systems. Valid values of $format |
| 206 |
are `cjk-japanese`, `cjk-chinese-simp`, and `cjk-chinese-trad`. |
| 207 |
--> |
| 208 |
<xsl:template name="l10n.number.cjk-ideographic"> |
| 209 |
<xsl:param name="value"/> |
| 210 |
<xsl:param name="format"/> |
| 211 |
<xsl:call-template name="l10n.number.cjk-ideographic.private"> |
| 212 |
<xsl:with-param name="value" select="$value"/> |
| 213 |
<xsl:with-param name="format" select="$format"/> |
| 214 |
<xsl:with-param name="level" select="0"/> |
| 215 |
</xsl:call-template> |
| 216 |
</xsl:template> |
| 217 |
|
| 218 |
<!--#* l10n.number.cjk-ideographic.private --> |
| 219 |
<xsl:template name="l10n.number.cjk-ideographic.private"> |
| 220 |
<xsl:param name="value"/> |
| 221 |
<xsl:param name="format"/> |
| 222 |
<xsl:param name="level" select="0"/> |
| 223 |
<xsl:param name="zero" select="true()"/> |
| 224 |
<xsl:variable name="ones"> |
| 225 |
<xsl:text>〇一二三四</xsl:text> |
| 226 |
<xsl:text>五六七八九</xsl:text> |
| 227 |
</xsl:variable> |
| 228 |
<xsl:variable name="tens"> |
| 229 |
<xsl:text>十百千</xsl:text> |
| 230 |
</xsl:variable> |
| 231 |
<!-- FIXME: pick a upper bound and fallback to decimal --> |
| 232 |
<xsl:variable name="myriads"> |
| 233 |
<xsl:choose> |
| 234 |
<xsl:when test="$format='cjk-japanese'"> |
| 235 |
<xsl:text>万億兆京垓</xsl:text> |
| 236 |
</xsl:when> |
| 237 |
<xsl:when test="$format='cjk-chinese-simp'"> |
| 238 |
<xsl:text>万亿兆</xsl:text> |
| 239 |
</xsl:when> |
| 240 |
<xsl:when test="$format='cjk-chinese-trad'"> |
| 241 |
<xsl:text>萬億兆</xsl:text> |
| 242 |
</xsl:when> |
| 243 |
</xsl:choose> |
| 244 |
</xsl:variable> |
| 245 |
|
| 246 |
<xsl:variable name="digit" select="$value mod 10"/> |
| 247 |
<xsl:if test="$value - $digit > 0"> |
| 248 |
<xsl:call-template name="l10n.number.cjk-ideographic.private"> |
| 249 |
<xsl:with-param name="value" select="($value - $digit) div 10"/> |
| 250 |
<xsl:with-param name="format" select="$format"/> |
| 251 |
<xsl:with-param name="level" select="$level + 1"/> |
| 252 |
<xsl:with-param name="zero" select="$digit = 0"/> |
| 253 |
</xsl:call-template> |
| 254 |
</xsl:if> |
| 255 |
<xsl:choose> |
| 256 |
<xsl:when test="$digit = 0"> |
| 257 |
<xsl:choose> |
| 258 |
<xsl:when test="$value = 0"> |
| 259 |
<xsl:value-of select="substring($ones, $digit + 1, 1)"/> |
| 260 |
</xsl:when> |
| 261 |
<xsl:when test="$format='cjk-chinese-simp' and not($zero)"> |
| 262 |
<xsl:value-of select="substring($ones, $digit + 1, 1)"/> |
| 263 |
</xsl:when> |
| 264 |
<xsl:when test="$format='cjk-chinese-trad' and not($zero)"> |
| 265 |
<xsl:value-of select="substring($ones, $digit + 1, 1)"/> |
| 266 |
</xsl:when> |
| 267 |
</xsl:choose> |
| 268 |
</xsl:when> |
| 269 |
<xsl:otherwise> |
| 270 |
<xsl:value-of select="substring($ones, $digit + 1, 1)"/> |
| 271 |
</xsl:otherwise> |
| 272 |
</xsl:choose> |
| 273 |
<xsl:variable name="ten" select="$level mod 4"/> |
| 274 |
<xsl:choose> |
| 275 |
<xsl:when test="$ten != 0"> |
| 276 |
<xsl:if test="$digit != 0"> |
| 277 |
<xsl:value-of select="substring($tens, $ten, 1)"/> |
| 278 |
</xsl:if> |
| 279 |
</xsl:when> |
| 280 |
<xsl:otherwise> |
| 281 |
<xsl:variable name="myriad" select="($level - $ten) div 4"/> |
| 282 |
<xsl:if test="$myriad != 0"> |
| 283 |
<xsl:value-of select="substring($myriads, $myriad, 1)"/> |
| 284 |
</xsl:if> |
| 285 |
</xsl:otherwise> |
| 286 |
</xsl:choose> |
| 287 |
</xsl:template> |
| 288 |
|
| 289 |
|
| 290 |
<!--**========================================================================== |
| 291 |
l10n.number.ionic |
| 292 |
Formats a number using the Ionic numeral system |
| 293 |
|
| 294 |
[xsl:params] |
| 295 |
$value: The numeric value of the number to format |
| 296 |
$format: Which format to use |
| 297 |
|
| 298 |
REMARK: Talk about the Ionic numeral system. Talk about $format |
| 299 |
See `http://en.wikipedia.org/wiki/Greek_numerals`. |
| 300 |
--> |
| 301 |
<xsl:template name="l10n.number.ionic"> |
| 302 |
<xsl:param name="value"/> |
| 303 |
<xsl:param name="format" select="'ionic-lower'"/> |
| 304 |
<xsl:choose> |
| 305 |
<xsl:when test="$value < 1 or $value > 999999"> |
| 306 |
<xsl:number format="1" value="$value"/> |
| 307 |
</xsl:when> |
| 308 |
<xsl:otherwise> |
| 309 |
<xsl:call-template name="l10n.number.ionic.private"> |
| 310 |
<xsl:with-param name="value" select="$value"/> |
| 311 |
<xsl:with-param name="format" select="$format"/> |
| 312 |
<xsl:with-param name="level" select="1"/> |
| 313 |
</xsl:call-template> |
| 314 |
<xsl:text>´</xsl:text> |
| 315 |
</xsl:otherwise> |
| 316 |
</xsl:choose> |
| 317 |
</xsl:template> |
| 318 |
|
| 319 |
<!--#* l10n.number.ionic.private --> |
| 320 |
<xsl:template name="l10n.number.ionic.private"> |
| 321 |
<xsl:param name="value"/> |
| 322 |
<xsl:param name="format" select="'ionic-lower'"/> |
| 323 |
<xsl:param name="level" select="1"/> |
| 324 |
<xsl:param name="stigma" select="false()"/> |
| 325 |
<xsl:variable name="digit" select="$value mod 10"/> |
| 326 |
<xsl:if test="$value - $digit > 0"> |
| 327 |
<xsl:call-template name="l10n.number.ionic.private"> |
| 328 |
<xsl:with-param name="value" select="($value - $digit) div 10"/> |
| 329 |
<xsl:with-param name="format" select="$format"/> |
| 330 |
<xsl:with-param name="level" select="$level + 1"/> |
| 331 |
<xsl:with-param name="stigma" select="$stigma"/> |
| 332 |
</xsl:call-template> |
| 333 |
</xsl:if> |
| 334 |
<xsl:choose> |
| 335 |
<xsl:when test="$format='ionic-lower'"> |
| 336 |
<xsl:choose> |
| 337 |
<xsl:when test="$digit = 0"/> |
| 338 |
<xsl:when test="not($stigma) and $digit = 6 and $level = 1"> |
| 339 |
<xsl:text>στ</xsl:text> |
| 340 |
</xsl:when> |
| 341 |
<xsl:when test="$level = 1 or $level = 4"> |
| 342 |
<xsl:if test="$level = 4"> |
| 343 |
<xsl:text>,</xsl:text> |
| 344 |
</xsl:if> |
| 345 |
<xsl:value-of select="substring('αβγδεϛζηθ', $digit, 1)"/> |
| 346 |
</xsl:when> |
| 347 |
<xsl:when test="$level = 2 or $level = 5"> |
| 348 |
<xsl:if test="$level = 5"> |
| 349 |
<xsl:text>,</xsl:text> |
| 350 |
</xsl:if> |
| 351 |
<xsl:value-of select="substring('ικλμνξοπϟ', $digit, 1)"/> |
| 352 |
</xsl:when> |
| 353 |
<xsl:when test="$level = 3 or $level = 6"> |
| 354 |
<xsl:if test="$level = 6"> |
| 355 |
<xsl:text>,</xsl:text> |
| 356 |
</xsl:if> |
| 357 |
<xsl:value-of select="substring('ρστυφχψωϡ', $digit, 1)"/> |
| 358 |
</xsl:when> |
| 359 |
</xsl:choose> |
| 360 |
</xsl:when> |
| 361 |
<xsl:when test="$format='ionic-upper'"> |
| 362 |
<xsl:choose> |
| 363 |
<xsl:when test="$digit = 0"/> |
| 364 |
<xsl:when test="not($stigma) and $digit = 6 and $level = 1"> |
| 365 |
<xsl:text>ΣΤ</xsl:text> |
| 366 |
</xsl:when> |
| 367 |
<xsl:when test="$level = 1 or $level = 4"> |
| 368 |
<xsl:if test="$level = 4"> |
| 369 |
<xsl:text>,</xsl:text> |
| 370 |
</xsl:if> |
| 371 |
<xsl:value-of select="substring('ΑΒΓΔΕϚΖΗΘ', $digit, 1)"/> |
| 372 |
</xsl:when> |
| 373 |
<xsl:when test="$level = 2 or $level = 5"> |
| 374 |
<xsl:if test="$level = 5"> |
| 375 |
<xsl:text>,</xsl:text> |
| 376 |
</xsl:if> |
| 377 |
<xsl:value-of select="substring('ΙΚΛΜΝΞΟΠϘ', $digit, 1)"/> |
| 378 |
</xsl:when> |
| 379 |
<xsl:when test="$level = 3 or $level = 6"> |
| 380 |
<xsl:if test="$level = 6"> |
| 381 |
<xsl:text>,</xsl:text> |
| 382 |
</xsl:if> |
| 383 |
<xsl:value-of select="substring('ΡΣΤΥΦΧΨΩϠ', $digit, 1)"/> |
| 384 |
</xsl:when> |
| 385 |
</xsl:choose> |
| 386 |
</xsl:when> |
| 387 |
<xsl:otherwise> |
| 388 |
<xsl:value-of select="$digit"/> |
| 389 |
</xsl:otherwise> |
| 390 |
</xsl:choose> |
| 391 |
</xsl:template> |
| 392 |
|
| 393 |
</xsl:stylesheet> |