From 62b24c144d0ac297394967d2fa353fb034af4a82 Mon Sep 17 00:00:00 2001 From: jez Date: Tue, 7 Apr 2009 13:39:31 +0100 Subject: [PATCH] Resolved cdata-section-element names so that unprefixed names are in the default namespace. Merge multiple xsl:output/@cdata-section-elements --- include/XSLT/impl/handler/xslt_output_handler.hpp | 5 ++++- include/XSLT/impl/xslt_compilation_context.hpp | 5 +++++ include/XSLT/impl/xslt_compiled_stylesheet.hpp | 2 +- include/XSLT/impl/xslt_output.hpp | 2 ++ include/XSLT/impl/xslt_sink.hpp | 6 +++++- include/XSLT/impl/xslt_stylesheet_parser.hpp | 5 +++++ 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/XSLT/impl/handler/xslt_output_handler.hpp b/include/XSLT/impl/handler/xslt_output_handler.hpp index 1239e9d6..27005a57 100644 --- a/include/XSLT/impl/handler/xslt_output_handler.hpp +++ b/include/XSLT/impl/handler/xslt_output_handler.hpp @@ -64,13 +64,16 @@ private: { Output::CDATAElements elements; + if(cdata_section_elements.empty()) + return elements; + std::istringstream is(cdata_section_elements); while(!is.eof()) { std::string e; is >> e; - XML::QualifiedName qualifiedName = context_.processInternalQName(e); + XML::QualifiedName qualifiedName = context_.processElementQName(e); elements.insert(QName::create(qualifiedName)); } // while diff --git a/include/XSLT/impl/xslt_compilation_context.hpp b/include/XSLT/impl/xslt_compilation_context.hpp index 39f39de0..f824b810 100755 --- a/include/XSLT/impl/xslt_compilation_context.hpp +++ b/include/XSLT/impl/xslt_compilation_context.hpp @@ -59,6 +59,11 @@ public: Arabica::XPath::XPathExpressionPtr xpath_attribute_value_template(const std::string& expr) const { return xpath_.compile_attribute_value_template(expr); } CompiledStylesheet& stylesheet() const { return stylesheet_; } + XML::QualifiedName processElementQName(const std::string& qName) const + { + return parser_.processElementQName(qName); + } // processElementQName + XML::QualifiedName processInternalQName(const std::string& qName) const { return parser_.processInternalQName(qName); diff --git a/include/XSLT/impl/xslt_compiled_stylesheet.hpp b/include/XSLT/impl/xslt_compiled_stylesheet.hpp index b7838390..466d8856 100755 --- a/include/XSLT/impl/xslt_compiled_stylesheet.hpp +++ b/include/XSLT/impl/xslt_compiled_stylesheet.hpp @@ -131,7 +131,7 @@ public: void output_settings(const Output::Settings& settings, const Output::CDATAElements& cdata_elements) { output_settings_ = settings; - output_cdata_elements_ = cdata_elements; + output_cdata_elements_.insert(cdata_elements.begin(), cdata_elements.end()); } // output_settings void prepare() diff --git a/include/XSLT/impl/xslt_output.hpp b/include/XSLT/impl/xslt_output.hpp index 507b7983..6bf573de 100644 --- a/include/XSLT/impl/xslt_output.hpp +++ b/include/XSLT/impl/xslt_output.hpp @@ -334,6 +334,8 @@ private: bool isCDATA() { + if(element_stack_.empty()) + return false; QName currentElement = element_stack_.top(); return cdataElements_.find(currentElement) != cdataElements_.end(); } // isCDATA diff --git a/include/XSLT/impl/xslt_sink.hpp b/include/XSLT/impl/xslt_sink.hpp index 302af543..2eea937f 100755 --- a/include/XSLT/impl/xslt_sink.hpp +++ b/include/XSLT/impl/xslt_sink.hpp @@ -83,6 +83,7 @@ public: StreamSink(std::ostream& stream) : stream_(stream), disable_output_escaping_(false), + in_cdata_(false), seen_root_(true), out_again_(false), indent_(-1), @@ -164,7 +165,7 @@ protected: { close_element_if_empty(); - if(!disable_output_escaping_) + if(!disable_output_escaping_ && !in_cdata_) std::for_each(ch.begin(), ch.end(), Arabica::XML::text_escaper(stream_)); else stream_ << ch; @@ -174,11 +175,13 @@ protected: { close_element_if_empty(); + in_cdata_ = true; stream_ << ""; } // do_end_CDATA @@ -299,6 +302,7 @@ private: std::ostream& stream_; bool disable_output_escaping_; + bool in_cdata_; bool empty_; bool seen_root_; Settings settings_; diff --git a/include/XSLT/impl/xslt_stylesheet_parser.hpp b/include/XSLT/impl/xslt_stylesheet_parser.hpp index 66f654b2..aca013b4 100755 --- a/include/XSLT/impl/xslt_stylesheet_parser.hpp +++ b/include/XSLT/impl/xslt_stylesheet_parser.hpp @@ -41,6 +41,11 @@ public: return namespace_tracker_.getURI(prefix); } // namespaceURI + XML::QualifiedName processElementQName(const std::string& rawName) const + { + return namespace_tracker_.processElementName(rawName); + } // processElementQName + XML::QualifiedName processInternalQName(const std::string& rawName) const { return namespace_tracker_.processName(rawName);