Take the 2-minute tour ×

This is a part of my template: <xsl:value-of select="format-number(469802.00*30.05, '#.00')"/> When used, it yields a 14117550.10.

However, when i first store the product in a vairable and apply format-number afterwards: <xsl:variable name="end"> <xsl:value-of select="469802.00*30.05"/> </xsl:variable> <xsl:value-of select="format-number($end, '#.00')"/> the result is nAn

I use XALAN.

Why is the behaviour different?

share|improve this question
I can't see anything wrong with the code, except its horrifying inefficiency. Multiplying two numbers, converting the result to a text node, making the text node part of a result tree fragment, then getting the string value of the result tree fragment and converting it to a number so you can format it as a string - what are you playing at? –  Michael Kay Feb 13 '13 at 19:36
So what's the proper way to store a number in a variable? –  Flynn1179 Feb 14 '13 at 0:28
i simplified the original version, which contained a number of conditions and multiplied parts of the tree, not just numbers (like, set this variable to that if..., set this variable to that if...) –  gisly Feb 14 '13 at 4:14

2 Answers 2

I can't repro the problem with Saxon.


<xsl:variable name="end" select="469802.00*30.05"/>
<xsl:value-of select="format-number(number($end), '#.00')"/>
share|improve this answer

I don't have Xalan to hand, but from your code, I'm wondering if it's something to do with the spaces either side of the <xsl:value-of> element within the <xsl:variable> element.

Try making sure there's no whitespace inside your <xsl:variable> element within the stylesheet.

share|improve this answer

Your Answer


