473,508 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML & Decimal Numbers

Hi,

A couple Q's , so I've come to the experts<g>.

1) I need a definitive answer to the following debate. I've got a couple
developers who disagree on the following question. We've got an XML file of
numerical data results where it could contain values such as:
<RESULT>0.12345</RESULT> when created in English, but it could contain:
<RESULT>0,12345</RESULT> when created in another language... such as German
or French. One developer claims this should be perfrectly allowed, the other
claims you can never use commas in XML files for content and that he read it
somewhere, but can't find the reference. Who's correct?

2) Related to the above debate, is the question of using an XSL file to
generate the HTML from the above. How does one properly use the
format-number function and the decimal-format xsl command to allow only 1
XSL file to be used across multiple languages so that the selection and
display of the above RESULT value is correct for the current culture. Be
aware that an <xsl: choose> command operates on the RESULT value as well.
Does this require separate XSL files for each language?

TIA,

--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> jo*********@thermo.com
Nov 12 '05 #1
4 8931


John Bowman < wrote:

1) I need a definitive answer to the following debate. I've got a couple
developers who disagree on the following question. We've got an XML file of
numerical data results where it could contain values such as:
<RESULT>0.12345</RESULT> when created in English, but it could contain:
<RESULT>0,12345</RESULT> when created in another language... such as German
or French. One developer claims this should be perfrectly allowed, the other
claims you can never use commas in XML files for content and that he read it
somewhere, but can't find the reference. Who's correct?


Of course you can put a comma in there but if you want to store
numerical values then use the dot, you can then when you output the
stored data format the numbers as needed in the locale desired.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Martin,

Thanks for the info.

That said, then if I have a simple example XML file as below containing the
data values:

<?xml-stylesheet type="text/xsl" href="format.xsl"?>
<DOCUMENT>
<RESULT>29.8220</RESULT>
<RESULT>6.1234</RESULT>
<RESULT>-0.0678</RESULT>
</DOCUMENT>

How do I get the value of each of the RESULT's into the format-number
function so that it transforms them using the proper decimal-format? That
is, it should display it using the "," specified in the <xsl:decimal-format
name="fra" decimal-separator=","/> element? Basically, I can't get
format-number to accept anything for the value retrieved. It seems that
format-number only allows specific literal constants such as
format-number(1.2345, "#.#"), is that correct?

Below is a starting XSL file produced using Stylus Studio that displays the
values with "."'s. How can I modifiy it so the output shows: 29,8220 6,1234
0,0678 using the specified comma?

<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:decimal-format name="fra" decimal-separator=","/>
<xsl:template match="/">
<html><head/>
<body>
<xsl:for-each select="DOCUMENT/RESULT">
<xsl:value-of select="."/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Thanks!

John

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...


John Bowman < wrote:

1) I need a definitive answer to the following debate. I've got a couple
developers who disagree on the following question. We've got an XML file
of numerical data results where it could contain values such as:
<RESULT>0.12345</RESULT> when created in English, but it could contain:
<RESULT>0,12345</RESULT> when created in another language... such as
German or French. One developer claims this should be perfrectly allowed,
the other claims you can never use commas in XML files for content and
that he read it somewhere, but can't find the reference. Who's correct?


Of course you can put a comma in there but if you want to store numerical
values then use the dot, you can then when you output the stored data
format the numbers as needed in the locale desired.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #3


John Bowman < wrote:

<DOCUMENT>
<RESULT>29.8220</RESULT>
<RESULT>6.1234</RESULT>
<RESULT>-0.0678</RESULT>
</DOCUMENT>

How do I get the value of each of the RESULT's into the format-number
function so that it transforms them using the proper decimal-format?


Here is an example stylesheet that uses two different formats to format
your example input:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" encoding="UTF-8" indent="yes" />

<xsl:decimal-format
name="de-DE"
decimal-separator=","
grouping-separator="." />

<xsl:decimal-format
decimal-separator="."
grouping-separator="," />

<xsl:template match="/">
<results>
<culture name="en-US">
<xsl:for-each select="DOCUMENT/RESULT">
<result>
<xsl:value-of select="format-number(., '0.0000')" />
</result>
</xsl:for-each>
</culture>
<culture name="de-DE">
<xsl:for-each select="DOCUMENT/RESULT">
<result>
<xsl:value-of select="format-number(., '0,0000', 'de-DE')" />
</result>
</xsl:for-each>
</culture>
</results>
</xsl:template>

</xsl:stylesheet>

The result of the transformation should look alike

<?xml version="1.0" encoding="UTF-8"?>
<results>
<culture name="en-US">
<result>29.8220</result>
<result>6.1234</result>
<result>-0.0678</result>
</culture>
<culture name="de-DE">
<result>29,8220</result>
<result>6,1234</result>
<result>-0,0678</result>
</culture>
</results>

The documentation of xsl:format and format-number is here:
<http://www.w3.org/TR/xslt#format-number>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
Martin,

Thanks! The syntax of using just the period in the format-number function
was the trick.

John

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...


John Bowman < wrote:

<DOCUMENT>
<RESULT>29.8220</RESULT>
<RESULT>6.1234</RESULT>
<RESULT>-0.0678</RESULT>
</DOCUMENT>

How do I get the value of each of the RESULT's into the format-number
function so that it transforms them using the proper decimal-format?


Here is an example stylesheet that uses two different formats to format
your example input:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" encoding="UTF-8" indent="yes" />

<xsl:decimal-format
name="de-DE"
decimal-separator=","
grouping-separator="." />

<xsl:decimal-format
decimal-separator="."
grouping-separator="," />

<xsl:template match="/">
<results>
<culture name="en-US">
<xsl:for-each select="DOCUMENT/RESULT">
<result>
<xsl:value-of select="format-number(., '0.0000')" />
</result>
</xsl:for-each>
</culture>
<culture name="de-DE">
<xsl:for-each select="DOCUMENT/RESULT">
<result>
<xsl:value-of select="format-number(., '0,0000', 'de-DE')" />
</result>
</xsl:for-each>
</culture>
</results>
</xsl:template>

</xsl:stylesheet>

The result of the transformation should look alike

<?xml version="1.0" encoding="UTF-8"?>
<results>
<culture name="en-US">
<result>29.8220</result>
<result>6.1234</result>
<result>-0.0678</result>
</culture>
<culture name="de-DE">
<result>29,8220</result>
<result>6,1234</result>
<result>-0,0678</result>
</culture>
</results>

The documentation of xsl:format and format-number is here:
<http://www.w3.org/TR/xslt#format-number>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
4493
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
6102
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
2
3449
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
11
2218
by: Pieter | last post by:
Hi, I'm having some troubles with my numeric-types in my VB.NET 2005 application, together with a SQL Server 2000. - I first used Single in my application, and Decimal in my database. But a...
28
5812
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
7
9372
by: Jromero | last post by:
I need to add the sum of hex and decimal right now is not adding anything A5 165 A5 165A50 FAA 4010 FAA
8
2948
by: RN1 | last post by:
The book I am referring to learn ASP states the following about the Int & Fix VBScript Maths functions: ========================================= Both Int & Fix return the integer portion of the...
10
5301
by: Jason | last post by:
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole...
0
28044
Frinavale
by: Frinavale | last post by:
Convert a Hex number into a decimal number and a decimal number to Hex number This is a very simple script that converts decimal numbers into hex values and hex values into decimal numbers. The...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.