Number repr in compatibilty mode (XPath 1.0)
Added by Anonymous over 15 years ago
Legacy ID: #7438109 Legacy Poster: Claudio Tasso (tassoc)
Hi, I'm using the latest Saxon version from subversion repository. I'm trying evaluating an XPath expression using compatibility mode in order to obtain plain number representation, because XPath 2.0 scientific format is not good for me. In fact, according to XPath 2.0, when a number is outside the range 1E-6 to 1E+6 then its string representation uses scientific notation, for example "1.32122312314E11". I need number representation used in XPath 1.0, so I tried the following code: ------------------------------------- System.setProperty(XPathFactory.DEFAULT_PROPERTY_NAME+":"+XPathFactory.DEFAULT_OBJECT_MODEL_URI, "net.sf.saxon.xpath.XPathFactoryImpl"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbf.newDocumentBuilder(); System.out.println(dbf); Document document = builder.parse(new InputSource(new StringReader("<Doc/>"))); XPathFactory xpf = XPathFactory.newInstance(); XPath xPath = xpf.newXPath(); ((XPathEvaluator)xPath).setBackwardsCompatible(true); value = (String) xPath.evaluate("number('132122312313.5354353')", document, XPathConstants.STRING); System.out.println("String: "+value); --------------------------- But the result is not what is expected: String: 1.3212231231353543E11 How can I obtain an XPath 1.0 compatible number representation? Thanks in advance
Replies (1)
RE: Number repr in compatibilty mode (XPath 1.0) - Added by Anonymous over 15 years ago
Legacy ID: #7438133 Legacy Poster: Michael Kay (mhkay)
The rules for converting numbers to strings are not affected by compatibility mode: see http://www.w3.org/TR/2009/PER-xpath20-20090421/#id-incompat-in-true-mode I would suggest converting the double to a decimal and then converting the decimal to a string.
Please register to reply