From d68a9240cefe281f4d70bf7b8aa16f68f4a12dbb Mon Sep 17 00:00:00 2001 From: Jez Higgins Date: Fri, 2 Nov 2012 22:52:42 +0000 Subject: [PATCH] attribute and call_tempalte --- .../impl/handler/xslt_attribute_handler.hpp | 25 +++++++-------- .../handler/xslt_call_template_handler.hpp | 31 ++++++++++--------- .../handler/xslt_item_container_handler.hpp | 4 +-- include/XSLT/impl/xslt_attribute.hpp | 24 +++++++------- include/XSLT/impl/xslt_call_template.hpp | 8 +++-- 5 files changed, 48 insertions(+), 44 deletions(-) diff --git a/include/XSLT/impl/handler/xslt_attribute_handler.hpp b/include/XSLT/impl/handler/xslt_attribute_handler.hpp index f0929f57..2fe964c3 100644 --- a/include/XSLT/impl/handler/xslt_attribute_handler.hpp +++ b/include/XSLT/impl/handler/xslt_attribute_handler.hpp @@ -9,34 +9,33 @@ namespace Arabica namespace XSLT { -class AttributeHandler : public ItemContainerHandler +template +class AttributeHandler : public ItemContainerHandler > { public: - AttributeHandler(CompilationContext& context) : - ItemContainerHandler(context) + AttributeHandler(CompilationContext& context) : + ItemContainerHandler >(context) { } // AttributeHandler protected: - virtual Attribute* createContainer(const std::string& /* namespaceURI */, - const std::string& /* localName */, - const std::string& qName, - const SAX::Attributes& atts) + virtual Attribute* 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 }, { "namespace", false, "", 0 }, { 0, false, 0, 0 } }; - std::map attrs = gatherAttributes(qName, atts, rules); + std::map attrs = gatherAttributes(qName, atts, rules); - Arabica::XPath::XPathExpressionPtr name = context().xpath_attribute_value_template(attrs["name"]); + Arabica::XPath::XPathExpressionPtr name = context().xpath_attribute_value_template(attrs["name"]); if(attrs["namespace"] == "") - return new Attribute(name, - context().inScopeNamespaces()); + return new Attribute(name, context().inScopeNamespaces()); - return new Attribute(name, - context().xpath_attribute_value_template(attrs["namespace"])); + return new Attribute(name, context().xpath_attribute_value_template(attrs["namespace"])); } // createContainer }; // class AttributeHandler diff --git a/include/XSLT/impl/handler/xslt_call_template_handler.hpp b/include/XSLT/impl/handler/xslt_call_template_handler.hpp index dbb88151..ac9a2338 100644 --- a/include/XSLT/impl/handler/xslt_call_template_handler.hpp +++ b/include/XSLT/impl/handler/xslt_call_template_handler.hpp @@ -9,30 +9,31 @@ namespace Arabica namespace XSLT { -class CallTemplateHandler : public SAX::DefaultHandler +template +class CallTemplateHandler : public SAX::DefaultHandler { public: - CallTemplateHandler(CompilationContext& context) : + CallTemplateHandler(CompilationContext& context) : context_(context), callTemplate_(0) { } // CallTemplateHandler - 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(callTemplate_ == 0) { static const ValueRule rules[] = { { "name", true, 0, 0 }, { 0, false, 0, 0 } }; - std::map attrs = gatherAttributes(qName, atts, rules); + std::map attrs = gatherAttributes(qName, atts, rules); - std::string name = context_.processInternalQName(attrs["name"]).clarkName(); + string_type name = context_.processInternalQName(attrs["name"]).clarkName(); - callTemplate_ = new CallTemplate(name); + callTemplate_ = new CallTemplate(name); return; } // if(callTemplate_ == 0) @@ -50,21 +51,21 @@ public: throw SAX::SAXException("xsl:call-template 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(callTemplate_); context_.pop(); } // endElement - virtual void characters(const std::string& /* ch */) + virtual void characters(const string_type& /* ch */) { } // characters private: - CompilationContext& context_; - CallTemplate* callTemplate_; + CompilationContext& context_; + CallTemplate* callTemplate_; }; // class CallTemplateHandler } // 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 6abc1907..d4fdfa4e 100644 --- a/include/XSLT/impl/handler/xslt_item_container_handler.hpp +++ b/include/XSLT/impl/handler/xslt_item_container_handler.hpp @@ -140,8 +140,8 @@ const ChildElement* AllowedChildren() { { "apply-imports", CreateHandler }, { "apply-templates", CreateHandler }, - { "attribute", CreateHandler }, - { "call-template", CreateHandler }, + { "attribute", CreateHandler > > }, + { "call-template", CreateHandler > > }, { "choose", CreateHandler > > }, { "comment", CreateHandler > > }, { "copy", CreateHandler }, diff --git a/include/XSLT/impl/xslt_attribute.hpp b/include/XSLT/impl/xslt_attribute.hpp index bdddb2f9..8211387f 100644 --- a/include/XSLT/impl/xslt_attribute.hpp +++ b/include/XSLT/impl/xslt_attribute.hpp @@ -8,18 +8,19 @@ namespace Arabica namespace XSLT { +template class Attribute : public ItemContainer { public: - Attribute(const Arabica::XPath::XPathExpressionPtr& name, - const Arabica::XPath::XPathExpressionPtr& name_space) : + Attribute(const Arabica::XPath::XPathExpressionPtr& name, + const Arabica::XPath::XPathExpressionPtr& name_space) : name_(name), namespace_(name_space) { } // Attribute - Attribute(const Arabica::XPath::XPathExpressionPtr& name, - const std::map& namespaces) : + Attribute(const Arabica::XPath::XPathExpressionPtr& name, + const std::map& namespaces) : name_(name), namespaces_(namespaces) { @@ -27,13 +28,14 @@ public: virtual ~Attribute() { } - virtual void execute(const DOM::Node& node, ExecutionContext& context) const + virtual void execute(const DOM::Node& node, + ExecutionContext& context) const { - std::string name = name_->evaluateAsString(node, context.xpathContext()); + string_type name = name_->evaluateAsString(node, context.xpathContext()); if(name.empty()) throw SAX::SAXException("xsl:attribute name attribute must evaluate to a valid element name"); - std::string namesp; + string_type namesp; if(namespace_ != 0) namesp = namespace_->evaluateAsString(node, context.xpathContext()); @@ -42,7 +44,7 @@ public: QName qn = QName::create(name); if(!qn.prefix.empty()) { - std::map::const_iterator ns = namespaces_.find(qn.prefix); + std::map::const_iterator ns = namespaces_.find(qn.prefix); if(ns == namespaces_.end()) throw SAX::SAXException("xsl:attribute Runtime Error - Undeclared prefix " + qn.prefix); namesp = ns->second; @@ -56,9 +58,9 @@ public: } // execute private: - Arabica::XPath::XPathExpressionPtr name_; - Arabica::XPath::XPathExpressionPtr namespace_; - std::map namespaces_; + Arabica::XPath::XPathExpressionPtr name_; + Arabica::XPath::XPathExpressionPtr namespace_; + std::map namespaces_; }; // class Attribute } // namespace XSLT diff --git a/include/XSLT/impl/xslt_call_template.hpp b/include/XSLT/impl/xslt_call_template.hpp index 8f18889c..a82f5ee7 100644 --- a/include/XSLT/impl/xslt_call_template.hpp +++ b/include/XSLT/impl/xslt_call_template.hpp @@ -9,23 +9,25 @@ namespace Arabica namespace XSLT { +template class CallTemplate : public Item, public WithParamable { public: - CallTemplate(const std::string& name) : + CallTemplate(const string_type& name) : name_(name) { } // CallTemplate - 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); context.stylesheet().callTemplate(name_, node, context); } // execute private: - const std::string name_; + const string_type name_; }; // class CallTemplate } // namespace XSLT