#ifndef ARABICA_XSLT_VARIABLES_HANDLER_HPP #define ARABICA_XSLT_VARIABLES_HANDLER_HPP #include "../xslt_param.hpp" #include "../xslt_variable.hpp" #include "xslt_item_container_handler.hpp" namespace Arabica { namespace XSLT { template class VariableHandler : public ItemContainerHandler { public: typedef typename VType::string_type string_type; typedef typename VType::string_adaptor string_adaptor; typedef ItemContainerHandler baseT; VariableHandler(CompilationContext& context) : baseT(context), has_select_(false), precedence_(Precedence::FrozenPrecedence()) { } // VariableHandler VariableHandler(CompilationContext& context, const Precedence& precedence) : baseT(context), has_select_(false), precedence_(precedence) { } // VariableHandler protected: virtual VType* createContainer(const string_type& /* namespaceURI */, const string_type& /* localName */, const string_type& qName, const SAX::Attributes& atts) { static const ValueRule rules[] = { { "name", true, 0, 0 }, { "select", false, 0, 0 }, { 0, false, 0, 0 } }; std::map attrs = gatherAttributes(qName, atts, rules); const string_type& select = atts.getValue("select"); Arabica::XPath::XPathExpressionPtr xpath; if(select != "") { xpath = baseT::context().xpath_expression(select); has_select_ = true; } // if ... string_type name = baseT::context().processInternalQName(attrs["name"]).clarkName(); return new VType(name, xpath, precedence_); } // createContainer virtual void characters(const string_type& ch) { if(has_select_) { for(string_type::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i) if(!Arabica::XML::is_space(*i)) throw SAX::SAXException("A variable or param can not have both a select attribute and text context"); } ItemContainerHandler::characters(ch); } // characters private: bool has_select_; const Precedence precedence_; }; // class VariableHandler template class TopLevelVariableHandler : public VariableHandler { public: typedef typename VType::string_type string_type; typedef typename VType::string_adaptor string_adaptor; typedef VariableHandler baseT; TopLevelVariableHandler(CompilationContext& context) : baseT(context, context.precedence()) { } // VariableHandler virtual void endElement(const string_type& /* namespaceURI */, const string_type& /* localName */, const string_type& /* qName */) { baseT::context().stylesheet().add_variable(baseT::container()); baseT::context().pop(); } // endElement }; // class TopLevelVariableHandler } // namespace XSLT } // namespace Arabica #endif