473,597 Members | 2,247 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*********@the rmo.com
Nov 12 '05 #1
4 8940


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.xs l"?>
<DOCUMENT>
<RESULT>29.8220 </RESULT>
<RESULT>6.123 4</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:styleshe et 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="DOCUMEN T/RESULT">
<xsl:value-of select="."/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Thanks!

John

"Martin Honnen" <ma*******@yaho o.de> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l...


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.123 4</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:styleshe et
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="DOCUMEN T/RESULT">
<result>
<xsl:value-of select="format-number(., '0.0000')" />
</result>
</xsl:for-each>
</culture>
<culture name="de-DE">
<xsl:for-each select="DOCUMEN T/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.123 4</result>
<result>-0.0678</result>
</culture>
<culture name="de-DE">
<result>29,8220 </result>
<result>6,123 4</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*******@yaho o.de> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...


John Bowman < wrote:

<DOCUMENT>
<RESULT>29.8220 </RESULT>
<RESULT>6.123 4</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:styleshe et
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="DOCUMEN T/RESULT">
<result>
<xsl:value-of select="format-number(., '0.0000')" />
</result>
</xsl:for-each>
</culture>
<culture name="de-DE">
<xsl:for-each select="DOCUMEN T/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.123 4</result>
<result>-0.0678</result>
</culture>
<culture name="de-DE">
<result>29,8220 </result>
<result>6,123 4</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
4516
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
6130
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. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
2
3461
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 with 2's complement, 1's complement, or sign-magnitude arithmetic. But the followup remark is sometimes also made that the choice of arithmetic isn't completely unconstrained, since the bitwise operators seem to presume a base-2 machine.
11
2235
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 Single with value 4.475 was converted to a Decimal with value 4.4749999999999996D. So after inserting and selecting it from the database I got another value than the original!
28
5853
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is uncertain, as such numbers are not represented exactly. See section 4.7 for Rounding issues.
7
9391
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
2964
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 number but the difference lies in handling negative numbers. Int returns the first integer lesser than or equal to the number whereas Fix returns the first integer greater than or equal to the number. =========================================
10
5308
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 number text box, a numerator text box, and a denominator text box. I realize that this is probably the closest I'll get to having fractions displayed in VB, so that's no big deal. I'm able to simplify most numbers with some code I've written,...
0
28051
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 example following this one demonstrates how to convert decimal numbers into binary values. A hex number is a string that contains numbers between 0-9 and characters A-F; where A = 10, B = 11, ..., F = 15. (For more information please look up...
0
8276
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8040
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8259
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6698
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3889
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1495
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1243
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.