From b559feb7be6b2540b2fe200f579973f99215cbd9 Mon Sep 17 00:00:00 2001 From: jez Date: Tue, 5 Aug 2008 22:03:33 +0100 Subject: [PATCH] Added several more variables tests, related the namespace prefixes fixed internal qname resolution - 2.4 says unprefixed names are not in the default namespace fixed xsl:element - unprefixed names, when no namespace uri is supplied are in teh default namespace --- .../handler/xslt_apply_templates_handler.hpp | 2 +- .../handler/xslt_call_template_handler.hpp | 2 +- .../impl/handler/xslt_template_handler.hpp | 4 +-- .../impl/handler/xslt_variable_handler.hpp | 2 +- .../XSLT/impl/xslt_compilation_context.hpp | 7 ++-- include/XSLT/impl/xslt_element.hpp | 13 +++---- include/XSLT/impl/xslt_qname.hpp | 10 +++--- .../XSLT/testsuite/TESTS/arabica-catalog.xml | 36 +++++++++++++++++++ .../REF_OUT/variables/namespace4_result.xml | 1 + .../REF_OUT/variables/namespace_result.xml | 1 + .../TESTS/arabica/variables/namespace.xsl | 13 +++++++ .../TESTS/arabica/variables/namespace2.xsl | 14 ++++++++ .../TESTS/arabica/variables/namespace3.xsl | 15 ++++++++ .../TESTS/arabica/variables/namespace4.xsl | 14 ++++++++ 14 files changed, 114 insertions(+), 20 deletions(-) create mode 100644 tests/XSLT/testsuite/TESTS/arabica/REF_OUT/variables/namespace4_result.xml create mode 100644 tests/XSLT/testsuite/TESTS/arabica/REF_OUT/variables/namespace_result.xml create mode 100644 tests/XSLT/testsuite/TESTS/arabica/variables/namespace.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/variables/namespace2.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/variables/namespace3.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/variables/namespace4.xsl diff --git a/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp b/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp index 50eb13d7..f7de707e 100755 --- a/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp +++ b/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp @@ -38,7 +38,7 @@ public: std::pair mode; if(attrs["mode"] != "") - mode = context_.processQName(attrs["mode"]); + mode = context_.processInternalQName(attrs["mode"]); applyTemplates_ = new ApplyTemplates(xpath, mode); return; diff --git a/include/XSLT/impl/handler/xslt_call_template_handler.hpp b/include/XSLT/impl/handler/xslt_call_template_handler.hpp index 5972eb02..aefe4356 100644 --- a/include/XSLT/impl/handler/xslt_call_template_handler.hpp +++ b/include/XSLT/impl/handler/xslt_call_template_handler.hpp @@ -30,7 +30,7 @@ public: std::map attrs = gatherAttributes(qName, atts, rules); - std::pair name = context_.processQName(attrs["name"]); + std::pair name = context_.processInternalQName(attrs["name"]); callTemplate_ = new CallTemplate(name); return; diff --git a/include/XSLT/impl/handler/xslt_template_handler.hpp b/include/XSLT/impl/handler/xslt_template_handler.hpp index 08db990b..1b8a8bad 100755 --- a/include/XSLT/impl/handler/xslt_template_handler.hpp +++ b/include/XSLT/impl/handler/xslt_template_handler.hpp @@ -55,11 +55,11 @@ protected: std::pair name; if(atts.getValue("name") != "") - name = context().processQName(atts.getValue("name")); + name = context().processInternalQName(atts.getValue("name")); std::pair mode; if(atts.getValue("mode") != "") - mode = context().processQName(atts.getValue("mode")); + mode = context().processInternalQName(atts.getValue("mode")); if(match == "") return new Template(name, diff --git a/include/XSLT/impl/handler/xslt_variable_handler.hpp b/include/XSLT/impl/handler/xslt_variable_handler.hpp index 80e7cf6a..79c1209a 100644 --- a/include/XSLT/impl/handler/xslt_variable_handler.hpp +++ b/include/XSLT/impl/handler/xslt_variable_handler.hpp @@ -41,7 +41,7 @@ protected: has_select_ = true; } // if ... - std::pair name = this->context().processQName(attrs["name"]); + std::pair name = this->context().processInternalQName(attrs["name"]); return new VType(name.first, name.second, xpath); } // createContainer diff --git a/include/XSLT/impl/xslt_compilation_context.hpp b/include/XSLT/impl/xslt_compilation_context.hpp index 44a928f8..11ec9d58 100755 --- a/include/XSLT/impl/xslt_compilation_context.hpp +++ b/include/XSLT/impl/xslt_compilation_context.hpp @@ -58,12 +58,15 @@ public: Arabica::XPath::XPathExpressionPtr xpath_attribute_value_template(const std::string& expr) const { return xpath_.compile_attribute_value_template(expr); } Stylesheet& stylesheet() const { return stylesheet_; } - std::pair processQName(const std::string& qName) const + std::pair processInternalQName(const std::string& qName) const { if(!Arabica::XML::is_qname(qName)) throw SAX::SAXException("Bad name : " + qName); + // 2.4 The default namespace is not used for unprefixed names. + if(qName.find(':') == std::string::npos) + return std::make_pair("", qName); return parser_.processQName(qName); - } // processQName + } // processInternalQName std::string makeAbsolute(const std::string& href) const { diff --git a/include/XSLT/impl/xslt_element.hpp b/include/XSLT/impl/xslt_element.hpp index af34c2ef..85afe348 100755 --- a/include/XSLT/impl/xslt_element.hpp +++ b/include/XSLT/impl/xslt_element.hpp @@ -34,7 +34,7 @@ public: virtual void execute(const DOM::Node& node, ExecutionContext& context) const { std::string name = name_->evaluateAsString(node, context.xpathContext()); - if(name.empty()) + if(!Arabica::XML::is_qname(name)) throw SAX::SAXException("xsl:element name attribute must evaluate to a valid element name"); std::string namesp; @@ -44,13 +44,10 @@ public: else { QName qn = QName::createQName(name); - if(!qn.prefix.empty()) - { - std::map::const_iterator ns = namespaces_.find(qn.prefix); - if(ns == namespaces_.end()) - throw SAX::SAXException("xsl:element Runtime Error - Undeclared prefix " + qn.prefix); - namesp = ns->second; - } // if(!qn.prefix.empty()) + std::map::const_iterator ns = namespaces_.find(qn.prefix); + if(ns == namespaces_.end()) + throw SAX::SAXException("xsl:element Runtime Error - Undeclared prefix " + qn.prefix); + namesp = ns->second; } // if ... if(context.sink().start_element(name, namesp)) diff --git a/include/XSLT/impl/xslt_qname.hpp b/include/XSLT/impl/xslt_qname.hpp index b02fbe1d..2bd7b53b 100644 --- a/include/XSLT/impl/xslt_qname.hpp +++ b/include/XSLT/impl/xslt_qname.hpp @@ -1,6 +1,8 @@ #ifndef ARABICA_XSLT_QNAME_HPP #define ARABICA_XSLT_QNAME_HPP +#include + namespace Arabica { namespace XSLT @@ -14,6 +16,9 @@ struct QName static QName createQName(const std::string& qName) { + if(!Arabica::XML::is_qname(qName)) + throw SAX::SAXException("Bad name : " + qName); + static char COLON = Arabica::text::Unicode::COLON; QName qn; @@ -24,11 +29,6 @@ struct QName { qn.prefix = qName.substr(0, colon); qn.localName = qName.substr(colon+1); - - if((qn.prefix.length() == 0) || - (qn.localName.length() == 0) || - (qn.localName.find(COLON) != std::string::npos)) - throw SAX::SAXException("Bad qname"); } return qn; diff --git a/tests/XSLT/testsuite/TESTS/arabica-catalog.xml b/tests/XSLT/testsuite/TESTS/arabica-catalog.xml index 6ef60d52..03a7b2de 100755 --- a/tests/XSLT/testsuite/TESTS/arabica-catalog.xml +++ b/tests/XSLT/testsuite/TESTS/arabica-catalog.xml @@ -178,5 +178,41 @@ import_precedence2_result.xml + + variables + namespace + + foo.xml + namespace.xsl + namespace_result.xml + + + + variables + namespace + + foo.xml + namespace2.xsl + namespace_result.xml + + + + variables + namespace + + foo.xml + namespace3.xsl + namespace_result.xml + + + + variables + namespace + + foo.xml + namespace4.xsl + namespace4_result.xml + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/REF_OUT/variables/namespace4_result.xml b/tests/XSLT/testsuite/TESTS/arabica/REF_OUT/variables/namespace4_result.xml new file mode 100644 index 00000000..265aca56 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/REF_OUT/variables/namespace4_result.xml @@ -0,0 +1 @@ +var(foo) diff --git a/tests/XSLT/testsuite/TESTS/arabica/REF_OUT/variables/namespace_result.xml b/tests/XSLT/testsuite/TESTS/arabica/REF_OUT/variables/namespace_result.xml new file mode 100644 index 00000000..9dc40375 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/REF_OUT/variables/namespace_result.xml @@ -0,0 +1 @@ +var(foo) diff --git a/tests/XSLT/testsuite/TESTS/arabica/variables/namespace.xsl b/tests/XSLT/testsuite/TESTS/arabica/variables/namespace.xsl new file mode 100644 index 00000000..39b21e79 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/variables/namespace.xsl @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/variables/namespace2.xsl b/tests/XSLT/testsuite/TESTS/arabica/variables/namespace2.xsl new file mode 100644 index 00000000..cbc95c2d --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/variables/namespace2.xsl @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/variables/namespace3.xsl b/tests/XSLT/testsuite/TESTS/arabica/variables/namespace3.xsl new file mode 100644 index 00000000..10d108d1 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/variables/namespace3.xsl @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/variables/namespace4.xsl b/tests/XSLT/testsuite/TESTS/arabica/variables/namespace4.xsl new file mode 100644 index 00000000..9f495aa0 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/variables/namespace4.xsl @@ -0,0 +1,14 @@ + + + + + + + + + +