[xsl] format-number using variable format string

Subject: [xsl] format-number using variable format string
From: "Nick James" <nicholasjames2@xxxxxxxxxxx>
Date: Fri, 07 Sep 2007 14:54:25 +0000
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"?>
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)' />

the output is
$ xsltproc problem.xsl problem.xml


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?


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

Current Thread