From 9ca29ae10db502097594ced7987ac437fa1e0d62 Mon Sep 17 00:00:00 2001 From: David Lichteblau Date: Sat, 26 Apr 2008 15:04:32 +0200 Subject: [PATCH] Don't leak namespaces into the included stylesheet --- TEST | 14 +++++++------- parser.lisp | 5 +++-- unparse.lisp | 4 ++-- xslt.lisp | 19 ++++++++++++++----- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/TEST b/TEST index 23db4f9..821cdae 100644 --- a/TEST +++ b/TEST @@ -13266,14 +13266,14 @@ PASS Import__91033 [XSLT-Structure] Expected output (1): MSFT_Conformance_Tests/Import/Import__91033.saxon Actual output: MSFT_Conformance_Tests/Import/Import__91033.xuriella -FAIL Import__91048 [XSLT-Structure]: output doesn't match +PASS Import__91048 [XSLT-Structure] Stylesheet: MSFT_Conformance_Tests/Import/91048a.noindent-xsl Data: MSFT_Conformance_Tests/Import/books.xml Supplemental stylesheet: MSFT_Conformance_Tests/Import/91048e.xsl Expected output (1): MSFT_Conformance_Tests/Import/Import__91048.saxon Actual output: MSFT_Conformance_Tests/Import/Import__91048.xuriella -FAIL Import__91116 [XSLT-Structure]: output doesn't match +PASS Import__91116 [XSLT-Structure] Stylesheet: MSFT_Conformance_Tests/Import/91116a.noindent-xsl Data: MSFT_Conformance_Tests/Import/books.xml Supplemental stylesheet: MSFT_Conformance_Tests/Import/91116c.xsl @@ -13294,7 +13294,7 @@ PASS Import__91118 [XSLT-Structure] Expected output (1): MSFT_Conformance_Tests/Import/Import__91118.saxon Actual output: MSFT_Conformance_Tests/Import/Import__91118.xuriella -FAIL Import__91134 [XSLT-Structure]: output doesn't match +PASS Import__91134 [XSLT-Structure] Stylesheet: MSFT_Conformance_Tests/Import/91134a.noindent-xsl Data: MSFT_Conformance_Tests/Import/books.xml Supplemental stylesheet: MSFT_Conformance_Tests/Import/91134b.xsl @@ -13308,7 +13308,7 @@ PASS Import__91135 [XSLT-Structure] Expected output (1): MSFT_Conformance_Tests/Import/Import__91135.saxon Actual output: MSFT_Conformance_Tests/Import/Import__91135.xuriella -FAIL Import__91136 [XSLT-Structure]: output doesn't match +PASS Import__91136 [XSLT-Structure] Stylesheet: MSFT_Conformance_Tests/Import/91136a.noindent-xsl Data: MSFT_Conformance_Tests/Import/books.xml Supplemental stylesheet: MSFT_Conformance_Tests/Import/91136c.xsl @@ -17647,14 +17647,14 @@ PASS Stylesheet__91806 [XSLT-Structure] Expected output (1): MSFT_Conformance_Tests/Stylesheet/Stylesheet__91806.saxon Actual output: MSFT_Conformance_Tests/Stylesheet/Stylesheet__91806.xuriella -FAIL Stylesheet__91807 [XSLT-Structure]: output doesn't match +PASS Stylesheet__91807 [XSLT-Structure] Stylesheet: MSFT_Conformance_Tests/Stylesheet/91807.noindent-xsl Data: MSFT_Conformance_Tests/Stylesheet/books.xml Supplemental stylesheet: MSFT_Conformance_Tests/Stylesheet/91807a.xsl Expected output (1): MSFT_Conformance_Tests/Stylesheet/Stylesheet__91807.saxon Actual output: MSFT_Conformance_Tests/Stylesheet/Stylesheet__91807.xuriella -FAIL Stylesheet__91808 [XSLT-Structure]: output doesn't match +PASS Stylesheet__91808 [XSLT-Structure] Stylesheet: MSFT_Conformance_Tests/Stylesheet/91808.noindent-xsl Data: MSFT_Conformance_Tests/Stylesheet/books.xml Supplemental stylesheet: MSFT_Conformance_Tests/Stylesheet/91808a.xsl @@ -19388,4 +19388,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 2925/3080 tests (3 expected failures, 152 unexpected failures). +Passed 2931/3080 tests (3 expected failures, 146 unexpected failures). diff --git a/parser.lisp b/parser.lisp index cbab0c4..1076be4 100644 --- a/parser.lisp +++ b/parser.lisp @@ -29,10 +29,11 @@ (in-package :xuriella) -(defun map-namespace-declarations (fn element) +(defun map-namespace-declarations (fn element &optional include-redeclared) (let ((parent (stp:parent element))) (maphash (lambda (prefix uri) - (unless (and (typep parent 'stp:element) + (unless (and (not include-redeclared) + (typep parent 'stp:element) (equal (stp:find-namespace prefix parent) uri)) (funcall fn prefix uri))) (cxml-stp-impl::collect-local-namespaces element)))) diff --git a/unparse.lisp b/unparse.lisp index 1e8267d..5742a32 100644 --- a/unparse.lisp +++ b/unparse.lisp @@ -186,7 +186,7 @@ suggested-prefix value) -(defparameter *initial-namespaces* +(defparameter *initial-unparse-namespaces* '(("" . "") ("xmlns" . #"http://www.w3.org/2000/xmlns/") ("xml" . #"http://www.w3.org/XML/1998/namespace"))) @@ -211,7 +211,7 @@ :suggested-prefix suggested-prefix :all-namespaces (if parent (sink-element-all-namespaces parent) - *initial-namespaces*) + *initial-unparse-namespaces*) :new-namespaces nil :attributes nil)) (*current-element* elt) diff --git a/xslt.lisp b/xslt.lisp index ba08166..c5d0f41 100644 --- a/xslt.lisp +++ b/xslt.lisp @@ -192,11 +192,14 @@ ;;;; XSLT-ENVIRONMENT and XSLT-CONTEXT -(defparameter *namespaces* +(defparameter *initial-namespaces* '((nil . "") ("xmlns" . #"http://www.w3.org/2000/xmlns/") ("xml" . #"http://www.w3.org/XML/1998/namespace"))) +(defparameter *namespaces* + *initial-namespaces*) + (defvar *global-variable-declarations*) (defvar *lexical-variable-declarations*) @@ -442,10 +445,12 @@ (ensure-mode stylesheet local-name uri)) (find-mode stylesheet nil))) -(defun acons-namespaces (element &optional (bindings *namespaces*)) +(defun acons-namespaces + (element &optional (bindings *namespaces*) include-redeclared) (map-namespace-declarations (lambda (prefix uri) (push (cons prefix uri) bindings)) - element) + element + include-redeclared) bindings) (defun find-key (name stylesheet) @@ -573,10 +578,14 @@ (defun map-toplevel (fn xpath ) (dolist (node (list-toplevel xpath )) - (let ((*namespaces* *namespaces*)) + (let ((*namespaces* *initial-namespaces*)) (xpath:do-node-set (ancestor (xpath:evaluate "ancestor::node()" node)) + (xpath:with-namespaces (("" #.*xsl*)) + (when (xpath:node-matches-p ancestor "stylesheet|transform") + ;; discard namespaces from including stylesheets + (setf *namespaces* *initial-namespaces*))) (when (xpath-protocol:node-type-p ancestor :element) - (setf *namespaces* (acons-namespaces ancestor)))) + (setf *namespaces* (acons-namespaces ancestor *namespaces* t)))) (funcall fn node)))) (defun list-toplevel (xpath ) -- 2.11.4.GIT