arabica/include/XSLT/impl/handler/xslt_call_template_handler.hpp

79 lines
2.5 KiB
C++
Raw Normal View History

2007-07-19 17:01:42 +00:00
#ifndef ARABICA_XSLT_CALL_TEMPLATE_HANDLER_HPP
#define ARABICA_XSLT_CALL_TEMPLATE_HANDLER_HPP
#include "../xslt_call_template.hpp"
#include "xslt_with_param_handler.hpp"
namespace Arabica
{
namespace XSLT
{
2012-11-04 22:34:40 +00:00
template<class stringT, class adaptorT>
class CallTemplateHandler : public SAX::DefaultHandler<stringT, adaptorT>
2007-07-19 17:01:42 +00:00
{
public:
2012-11-04 22:34:40 +00:00
typedef stringT string_type;
typedef adaptorT string_adaptor;
2012-11-02 22:52:42 +00:00
CallTemplateHandler(CompilationContext<string_type, string_adaptor>& context) :
2007-07-19 17:01:42 +00:00
context_(context),
callTemplate_(0)
{
} // CallTemplateHandler
2012-11-02 22:52:42 +00:00
virtual void startElement(const string_type& namespaceURI,
const string_type& localName,
const string_type& qName,
const SAX::Attributes<string_type, string_adaptor>& atts)
2007-07-19 17:01:42 +00:00
{
if(callTemplate_ == 0)
{
2010-01-10 21:25:35 +00:00
static const ValueRule rules[] = { { "name", true, 0, 0 },
{ 0, false, 0, 0 } };
2007-10-26 12:28:48 +00:00
2012-11-02 22:52:42 +00:00
std::map<string_type, string_type> attrs = gatherAttributes(qName, atts, rules);
2007-10-26 12:28:48 +00:00
2012-11-02 22:52:42 +00:00
string_type name = context_.processInternalQName(attrs["name"]).clarkName();
2007-07-19 17:01:42 +00:00
2012-11-02 22:52:42 +00:00
callTemplate_ = new CallTemplate<string_type, string_adaptor>(name);
2007-07-19 17:01:42 +00:00
return;
} // if(callTemplate_ == 0)
2012-11-09 19:17:13 +00:00
if((namespaceURI == StylesheetConstant<string_type, string_adaptor>::NamespaceURI()) && (localName == "with-param"))
2007-07-19 17:01:42 +00:00
{
context_.push(0,
2012-11-06 08:11:27 +00:00
new WithParamHandler<string_type, string_adaptor>(context_, *callTemplate_),
2007-07-19 17:01:42 +00:00
namespaceURI,
localName,
qName,
2007-07-19 17:01:42 +00:00
atts);
return;
} // if(localName == "with-param")
2010-05-19 20:22:22 +01:00
throw SAX::SAXException("xsl:call-template can only contain xsl:sort and xsl:with-param elements.");
2007-07-19 17:01:42 +00:00
} // startElement
2012-11-02 22:52:42 +00:00
virtual void endElement(const string_type& /* namespaceURI */,
const string_type& /* localName */,
const string_type& /* qName */)
2007-07-19 17:01:42 +00:00
{
context_.parentContainer().add_item(callTemplate_);
context_.pop();
} // endElement
2012-11-02 22:52:42 +00:00
virtual void characters(const string_type& /* ch */)
2007-07-19 17:01:42 +00:00
{
} // characters
private:
2012-11-02 22:52:42 +00:00
CompilationContext<string_type, string_adaptor>& context_;
CallTemplate<string_type, string_adaptor>* callTemplate_;
2007-07-19 17:01:42 +00:00
}; // class CallTemplateHandler
} // namespace XSLT
} // namespace Arabica
#endif // ARABICA_XSLT_CALL_TEMPLATE_HANDLER_HPP