![]() |
Languages »
XML »
XML/XSLT
Intermediate
License: The Code Project Open License (CPOL)
XSLT Number to String TransformationBy Mahendra Kumar SrivastavaAn XSLT transform for string representation of numeric place values. |
XML, HTML, XSLT, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

We all have seen many applications written in different languages to transform numerical data to its equivalent place value representation. For example: 123 represented as 'One Hundred Twenty Three'. I am learning XSLT, and wrote this application to perform this transformation from XML to HTML numeric to place value translation. This transform file uses many features of XSLT like in-built methods for string manipulation, formatting, and number conversion.
People unfamiliar with India’s traditional numbering system may find this challenging. The system used in India, Pakistan, and Bangladesh is based on a unique grouping of two decimal places, rather than three decimal places common in the West. During business dealings in India, people are likely to come across the numerical terms Arab, Crore, and Lakh (see table below), although the higher numbers listed are rarely used. These more common words are often used in combination, e.g., one Lakh Crore, which is 1012, or one trillion. The terms Padma and Kharab are sometimes used in Hindi.
|
Term Figure |
No of zeros |
Western system (short-scale) |
|
Lakh (lac) 1,00,000 |
5 |
100000 (100 thousand) |
|
Crore 1,00,00,000 |
7 |
10,000,000 (Ten million) |
|
Arab 1,00,00,00,000 |
9 |
1,000,000,000 (One billion) |
|
Kharab 1,00,00,00,00,000 |
11 |
100,000,000,000 (100 billion) |
|
Neel 1,00,00,00,00,00,000 |
13 |
10,000,000,000,000 (10 trillion) |
|
Padma 1,00,00,00,00,00,00,000 |
15 |
1,000,000,000,000,000 (One quadrillion) |
|
Shankh 1,00,00,00,00,00,00,00,000 |
17 |
100,000,000,000,000,000 (100 quadrillion) |
|
Maha-shankh 1,00,00,00,00,00,00,00,00,000 |
19 |
10,000,000,000,000,000,000 (10 quintillion) |
Make your XML document as in the specified format given below. Put a stylesheet reference to your XML and open the XML in a web browser (in this XML, # represents a digit):
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="TransformNumber.xslt" ?>
<numbers>
<number>#########</number>
<number>####</number>
<number>####</number>
<number>#</number>
<number>###########</number>
<number>#####</number>
</numbers>
(1234 -> 10234)
(10234->010234)
value:01 place:3 evaluates to 'One Thousand'
value:02 place:2 evaluates to 'Two Hunderd'
value:34 place:1 evaluates to 'Thirty Four'
resulting in the string: 'One Thousand Two Hundred Thirty Four'.
Each pair contains two digits.
(34 -> 3 + '0' -> 30 -> Thirty)
(34 -> 4 -> Four)
(3 -> 3-1 -> 2 -> Thousand)
The XSLT file in this project can help you understand calling recursive templates, and also gives an idea about how to use in-built functions. We can use this as a base and can design our own XSLT for the English number system translation.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Jul 2008 Editor: Smitha Vijayan |
Copyright 2008 by Mahendra Kumar Srivastava Everything else Copyright © CodeProject, 1999-2009 Web15 | Advertise on the Code Project |