#ifndef ARABICA_XSLT_OUTPUT_HANDLER_HPP #define ARABICA_XSLT_OUTPUT_HANDLER_HPP namespace Arabica { namespace XSLT { template class OutputHandler : public SAX::DefaultHandler { typedef StylesheetConstant SC; typedef AttributeValidators AV; public: OutputHandler(CompilationContext& context) : context_(context) { } // OutputHandler virtual void startElement(const string_type& /* namespaceURI */, const string_type& /* localName */, const string_type& qName, const SAX::Attributes& atts) { if(settings_.empty()) { static const AV rules = AV::rule(SC::method, false, SC::xml, AllowedValues(SC::xml, SC::html, SC::text)) .rule(SC::version, false, SC::Version) .rule(SC::encoding, false, SC::utf8) .rule(SC::omit_xml_declaration, false, SC::no, AllowedValues(SC::yes, SC::no)) .rule(SC::standalone, false, string_adaptor::empty_string(), AllowedValues(SC::yes, SC::no)) .rule(SC::doctype_public, false, string_adaptor::empty_string()) .rule(SC::doctype_system, false, string_adaptor::empty_string()) .rule(SC::cdata_section_elements, false, string_adaptor::empty_string()) .rule(SC::indent, false, SC::no, AllowedValues(SC::yes, SC::no)) .rule(SC::media_type, false, string_adaptor::empty_string()); settings_ = rules.gather(qName, atts); cdataElements_ = extractCDATAElements(settings_[SC::cdata_section_elements]); return; } // if(settings_ == 0) throw SAX::SAXException(string_adaptor::asStdString(qName) + " can not contain elements"); } // startElement virtual void endElement(const string_type& /* namespaceURI */, const string_type& /* localName */, const string_type& /* qName */) { context_.stylesheet().output_settings(settings_, cdataElements_); context_.pop(); } // endElement virtual void characters(const string_type& ch) { verifyNoCharacterData(ch, SC::output); } // characters private: typedef typename Output::CDATAElements CDATAElements; typedef typename Output::Settings Settings; CDATAElements extractCDATAElements(const string_type& cdata_section_elements) const { CDATAElements elements; if(string_adaptor::empty(cdata_section_elements)) return elements; string_type norm_cdata_sec_elements = text::normalize_whitespace(cdata_section_elements); std::basic_stringstream is; is << norm_cdata_sec_elements; while(!is.eof()) { std::basic_string e; is >> e; XML::QualifiedName qualifiedName = context_.processElementQName(string_adaptor::construct(e)); elements.insert(QName::create(qualifiedName)); } // while return elements; } // extractCDATAElements CompilationContext& context_; Settings settings_; CDATAElements cdataElements_; }; // class OutputHandler } // namespace XSLT } // namespace Arabica #endif