[xml/xslt]format-number fout bij grote getallen

Pagina: 1
Acties:

  • Crysania
  • Registratie: September 2000
  • Laatst online: 08:46
ik heb even een simpel voorbeeld gemaakt waaruit mijn probleem blijkt. ik heb en erg groot getal in een xml data bestand staan en wil dit op het scherm tonen via xslt.

voorbeeld xml:
code:
1
2
3
4
5
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="numtest.xsl"?>
<test>
    1234567890123456789012345
</test>


voorbeeld xslt:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <html>
        <head></head>
        <body>
            <xsl:value-of select="format-number(test,'#')"/>
        </body>
    </html>
</xsl:template>

</xsl:stylesheet>


output
code:
1
1234567890123456800000000


zoals je ziet worden de laatste getallen allemaal op het scherm gezet als 0. loop ik hier tegen de maximale grootte van getallen aan of wat is hier het probleem?

ik snap natuurlijk dat een oplossing is om dit getal niet via format-number op het scherm te zetten maar gewoon value-of select "veldnaam" maar dat is even niet de vraag. Is dit nu een bug in xml of een fout van mij?

  • djc
  • Registratie: December 2001
  • Laatst online: 08-09-2025

djc

Hmm, ik kan die hele functie hier niet eens vinden.

Rustacean


  • prototype
  • Registratie: Juni 2001
  • Niet online

prototype

Cheer Bear

Manuzhai schreef op vrijdag 11 augustus 2006 @ 17:36:
Hmm, ik kan die hele functie hier niet eens vinden.
Dat is dan ook niet de beste reference op het net.
XSLT function: string format-number (number, string, string?)

Standard excerpt:
The format-number function converts its first argument to a string using the format pattern string specified by the second argument and the decimal-format named by the third argument, or the default decimal-format, if there is no third argument. The format pattern string is in the syntax specified by the JDK 1.1 DecimalFormat class. The format pattern string is in a localized notation: the decimal-format determines what characters have a special meaning in the pattern (with the exception of the quote character, which is not localized). The format pattern must not contain the currency sign (#x00A4);
Bron: http://www.zvon.org/xxl/XSLTreference/Output/index.html (functions -> format-number)

Je zult dus even moeten kijken in de documentatie van DecimalFormat.
Het lijkt er in ieder geval op voor zover ik kan zien dat je inderdaad te maken krijgt met een afronding.