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

103 lines
3.2 KiB
C++
Raw Normal View History

2007-07-19 19:01:42 +02:00
#ifndef ARABICA_XSLT_APPLY_TEMPLATES_HANDLER_HPP
#define ARABICA_XSLT_APPLY_TEMPLATES_HANDLER_HPP
#include "../xslt_apply_templates.hpp"
#include "xslt_sort_handler.hpp"
#include "xslt_with_param_handler.hpp"
namespace Arabica
{
namespace XSLT
{
2012-11-04 23:34:40 +01:00
template<class stringT, class adaptorT>
class ApplyTemplatesHandler : public SAX::DefaultHandler<stringT, adaptorT>
2007-07-19 19:01:42 +02:00
{
public:
2012-11-04 23:34:40 +01:00
typedef stringT string_type;
typedef adaptorT string_adaptor;
2012-11-03 10:54:07 +01:00
ApplyTemplatesHandler(CompilationContext<string_type, string_adaptor>& context) :
2007-07-19 19:01:42 +02:00
context_(context),
applyTemplates_(0)
{
} // ApplyTemplatesHandler
2012-11-03 10:54:07 +01: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 19:01:42 +02:00
{
if(applyTemplates_ == 0)
{
2010-01-10 22:25:35 +01:00
static const ValueRule rules[] = { { "select", false, 0, 0 },
{ "mode", false, 0, 0 },
{ 0, false, 0, 0} };
2012-11-03 10:54:07 +01:00
std::map<string_type, string_type> attrs = gatherAttributes(qName, atts, rules);
2007-07-19 19:01:42 +02:00
2012-11-03 10:54:07 +01:00
const string_type& select = attrs["select"];
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> xpath;
2007-07-19 19:01:42 +02:00
if(select != "")
xpath = context_.xpath_expression(select);
2007-07-19 19:01:42 +02:00
2012-11-03 10:54:07 +01:00
string_type mode;
2007-10-26 21:12:27 +02:00
if(attrs["mode"] != "")
mode = context_.processInternalQName(attrs["mode"]).clarkName();
2012-11-03 10:54:07 +01:00
applyTemplates_ = new ApplyTemplates<string_type, string_adaptor>(xpath, mode);
2007-07-19 19:01:42 +02:00
return;
} // if(applyTemplates_ == 0)
if(namespaceURI == StylesheetConstant::NamespaceURI())
{
if(localName == "sort")
{
context_.push(0,
new SortHandler(context_, *applyTemplates_),
namespaceURI,
localName,
qName,
2007-07-19 19:01:42 +02:00
atts);
return;
} // if(localName == "sort")
if(localName == "with-param")
{
context_.push(0,
new WithParamHandler(context_, *applyTemplates_),
namespaceURI,
localName,
qName,
2007-07-19 19:01:42 +02:00
atts);
return;
} // if(localName == "sort")
} // if ...
throw SAX::SAXException("xsl:apply-templates can only contain xsl:sort and xsl:with-param elements.");
} // startElement
2012-11-03 10:54:07 +01:00
virtual void endElement(const string_type& /* namespaceURI */,
const string_type& /* localName */,
const string_type& /* qName */)
2007-07-19 19:01:42 +02:00
{
context_.parentContainer().add_item(applyTemplates_);
context_.pop();
} // endElement
2012-11-03 10:54:07 +01:00
virtual void characters(const string_type& ch)
2007-07-19 19:01:42 +02:00
{
verifyNoCharacterData(ch, "xsl:apply-templates");
2007-07-19 19:01:42 +02:00
} // characters
private:
2012-11-03 10:54:07 +01:00
CompilationContext<string_type, string_adaptor>& context_;
ApplyTemplates<string_type, string_adaptor>* applyTemplates_;
2007-07-19 19:01:42 +02:00
}; // class ApplyTemplatesHandler
} // namespace XSLT
} // namespace Arabica
#endif // ARABICA_XSLT_APPLY_TEMPLATES_HANDLER_HPP