RE: [xsl] format-number using variable format string

Subject: RE: [xsl] format-number using variable format string
From: "Carl Radley" <Carl.Radley@xxxxxxxxxxx>
Date: Fri, 7 Sep 2007 16:07:36 +0100
You are trying to select a node called &#108;.000
You want the variable as a string value, not a selection

Try this...

<xsl:variable name="numberFormat" select="'&#108;.000'" />


-----Original Message-----
From: Nick James [mailto:nicholasjames2@xxxxxxxxxxx]
Sent: 07 September 2007 15:54
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] format-number using variable format string


My problem is that I want to format some numbers in an xml file in a
fixed way, yet one which I can change relatively easily if need be. If
we have the file problem.xml:

<?xml version="1.0" encoding="utf-8"?>
<numbers>
    <number>22222.444444</number>
    <number>2.5555555</number>
    <number>999999.444444</number>
    <number>22222.444444</number>
</numbers>
and the file problem.xsl:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
    <xsl:output method="text" />
    <xsl:template match="number">
        <xsl:variable name="numberFormat" select="&#108;.000" />
        <xsl:value-of select='format-number(text(), $numberFormat)' />
    </xsl:template>
</xsl:stylesheet>

the output is
$ xsltproc problem.xsl problem.xml

    22222
    3
    999999
    22222

when I would have expected to see 3 dps on the numbers.

I keep on having this sort of problem with xsl(t?) - there are a hundred and
one good uses for it, but I end up getting completely bogged down.


Any answers?

NickJ

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

###############################################
Please help our environment -
only print this e-mail if you really need to.
###############################################

----------------------------------------------------------------
This e-mail (which includes any files attached to it) is not
contractually binding on its own, it is intended solely for
the named recipient and may contain CONFIDENTIAL, legally
privileged or trade secret information protected by law.
If you have received this message in error please delete it
and notify us immediately by telephoning +44(0)2476421213.
If you are not the intended recipient you must not use, disclose,
distribute, reproduce, retransmit, retain or rely on any
information contained in this e-mail. Please note that Severn
Trent Laboratories Limited reserve the right to monitor email
communications in accordance with applicable law and regulations.

To the extent permitted by law, neither Severn Trent Laboratories
Limited or any of its subsidiaries, nor any employee, director
or officer thereof, accepts any liability whatsoever in relation
to this e-mail including liability arising from any external breach
of security or confidentiality or for virus infection or for statements
made by the sender as these are not necessarily made on behalf of
Severn Trent Laboratories Limited.

Severn Trent Laboratories Limited is a limited company registered in
England and Wales under registered number 2148934 with its registered
office at 2297 Coventry Road, Birmingham B26 3PU.
-----------------------------------------------------------------------

Current Thread