#ifndef ARABICA_XSLT_APPLY_TEMPLATES_HANDLER_HPP #define ARABICA_XSLT_APPLY_TEMPLATES_HANDLER_HPP #include "../xslt_apply_templates.hpp" #include "xslt_sort_handler.hpp" #include "xslt_with_param_handler.hpp" namespace Arabica { namespace XSLT { template class ApplyTemplatesHandler : public SAX::DefaultHandler { public: ApplyTemplatesHandler(CompilationContext& context) : context_(context), applyTemplates_(0) { } // ApplyTemplatesHandler virtual void startElement(const string_type& namespaceURI, const string_type& localName, const string_type& qName, const SAX::Attributes& atts) { if(applyTemplates_ == 0) { static const ValueRule rules[] = { { "select", false, 0, 0 }, { "mode", false, 0, 0 }, { 0, false, 0, 0} }; std::map attrs = gatherAttributes(qName, atts, rules); const string_type& select = attrs["select"]; Arabica::XPath::XPathExpressionPtr xpath; if(select != "") xpath = context_.xpath_expression(select); string_type mode; if(attrs["mode"] != "") mode = context_.processInternalQName(attrs["mode"]).clarkName(); applyTemplates_ = new ApplyTemplates(xpath, mode); return; } // if(applyTemplates_ == 0) if(namespaceURI == StylesheetConstant::NamespaceURI()) { if(localName == "sort") { context_.push(0, new SortHandler(context_, *applyTemplates_), namespaceURI, localName, qName, atts); return; } // if(localName == "sort") if(localName == "with-param") { context_.push(0, new WithParamHandler(context_, *applyTemplates_), namespaceURI, localName, qName, atts); return; } // if(localName == "sort") } // if ... throw SAX::SAXException("xsl:apply-templates can only contain xsl:sort and xsl:with-param elements."); } // startElement virtual void endElement(const string_type& /* namespaceURI */, const string_type& /* localName */, const string_type& /* qName */) { context_.parentContainer().add_item(applyTemplates_); context_.pop(); } // endElement virtual void characters(const string_type& ch) { verifyNoCharacterData(ch, "xsl:apply-templates"); } // characters private: CompilationContext& context_; ApplyTemplates* applyTemplates_; }; // class ApplyTemplatesHandler } // namespace XSLT } // namespace Arabica #endif // ARABICA_XSLT_APPLY_TEMPLATES_HANDLER_HPP