diff --git a/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp b/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp index 8a6a4494..3a8d91f0 100644 --- a/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp +++ b/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp @@ -10,36 +10,37 @@ namespace Arabica namespace XSLT { -class ApplyTemplatesHandler : public SAX::DefaultHandler +template +class ApplyTemplatesHandler : public SAX::DefaultHandler { public: - ApplyTemplatesHandler(CompilationContext& context) : + ApplyTemplatesHandler(CompilationContext& context) : context_(context), applyTemplates_(0) { } // ApplyTemplatesHandler - virtual void startElement(const std::string& namespaceURI, - const std::string& localName, - const std::string& qName, - const SAX::Attributes& atts) + 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); + std::map attrs = gatherAttributes(qName, atts, rules); - const std::string& select = attrs["select"]; - Arabica::XPath::XPathExpressionPtr xpath; + const string_type& select = attrs["select"]; + Arabica::XPath::XPathExpressionPtr xpath; if(select != "") xpath = context_.xpath_expression(select); - std::string mode; + string_type mode; if(attrs["mode"] != "") mode = context_.processInternalQName(attrs["mode"]).clarkName(); - applyTemplates_ = new ApplyTemplates(xpath, mode); + applyTemplates_ = new ApplyTemplates(xpath, mode); return; } // if(applyTemplates_ == 0) @@ -73,22 +74,22 @@ public: throw SAX::SAXException("xsl:apply-templates can only contain xsl:sort and xsl:with-param elements."); } // startElement - virtual void endElement(const std::string& /* namespaceURI */, - const std::string& /* localName */, - const std::string& /* qName */) + 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 std::string& ch) + virtual void characters(const string_type& ch) { verifyNoCharacterData(ch, "xsl:apply-templates"); } // characters private: - CompilationContext& context_; - ApplyTemplates* applyTemplates_; + CompilationContext& context_; + ApplyTemplates* applyTemplates_; }; // class ApplyTemplatesHandler } // namespace XSLT diff --git a/include/XSLT/impl/handler/xslt_item_container_handler.hpp b/include/XSLT/impl/handler/xslt_item_container_handler.hpp index 04a231de..81d5d094 100644 --- a/include/XSLT/impl/handler/xslt_item_container_handler.hpp +++ b/include/XSLT/impl/handler/xslt_item_container_handler.hpp @@ -139,7 +139,7 @@ const ChildElement* AllowedChildren() static const ChildElement allowedChildren[] = { { "apply-imports", CreateHandler > > }, - { "apply-templates", CreateHandler }, + { "apply-templates", CreateHandler > > }, { "attribute", CreateHandler > > }, { "call-template", CreateHandler > > }, { "choose", CreateHandler > > }, diff --git a/include/XSLT/impl/xslt_apply_templates.hpp b/include/XSLT/impl/xslt_apply_templates.hpp index f627ddb2..50e11540 100644 --- a/include/XSLT/impl/xslt_apply_templates.hpp +++ b/include/XSLT/impl/xslt_apply_templates.hpp @@ -10,19 +10,21 @@ namespace Arabica namespace XSLT { +template class ApplyTemplates : public Item, public Sortable, public WithParamable { public: - ApplyTemplates(Arabica::XPath::XPathExpressionPtr select, - std::string& mode) : + ApplyTemplates(Arabica::XPath::XPathExpressionPtr select, + string_type& mode) : select_(select), mode_(mode) { } // ApplyTemplates - virtual void execute(const DOM::Node& node, ExecutionContext& context) const + virtual void execute(const DOM::Node& node, + ExecutionContext& context) const { ParamPasser passer(*this, node, context); @@ -33,13 +35,13 @@ public: return; } - Arabica::XPath::NodeSet nodes; + Arabica::XPath::NodeSet nodes; if(select_ == 0) - for(DOM::Node n = node.getFirstChild(); n != 0; n = n.getNextSibling()) + for(DOM::Node n = node.getFirstChild(); n != 0; n = n.getNextSibling()) nodes.push_back(n); else { - Arabica::XPath::XPathValue value = select_->evaluate(node, context.xpathContext()); + Arabica::XPath::XPathValue value = select_->evaluate(node, context.xpathContext()); if(value.type() != Arabica::XPath::NODE_SET) throw std::runtime_error("apply-templates select expression is not a node-set"); nodes = value.asNodeSet(); @@ -49,8 +51,8 @@ public: } // execute private: - Arabica::XPath::XPathExpressionPtr select_; - std::string mode_; + Arabica::XPath::XPathExpressionPtr select_; + string_type mode_; }; // class ApplyTemplates } // namespace XSLT