diff --git a/include/XSLT/impl/xslt_attribute.hpp b/include/XSLT/impl/xslt_attribute.hpp index 5775e409..bdddb2f9 100755 --- a/include/XSLT/impl/xslt_attribute.hpp +++ b/include/XSLT/impl/xslt_attribute.hpp @@ -39,7 +39,7 @@ public: namesp = namespace_->evaluateAsString(node, context.xpathContext()); else { - QName qn = QName::createQName(name); + QName qn = QName::create(name); if(!qn.prefix.empty()) { std::map::const_iterator ns = namespaces_.find(qn.prefix); diff --git a/include/XSLT/impl/xslt_element.hpp b/include/XSLT/impl/xslt_element.hpp index 415f1740..2c5d3f03 100755 --- a/include/XSLT/impl/xslt_element.hpp +++ b/include/XSLT/impl/xslt_element.hpp @@ -43,7 +43,7 @@ public: namesp = namespace_->evaluateAsString(node, context.xpathContext()); else { - QName qn = QName::createQName(name); + QName qn = QName::create(name); std::map::const_iterator ns = namespaces_.find(qn.prefix); if(ns == namespaces_.end()) throw SAX::SAXException("xsl:element Runtime Error - Undeclared prefix " + qn.prefix); diff --git a/include/XSLT/impl/xslt_qname.hpp b/include/XSLT/impl/xslt_qname.hpp index 3dc66750..eb7ef8ec 100644 --- a/include/XSLT/impl/xslt_qname.hpp +++ b/include/XSLT/impl/xslt_qname.hpp @@ -13,38 +13,45 @@ struct QName std::string prefix; std::string localName; std::string namespaceURI; + std::string qname; - static QName createQName(const std::string& qName) + QName(const std::string& p, + const std::string& lN, + const std::string& uri) : + prefix(p), + localName(lN), + namespaceURI(uri), + qname(p.empty() ? lN : (p + ":" + lN)) + { + } // QName + + static QName create(const std::string& qName) + { + return create(qName, ""); + } // create + + static QName create(const std::string& qName, const std::string& namespaceURI) { if(!Arabica::XML::is_qname >(qName)) throw SAX::SAXException("Bad name : " + qName); static char COLON = Arabica::text::Unicode::COLON; - QName qn; + + std::string prefix; + std::string localName; size_t colon = qName.find(COLON); + if(colon == std::string::npos) - qn.localName = qName; + localName = qName; else { - qn.prefix = qName.substr(0, colon); - qn.localName = qName.substr(colon+1); + prefix = qName.substr(0, colon); + localName = qName.substr(colon+1); } - - return qn; - } // createQName - - static QName createQName(const std::string& qName, const std::string namespaceURI) - { - QName qn(createQName(qName)); - qn.namespaceURI = namespaceURI; - - if(!qn.prefix.empty() && qn.namespaceURI.empty()) - throw SAX::SAXException("Undeclared prefix " + qn.prefix); - return qn; - } // createQName -}; // QName - + return QName(prefix, localName, namespaceURI); + } // create +}; // struct QName } // namespace XSLT } // namespace Arabica diff --git a/include/XSLT/impl/xslt_sink.hpp b/include/XSLT/impl/xslt_sink.hpp index c57f6ecd..17258915 100755 --- a/include/XSLT/impl/xslt_sink.hpp +++ b/include/XSLT/impl/xslt_sink.hpp @@ -52,8 +52,8 @@ public: bool start_element(const std::string& qName, const std::string& namespaceURI) { - QName qn = QName::createQName(qName, namespaceURI); - return start_element(qn.prefix, qn.localName, qn.namespaceURI); + QName en = QName::create(qName, namespaceURI); + return start_element(en.prefix, en.localName, en.namespaceURI); } // start_element bool start_element(const std::string& prefix, const std::string& localName, const std::string& namespaceURI) @@ -68,8 +68,8 @@ public: namespaceStack_.declareNamespace(prefix, namespaceURI); std::string mapped_prefix = namespaceStack_.findPrefix(namespaceURI); - name_ = (!mapped_prefix.empty()) ? mapped_prefix + ':' + localName : localName; - namespaceURI_ = namespaceURI; + + element_stack_.push(QName(mapped_prefix, localName, namespaceURI)); atts_.clear(); pending_element_ = true; @@ -80,8 +80,8 @@ public: void end_element(const std::string& qName, const std::string& namespaceURI) { - QName qn = QName::createQName(qName, namespaceURI); - end_element(qn.prefix, qn.localName, qn.namespaceURI); + QName en = QName::create(qName, namespaceURI); + end_element(en.prefix, en.localName, en.namespaceURI); } // end_element void end_element(const std::string& prefix, const std::string& localName, const std::string& namespaceURI) @@ -95,6 +95,7 @@ public: { std::string mapped_prefix = namespaceStack_.findPrefix(namespaceURI); do_end_element((!mapped_prefix.empty()) ? mapped_prefix + ':' + localName : localName, namespaceURI); + element_stack_.pop(); } // end_element namespaceStack_.popScope(); @@ -102,7 +103,7 @@ public: void start_attribute(const std::string& qName, const std::string& namespaceURI) { - QName qn = QName::createQName(qName, namespaceURI); + QName qn = QName::create(qName, namespaceURI); start_attribute(qn.prefix, qn.localName, qn.namespaceURI); } // start_attribute @@ -208,7 +209,7 @@ public: flush_element(); - name_ = target; + target_ = target; } // start_processing_instruction void end_processing_instruction() @@ -219,7 +220,7 @@ public: if(!text_mode_) { std::string data = escape(buffer_.str(), "?>", "? >"); - do_processing_instruction(name_, data); + do_processing_instruction(target_, data); } // if ... } // end_processing_instruction @@ -306,8 +307,7 @@ private: if(want_decs) addNamespaceDeclarations(); - do_start_element(name_, namespaceURI_, atts_); - + do_start_element(element_stack_.top().qname, element_stack_.top().namespaceURI, atts_); pending_element_ = false; } // flush_element @@ -336,8 +336,8 @@ private: int buffering_; bool pending_element_; int pending_attribute_; - std::string name_; - std::string namespaceURI_; + std::stack element_stack_; + std::string target_; SAX::AttributesImpl > atts_; std::stringstream buffer_; bool text_mode_;