Project

Profile

Help

ValidationException: String to double conversion: no digits found

Added by Maya Mathews over 7 years ago

We are trying to transform an XML using XSLT and are using the version Saxon 9.7.0.20 with Java 8. While running the program, we are getting the exception as

ValidationException: String to double conversion: no digits found|; INFO | jvm 1 | 2017/08/01 04:27:35.885 | |||STDOUT| at net.sf.saxon.type.ValidationFailure.makeException(ValidationFailure.java:385)|;

We have done some analysis and found that the issue with the variable ‘TotalRatio’. If we remove the following line from the xslt, it is working perfect.

<xsl:call-template name="Error"></xsl:call-template>

The transformation is performed correctly with library xalan-2.7.1, which was the one we were using earlier. I have read a similar kind of bug in the thread - https://saxonica.plan.io/issues/3233.

Could you please check whether this is a defect or anything I should be changed to make it work?

The sample XML and XSLT is attached.

Input.xml (647 Bytes) Input.xml Sample XML
Rules.xsl (1.04 KB) Rules.xsl Sample XSLT

Replies (3)

Please register to reply

RE: ValidationException: String to double conversion: no digits found - Added by Michael Kay over 7 years ago

This is an incompatibility between XPath 1.0 and 2.0, mentioned in Appendix C of https://www.w3.org/TR/xpath-functions/

See the entry for sum(): "2.0 raises an error if sequence contains values that cannot be added together such as NMTOKENS and other subtypes of string. 1.0 returns NaN." (It should also mention that the same applies to a sequence containing untypedAtomic values that cannot be converted to numbers).

Basically, you are applying sum() to a set of values that includes Ratio elements, and the only Ratio element in the set is empty. The specification for sum() says that it atomizes these nodes (producing an untypedAtomic value that is zero-length), and then casts the result to xs:double. Casting a zero-length string to xs:double throws a dynamic error FORG0001. In XSLT 1.0 the result would have been NaN, and the test $TotalRatio >1.5 when applied to NaN would return false.

One solution is to convert the values using the number() function rather than casting, by writing sum(x/x/x/x/Ratio/number()).

The reason it works when you remove the call on the error template is that the optimizer then realizes that it doesn't matter what the sum is, so there is no need to calculate it.

RE: ValidationException: String to double conversion: no digits found - Added by Maya Mathews over 7 years ago

Thanks for the reply.

Unfortunately, we won't have the option to edit the XSLT, as it is given by third party.

So we tried for forcing the processor to take the XPath 1.0 by using XPathCompiler.setBackwardsCompatible(true); However, it is giving me exception

net.sf.saxon.s9api.SaxonApiException: Configuration elements must be in namespace http://saxon.sf.net/ns/configuration

Is it possible to fix the issue without modifying the XSLT?

RE: ValidationException: String to double conversion: no digits found - Added by Michael Kay over 7 years ago

Some of the more common incompatibilities between XPath 1.0 and XPath 2.0 can be handled by running in backwards compatible mode, but this isn't one of them. There is no option in the 2.0 spec, or in Saxon, to reproduce the XPath 1.0 behaviour here, and therefore no solution to the problem that doesn't involve source code change. Of course it's easy to change the code in such a way that it still work under 1.0 as well as 2.0. If the third party isn't prepared to do this (and after all, XPath 2.0 is now over ten years old!) then it's a bit like refusing to convert web pages that use Flash - one day they will stop working.

The particular error "Configuration elements must be in namespace..." suggests you have tried to create a configuration file and have got it wrong, but that's a side issue. You're not going to be able to fix the problem in this way.

    (1-3/3)

    Please register to reply