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
|
|
|
{
|
2012-11-12 22:46:08 +01:00
|
|
|
typedef StylesheetConstant<stringT, adaptorT> SC;
|
2012-11-15 23:03:42 +01:00
|
|
|
typedef AttributeValidators<stringT, adaptorT> AV;
|
2012-11-12 22:46:08 +01:00
|
|
|
|
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)
|
|
|
|
{
|
2012-11-15 23:03:42 +01:00
|
|
|
static const AV rules = AV::rule(SC::select, false)
|
|
|
|
.rule(SC::mode, false);
|
|
|
|
|
|
|
|
std::map<string_type, string_type> attrs = rules.gather(qName, atts);
|
2007-07-19 19:01:42 +02:00
|
|
|
|
2012-11-12 22:46:08 +01:00
|
|
|
const string_type& select = attrs[SC::select];
|
2012-11-03 10:54:07 +01:00
|
|
|
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> xpath;
|
2012-11-12 22:46:08 +01:00
|
|
|
if(select != string_adaptor::empty_string())
|
2007-11-22 18:50:25 +01:00
|
|
|
xpath = context_.xpath_expression(select);
|
2007-07-19 19:01:42 +02:00
|
|
|
|
2012-11-03 10:54:07 +01:00
|
|
|
string_type mode;
|
2012-11-12 22:46:08 +01:00
|
|
|
if(attrs[SC::mode] != string_adaptor::empty_string())
|
|
|
|
mode = context_.processInternalQName(attrs[SC::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)
|
|
|
|
|
2012-11-12 22:46:08 +01:00
|
|
|
if(namespaceURI == StylesheetConstant<string_type, string_adaptor>::NamespaceURI)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
2012-11-12 22:46:08 +01:00
|
|
|
if(localName == SC::sort)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
context_.push(0,
|
2012-11-05 10:18:08 +01:00
|
|
|
new SortHandler<string_type, string_adaptor>(context_, *applyTemplates_),
|
2007-07-19 19:01:42 +02:00
|
|
|
namespaceURI,
|
|
|
|
localName,
|
2009-04-24 20:02:14 +02:00
|
|
|
qName,
|
2007-07-19 19:01:42 +02:00
|
|
|
atts);
|
|
|
|
return;
|
|
|
|
} // if(localName == "sort")
|
|
|
|
|
2012-11-12 22:46:08 +01:00
|
|
|
if(localName == SC::with_param)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
|
|
|
context_.push(0,
|
2012-11-06 09:11:27 +01:00
|
|
|
new WithParamHandler<string_type, string_adaptor>(context_, *applyTemplates_),
|
2007-07-19 19:01:42 +02:00
|
|
|
namespaceURI,
|
|
|
|
localName,
|
2009-04-24 20:02:14 +02:00
|
|
|
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
|
|
|
{
|
2012-11-12 22:46:08 +01:00
|
|
|
verifyNoCharacterData<string_type, string_adaptor>(ch, SC::apply_templates);
|
2007-07-19 19:01:42 +02:00
|
|
|
} // characters
|
|
|
|
|
|
|
|
private:
|
2012-11-12 22:46:08 +01:00
|
|
|
CompilationContext<string_type>& context_;
|
2012-11-03 10:54:07 +01:00
|
|
|
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
|
|
|
|
|