Andrey Shitov
Phone numbers 13 January 2006 |
|
Task: | Provide real examples to show why phone numbers should use XML. | ||
Page content for XSLT-produced websites is usually stored in XML documents (either files or database). If the page contains any phone numbers, they should not be typed as regular text but use a special tag, for example, <phone>
. It makes XML data better organized and allows the site to be displayed differently to various groups of users.
A bit of history |
Lets illustrate this with the example of Ukrainian telephone code. Sometimes you see 38, and the other times (mostly according to foreign sources) its 380. Even Russias leading telephone companies provide different information. Well, people argue about things, but the answer can be found. It just takes some efforts to surf the web, recollect a few facts to figure out what this 38 code is all about and why there is a zero. Official international dialing code of Ukraine is 380. It came into effect 16 April, 1995, as it was reported in ITU Operational Bulletin No. 590. There is also an example of dialing Kiev: before (+7 044 XXXXXXX) and after (+380 44 XXXXXXX) the document was issued. When Ukraine used the code of the USSR (7), one could make a call from Moscow to Kiev by dialing 8 044, which was the same code as for any other city in the USSR. And all Ukrainian city codes started with zero. But now its not clear whether the zero is the last number in the country code, or the first number in the city code. By the way, this problem affected some countries other than post-soviet states as well. To learn more you can read A reference scenario for moving to an open and unified European numbering environment, Annex 5 of Green paper on a numbering policy for telecommunications services in Europe. The official website of Ukrainian Ministry of Transport and Communications said 18 April, 2005, that it was 10 years since they began using international dialing code 380. However, this piece of news is no longer available online as it was removed soon after. |
One of the sites we made uses the following XML expression for phone numbers: <phone country="7" city="495">5401800</phone>
. If there are several phone numbers, they are grouped together:
|
Note that no hyphens are used. Phone number format (inserting brackets and hyphens) is completely defined in the XSLT template. Another good thing about XML is that it allows you to easily alter phone number format for the whole site by modifying just one XSLT element.
A less obvious advantage is that you have no trouble changing country and city codes. When Moscow came to use 495 instead of 095, we could just correct the XSLT part. We also had a chance to appreciate it when Ekaterinburg adopted a different phone number system in 2004.
This straight-forward approach causes contradictionssay, the initial XML file has city="095"
, but the output is (495). To avoid this, you can write country and city names rather than numbers. For example: <phone country="russia" city="moscow">5401800</phone>
. It requires an extra list of codes, though.
The XSLT transformation itself is so simple, that I suggest you should try to write it yourself, just to practice.
Geotargeting is a neat thing provided that you have an IP address location database (the most simple and the least accurate geotargeting is trying to guess location on the basis of http_Accept_Language variable).
A telephone number should be displayed differently depending on the users location. For example, a Moscow phone number for a person currently in Moscow can be as short as 540-18-00. If the user is in Russia but visiting the site from outside of Moscow, its better to provide the number with Moscow city code: (495) 540-18-00. And those who are abroad should see the country code as well: