469,338 Members | 8,161 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,338 developers. It's quick & easy.

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 8731


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by Batista, Facundo | last post: by
2 posts views Thread by Steve Summit | last post: by
8 posts views Thread by RN1 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.