format-number() is defined in the XSLT 2.0 specification, not in XPath 2.0. The reason is that it has a dependency on the xsl:decimal-format definitions in the stylesheet.

This changes in XPath 3.0; format-number becomes part of XPath, and you can set decimal formats using the XPath API. This is currently supported in Saxon-PE 9.4 (none of the 3.0 features are available in Saxon-HE at present, though this may change in the future).

When you say it's "costly" to change your code to get a numeric result, I assume you mean it's costly in terms of programmer effort.

Another option which may give you the results you want is to convert to xs:decimal and then to xs:string, so


Michael Kay

On 15/05/2012 11:45, Yoni Amir wrote:


I run into some troubles with saxon, specifically regarding xpath, not xslt.


I am using saxon-he, and I am using an xpath expression as follows: sum(/a/b)

I execute the xpath using standard Java api, roughly as follows (expecting a string as a result): getXpathExpression().evaluate(item, XPathConstants.STRING);


This works ok, but for large results (7 digits and up) I get the result in a scientific notation format: 3.0E6


So I tried to use the format-number function: format-number(sum(/a/b),'#')

but then I get this exception:


Caused by: net.sf.saxon.trans.XPathException: System function format-number#2 is not available with this host language/version

                at net.sf.saxon.expr.parser.ExpressionParser.grumble(


Any idea how I can solve this:


1)      Will upgrading to saxon-pe or saxon-ee help?

2)      I can change the code to expect a numeric result, but this is currently very costly, I am trying to avoid it.

3)      Any way to use custom functions in xpath?




Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 

saxon-help mailing list archived at