#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: VariableHandler(CompilationContext& context) : ItemContainerHandler(context), has_select_(false) { } // VariableHandler protected: virtual VType* createContainer(const std::string& namespaceURI, const std::string& localName, const std::string& qName, const SAX::Attributes& atts) { static const ValueRule rules[] = { { "name", true, 0 }, { "select", false, 0 }, { 0, false, 0} }; std::map attrs = gatherAttributes(qName, atts, rules); const std::string& select = atts.getValue("select"); Arabica::XPath::XPathExpressionPtr xpath; if(select != "") { xpath = this->context().xpath_expression(select); has_select_ = true; } // if ... std::pair name = this->context().processQName(attrs["name"]); return new VType(name.first, name.second, xpath); } // createContainer virtual void characters(const std::string& ch) { if(has_select_) { for(std::string::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_; }; // class VariableHandler template class TopLevelVariableHandler : public VariableHandler { public: TopLevelVariableHandler(CompilationContext& context) : VariableHandler(context) { } // VariableHandler virtual void endElement(const std::string& namespaceURI, const std::string& localName, const std::string& qName) { this->context().stylesheet().add_item(this->container()); this->context().pop(); } // endElement }; // class TopLevelVariableHandler } // namespace XSLT } // namespace Arabica #endif