From 0af033f4f945ad6c329ce0e0819de0e29e84b287 Mon Sep 17 00:00:00 2001 From: David Lichteblau Date: Sun, 23 Mar 2008 14:44:25 +0100 Subject: [PATCH] xsl:number fixes: no prefix and suffix when NaN is printed --- TMP | 4 ++-- number.lisp | 48 +++++++++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/TMP b/TMP index 31a919a..8c6fdff 100644 --- a/TMP +++ b/TMP @@ -436,7 +436,7 @@ PASS numbering_numbering78 [XSLT-Result-Tree] Expected output (1): Xalan_Conformance_Tests/numbering/numbering_numbering78.saxon Actual output: Xalan_Conformance_Tests/numbering/numbering_numbering78.xuriella -FAIL numbering_numbering79 [XSLT-Result-Tree]: Can't decode NaN or infinity: #. +PASS numbering_numbering79 [XSLT-Result-Tree] Stylesheet: Xalan_Conformance_Tests/numbering/numbering79.noindent-xsl Data: Xalan_Conformance_Tests/numbering/numbering79.xml Expected output (1): Xalan_Conformance_Tests/numbering/numbering_numbering79.saxon @@ -514,4 +514,4 @@ PASS numbering_numbering93 [XSLT-Result-Tree] Expected output (1): Xalan_Conformance_Tests/numbering/numbering_numbering93.saxon Actual output: Xalan_Conformance_Tests/numbering/numbering_numbering93.xuriella -Passed 83/86 tests. +Passed 84/86 tests. diff --git a/number.lisp b/number.lisp index 2e30653..38bb797 100644 --- a/number.lisp +++ b/number.lisp @@ -44,8 +44,12 @@ (grouping-size (and grouping-size (compile-avt grouping-size env)))) (lambda (ctx) (let ((value (when value - (round (xpath:number-value - (funcall value ctx))))) + (let ((x + (xpath:number-value + (funcall value ctx)))) + (if (xpath::nan-p x) + x + (round x))))) (format (funcall format ctx)) (lang (funcall lang ctx)) (letter-value (funcall letter-value ctx)) @@ -200,25 +204,27 @@ (defun format-number-list (list format lang letter-value grouping-separator grouping-size) (declare (ignore lang letter-value)) - (multiple-value-bind (prefix pairs suffix) - (parse-number-format format) - (with-output-to-string (s) - (write-string prefix s) - (loop - for (separator . subformat) in pairs - for n in list - for formatted = (format-number-token subformat n) - do - (when separator - (write-string separator s)) - (if (and grouping-separator - grouping-size) - (group-numbers formatted - grouping-separator - grouping-size - s) - (write-string formatted s))) - (write-string suffix s)))) + (if (some #'xpath::nan-p list) + "NaN" + (multiple-value-bind (prefix pairs suffix) + (parse-number-format format) + (with-output-to-string (s) + (write-string prefix s) + (loop + for (separator . subformat) in pairs + for n in list + for formatted = (format-number-token subformat n) + do + (when separator + (write-string separator s)) + (if (and grouping-separator + grouping-size) + (group-numbers formatted + grouping-separator + grouping-size + s) + (write-string formatted s))) + (write-string suffix s))))) (defun parse-number-format (format) (let ((lexer (format-lexer format)) -- 2.11.4.GIT