From 4184bd1a24dc78b7c2e549c1b63b03bd98660e8b Mon Sep 17 00:00:00 2001 From: David Lichteblau Date: Sun, 30 Mar 2008 13:37:39 +0200 Subject: [PATCH] Forwards compatible processing: Unknown instruction elements --- TEST | 36 +++++++++++++++++++----------------- instructions.lisp | 7 ++++++- package.lisp | 1 + parser.lisp | 43 +++++++++++++++++++++++++++++-------------- xslt.lisp | 19 +++++++++++-------- 5 files changed, 66 insertions(+), 40 deletions(-) diff --git a/TEST b/TEST index 59e092c..5d63471 100644 --- a/TEST +++ b/TEST @@ -9930,7 +9930,9 @@ PASS variable_variable70 [XSLT-Result-Tree] Expected output (1): Xalan_Conformance_Tests/variable/variable_variable70.saxon Actual output: Xalan_Conformance_Tests/variable/variable_variable70.xuriella -FAIL ver_ver01 [XSLT-Result-Tree]: undefined instruction: exciting-new-8.5-feature +WARNING: +This stylesheet requires XSLT 8.5 or higher +PASS ver_ver01 [XSLT-Result-Tree] Stylesheet: Xalan_Conformance_Tests/ver/ver01.noindent-xsl Data: Xalan_Conformance_Tests/ver/ver01.xml Expected output (1): Xalan_Conformance_Tests/ver/ver_ver01.saxon @@ -9942,19 +9944,19 @@ PASS ver_ver04 [XSLT-Result-Tree] Expected output (1): Xalan_Conformance_Tests/ver/ver_ver04.saxon Actual output: Xalan_Conformance_Tests/ver/ver_ver04.xuriella -FAIL ver_ver05 [XSLT-Result-Tree]: undefined instruction: exciting-new-17.1-feature +PASS ver_ver05 [XSLT-Result-Tree] Stylesheet: Xalan_Conformance_Tests/ver/ver05.noindent-xsl Data: Xalan_Conformance_Tests/ver/ver05.xml Expected output (1): Xalan_Conformance_Tests/ver/ver_ver05.saxon Actual output: Xalan_Conformance_Tests/ver/ver_ver05.xuriella -FAIL ver_ver06 [XSLT-Result-Tree]: undefined instruction: exciting-new-17.2-feature +PASS ver_ver06 [XSLT-Result-Tree] Stylesheet: Xalan_Conformance_Tests/ver/ver06.noindent-xsl Data: Xalan_Conformance_Tests/ver/ver06.xml Expected output (1): Xalan_Conformance_Tests/ver/ver_ver06.saxon Actual output: Xalan_Conformance_Tests/ver/ver_ver06.xuriella -FAIL ver_ver07 [XSLT-Result-Tree]: undefined instruction: result-document +PASS ver_ver07 [XSLT-Result-Tree] Stylesheet: Xalan_Conformance_Tests/ver/ver07.noindent-xsl Data: Xalan_Conformance_Tests/ver/ver07.xml Expected output (1): Xalan_Conformance_Tests/ver/ver_ver07.saxon @@ -11098,7 +11100,7 @@ PASS BVTs_bvt022 [Mixed]: raised an xslt-error as expected Expected output (1): MSFT_Conformance_Tests/BVTs/BVTs_bvt022.saxon Actual output: MSFT_Conformance_Tests/BVTs/BVTs_bvt022.xuriella -FAIL BVTs_bvt023 [Mixed]: undefined instruction: new +PASS BVTs_bvt023 [Mixed] Stylesheet: MSFT_Conformance_Tests/BVTs/fallback.noindent-xsl Data: MSFT_Conformance_Tests/BVTs/data.xml Expected output (1): MSFT_Conformance_Tests/BVTs/BVTs_bvt023.saxon @@ -14078,7 +14080,7 @@ PASS Errors_err033 [Mixed]: raised an xslt-error as expected Expected output (1): MSFT_Conformance_Tests/Errors/Errors_err033.saxon Actual output: MSFT_Conformance_Tests/Errors/Errors_err033.xuriella -FAIL Errors_err034 [Mixed]: expected error not signalled: +PASS Errors_err034 [Mixed]: raised an xslt-error as expected Stylesheet: MSFT_Conformance_Tests/Errors/extelem-bad.noindent-xsl Data: MSFT_Conformance_Tests/Errors/data.xml Expected output (1): MSFT_Conformance_Tests/Errors/Errors_err034.saxon @@ -16011,25 +16013,25 @@ PASS Fallback__91817 [XSLT-Extendability] Expected output (1): MSFT_Conformance_Tests/Fallback/Fallback__91817.saxon Actual output: MSFT_Conformance_Tests/Fallback/Fallback__91817.xuriella -FAIL Fallback__91818 [XSLT-Extendability]: undefined instruction: foo +PASS Fallback__91818 [XSLT-Extendability] Stylesheet: MSFT_Conformance_Tests/Fallback/91818.noindent-xsl Data: MSFT_Conformance_Tests/Fallback/books.xml Expected output (1): MSFT_Conformance_Tests/Fallback/Fallback__91818.saxon Actual output: MSFT_Conformance_Tests/Fallback/Fallback__91818.xuriella -FAIL Fallback__91819 [XSLT-Extendability]: undefined instruction: foo +PASS Fallback__91819 [XSLT-Extendability] Stylesheet: MSFT_Conformance_Tests/Fallback/91819.noindent-xsl Data: MSFT_Conformance_Tests/Fallback/books.xml Expected output (1): MSFT_Conformance_Tests/Fallback/Fallback__91819.saxon Actual output: MSFT_Conformance_Tests/Fallback/Fallback__91819.xuriella -FAIL Fallback__91820 [XSLT-Extendability]: undefined instruction: foo +PASS Fallback__91820 [XSLT-Extendability] Stylesheet: MSFT_Conformance_Tests/Fallback/91820.noindent-xsl Data: MSFT_Conformance_Tests/Fallback/books.xml Expected output (1): MSFT_Conformance_Tests/Fallback/Fallback__91820.saxon Actual output: MSFT_Conformance_Tests/Fallback/Fallback__91820.xuriella -FAIL Fallback__91821 [XSLT-Extendability]: undefined instruction: foo +PASS Fallback__91821 [XSLT-Extendability] Stylesheet: MSFT_Conformance_Tests/Fallback/91821.noindent-xsl Data: MSFT_Conformance_Tests/Fallback/books.xml Expected output (1): MSFT_Conformance_Tests/Fallback/Fallback__91821.saxon @@ -16041,13 +16043,13 @@ PASS Fallback__91822 [XSLT-Extendability]: raised an xslt-error as expected Expected output (1): MSFT_Conformance_Tests/Fallback/Fallback__91822.saxon Actual output: MSFT_Conformance_Tests/Fallback/Fallback__91822.xuriella -FAIL Fallback__91823 [XSLT-Extendability]: undefined instruction: foo +PASS Fallback__91823 [XSLT-Extendability] Stylesheet: MSFT_Conformance_Tests/Fallback/91823.noindent-xsl Data: MSFT_Conformance_Tests/Fallback/books.xml Expected output (1): MSFT_Conformance_Tests/Fallback/Fallback__91823.saxon Actual output: MSFT_Conformance_Tests/Fallback/Fallback__91823.xuriella -FAIL Fallback__91824 [XSLT-Extendability]: undefined instruction: foo +PASS Fallback__91824 [XSLT-Extendability] Stylesheet: MSFT_Conformance_Tests/Fallback/91824.noindent-xsl Data: MSFT_Conformance_Tests/Fallback/books.xml Expected output (1): MSFT_Conformance_Tests/Fallback/Fallback__91824.saxon @@ -16173,13 +16175,13 @@ PASS ForwardComp__91841 [XSLT-Extendability]: raised an xslt-error as expected Expected output (1): MSFT_Conformance_Tests/ForwardComp/ForwardComp__91841.saxon Actual output: MSFT_Conformance_Tests/ForwardComp/ForwardComp__91841.xuriella -FAIL ForwardComp__91842 [XSLT-Extendability]: undefined instruction: foo +PASS ForwardComp__91842 [XSLT-Extendability] Stylesheet: MSFT_Conformance_Tests/ForwardComp/91842.noindent-xsl Data: MSFT_Conformance_Tests/ForwardComp/books.xml Expected output (1): MSFT_Conformance_Tests/ForwardComp/ForwardComp__91842.saxon Actual output: MSFT_Conformance_Tests/ForwardComp/ForwardComp__91842.xuriella -FAIL ForwardComp__91843 [XSLT-Extendability]: undefined instruction: foo +PASS ForwardComp__91843 [XSLT-Extendability] Stylesheet: MSFT_Conformance_Tests/ForwardComp/91843.noindent-xsl Data: MSFT_Conformance_Tests/ForwardComp/books.xml Expected output (1): MSFT_Conformance_Tests/ForwardComp/ForwardComp__91843.saxon @@ -16191,13 +16193,13 @@ PASS ForwardComp__91844 [XSLT-Extendability]: raised an xslt-error as expected Expected output (1): MSFT_Conformance_Tests/ForwardComp/ForwardComp__91844.saxon Actual output: MSFT_Conformance_Tests/ForwardComp/ForwardComp__91844.xuriella -PASS ForwardComp__91845 [XSLT-Extendability]: raised an xslt-error as expected +PASS ForwardComp__91845 [XSLT-Extendability] Stylesheet: MSFT_Conformance_Tests/ForwardComp/91845.noindent-xsl Data: MSFT_Conformance_Tests/ForwardComp/books.xml Expected output (1): MSFT_Conformance_Tests/ForwardComp/ForwardComp__91845.saxon Actual output: MSFT_Conformance_Tests/ForwardComp/ForwardComp__91845.xuriella -PASS ForwardComp__91846 [XSLT-Extendability]: raised an xslt-error as expected +PASS ForwardComp__91846 [XSLT-Extendability] Stylesheet: MSFT_Conformance_Tests/ForwardComp/91846.noindent-xsl Data: MSFT_Conformance_Tests/ForwardComp/books.xml Expected output (1): MSFT_Conformance_Tests/ForwardComp/ForwardComp__91846.saxon @@ -22607,4 +22609,4 @@ PASS XSLTFunctions_DocumentFuncWithEmptyArg [Mixed] Expected output (1): MSFT_Conformance_Tests/XSLTFunctions/XSLTFunctions_DocumentFuncWithEmptyArg.saxon Actual output: MSFT_Conformance_Tests/XSLTFunctions/XSLTFunctions_DocumentFuncWithEmptyArg.xuriella -Passed 2723/3076 tests. +Passed 2737/3076 tests. diff --git a/instructions.lisp b/instructions.lisp index 3af1a31..8d13b76 100644 --- a/instructions.lisp +++ b/instructions.lisp @@ -487,6 +487,11 @@ (let ((*extension-namespaces* (append uris *extension-namespaces*))) (compile-instruction `(progn ,@body) env)))) +(define-instruction xsl:with-version (args env) + (destructuring-bind (version &rest body) args + (let ((*forwards-compatible-p* (not (equal version "1.0")))) + (compile-instruction `(progn ,@body) env)))) + ;; XSLT disallows multiple definitions of the same variable within a ;; template. Local variables can shadow global variables though. ;; Since our LET syntax makes it natural to shadow local variables the @@ -562,7 +567,7 @@ (compile-message #'warn args env)) (define-instruction xsl:terminate (args env) - (compile-message #'error args env)) + (compile-message #'xslt-error args env)) (defun namespaces-as-alist (element) (let ((namespaces '())) diff --git a/package.lisp b/package.lisp index 296605f..004d5f4 100644 --- a/package.lisp +++ b/package.lisp @@ -29,6 +29,7 @@ #:document ;fixme: incompatible with XSLT 2.0 ;; xuriella internals + #:with-version #:with-namespaces #:with-excluded-namespaces #:with-extension-namespaces diff --git a/parser.lisp b/parser.lisp index fbec9c8..2854480 100644 --- a/parser.lisp +++ b/parser.lisp @@ -99,11 +99,15 @@ (let ((expr (cond ((equal (stp:namespace-uri node) *xsl*) - (parse-instruction/xsl-element - (or (find-symbol (stp:local-name node) :xuriella) - (xslt-error "undefined instruction: ~A" - (stp:local-name node))) - node)) + (let ((sym (find-symbol (stp:local-name node) :xuriella))) + (cond + (sym + (parse-instruction/xsl-element sym node)) + (*forwards-compatible-p* + (parse-fallback-children node)) + (t + (xslt-error "undefined instruction: ~A" + (stp:local-name node)))))) ((find (stp:namespace-uri node) *extension-namespaces* :test #'equal) @@ -136,6 +140,7 @@ ,(stp:namespace-prefix a)) ,(stp:value a))) ,@(parse-body node))) + (version (stp:attribute-value node "version" *xsl*)) (extensions '())) (stp:with-attributes ((eep "extension-element-prefixes" *xsl*)) node @@ -145,17 +150,27 @@ (push (or (stp:find-namespace prefix node) (xslt-error "namespace not found: ~A" prefix)) extensions))) - (if extensions - `(xsl:with-extension-namespaces ,extensions - (xsl:with-excluded-namespaces ,extensions - ,le)) - le))) + (when extensions + (setf le + `(xsl:with-extension-namespaces ,extensions + (xsl:with-excluded-namespaces ,extensions + ,le)))) + (when version + (setf le + `(xsl:with-version ,version + ,le))) + le)) (defun parse-fallback-children (node) - `(progn - ,@(loop - for fallback in (stp:filter-children (of-name "fallback") node) - append (parse-body fallback)))) + (let ((fallbacks + (loop + for fallback in (stp:filter-children (of-name "fallback") node) + append (parse-body fallback)))) + (if fallbacks + `(progn ,@fallbacks) + `(xsl:terminate + (xsl:text + "no fallback children in unknown element using forwards compatible processing"))))) (defmacro define-instruction-parser (name (node-var) &body body) `(progn diff --git a/xslt.lisp b/xslt.lisp index 9e32a72..2df6990 100644 --- a/xslt.lisp +++ b/xslt.lisp @@ -402,6 +402,7 @@ (defvar *apply-imports-limit*) (defvar *import-priority*) (defvar *extension-namespaces*) +(defvar *forwards-compatible-p*) (defmacro do-toplevel ((var xpath ) &body body) `(map-toplevel (lambda (,var) ,@body) ,xpath ,)) @@ -424,14 +425,16 @@ (xpath::mappend-pipe #'recurse subsubs))))) (xpath::sort-nodes (recurse )))) -(defmacro with-parsed-prefixes ((node env) &body body) - `(invoke-with-parsed-prefixes (lambda () ,@body) ,node ,env)) +(defmacro with-import-magic ((node env) &body body) + `(invoke-with-import-magic (lambda () ,@body) ,node ,env)) -(defun invoke-with-parsed-prefixes (fn node env) +(defun invoke-with-import-magic (fn node env) (unless (or (namep node "stylesheet") (namep node "transform")) (setf node (stp:parent node))) (let ((*excluded-namespaces* (list *xsl*)) - (*extension-namespaces* '())) + (*extension-namespaces* '()) + (*forwards-compatible-p* + (not (equal (stp:attribute-value node "version") "1.0")))) (parse-exclude-result-prefixes! node env) (parse-extension-element-prefixes! node env) (funcall fn))) @@ -443,7 +446,7 @@ (apply-imports-limit (1+ *import-priority*)) (continuations '())) (let ((*namespaces* namespaces)) - (invoke-with-parsed-prefixes (constantly t) env)) + (invoke-with-import-magic (constantly t) env)) (macrolet ((with-specials ((&optional) &body body) `(let ((*instruction-base-uri* instruction-base-uri) (*namespaces* namespaces) @@ -521,7 +524,7 @@ (defun parse-attribute-sets! (stylesheet env) (do-toplevel (elt "attribute-set" ) - (with-parsed-prefixes (elt env) + (with-import-magic (elt env) (push (let* ((sets (mapcar (lambda (qname) (multiple-value-list (decode-qname qname env nil))) @@ -776,7 +779,7 @@ (*excluded-namespaces* (list *xsl*)) (*extension-namespaces* '()) (qname (stp:attribute-value "name"))) - (with-parsed-prefixes ( global-env) + (with-import-magic ( global-env) (unless qname (xslt-error "name missing in ~A" (stp:local-name ))) (multiple-value-bind (local-name uri) @@ -871,7 +874,7 @@ (do-toplevel (