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

73 lines
2.4 KiB
C++
Raw Normal View History

2007-07-19 19:01:42 +02:00
#ifndef ARABICA_XSLT_FOR_EACH_HANDLER_HPP
#define ARABICA_XSLT_FOR_EACH_HANDLER_HPP
#include "../xslt_for_each.hpp"
#include "xslt_item_container_handler.hpp"
#include "xslt_sort_handler.hpp"
namespace Arabica
{
namespace XSLT
{
2012-11-03 10:37:13 +01:00
template<class string_type, class string_adaptor>
class ForEachHandler : public ItemContainerHandler<ForEach<string_type, string_adaptor> >
2007-07-19 19:01:42 +02:00
{
typedef StylesheetConstant<string_type, string_adaptor> SC;
2012-11-15 23:03:42 +01:00
typedef AttributeValidators<string_type, string_adaptor> AV;
2012-11-03 10:37:13 +01:00
typedef ItemContainerHandler<ForEach<string_type, string_adaptor> > baseT;
2007-07-19 19:01:42 +02:00
public:
2012-11-03 10:37:13 +01:00
ForEachHandler(CompilationContext<string_type, string_adaptor>& context) :
baseT(context),
2007-07-19 19:01:42 +02:00
done_sort_(false)
{
} // ForEachHandler
protected:
2012-11-03 10:37:13 +01:00
virtual ForEach<string_type, string_adaptor>* createContainer(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
{
2012-11-15 23:03:42 +01:00
static const AV rules = AV::rule(SC::select, true);
string_type select = rules.gather(qName, atts)[SC::select];
2007-07-19 19:01:42 +02:00
2012-11-03 10:37:13 +01:00
return new ForEach<string_type, string_adaptor>(baseT::context().xpath_expression(select));
2007-07-19 19:01:42 +02:00
} // createContainer
2012-11-03 10:37:13 +01:00
virtual bool createChild(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((namespaceURI == StylesheetConstant<string_type, string_adaptor>::NamespaceURI) &&
(localName == SC::sort))
2010-01-10 23:02:43 +01:00
{
2007-07-19 19:01:42 +02:00
if(!done_sort_)
{
2012-11-03 10:38:31 +01:00
baseT::context().push(0,
2012-11-05 10:18:08 +01:00
new SortHandler<string_type, string_adaptor>(baseT::context(), *baseT::container()),
2007-07-19 19:01:42 +02:00
namespaceURI,
localName,
qName,
2007-07-19 19:01:42 +02:00
atts);
return true;
}
else
throw SAX::SAXException("xsl:sort must immediately follow xsl:for-each");
2010-01-10 23:02:43 +01:00
} // if ...
2007-07-19 19:01:42 +02:00
done_sort_ = true;
2012-11-03 10:37:13 +01:00
return baseT::createChild(namespaceURI, localName, qName, atts);
2007-07-19 19:01:42 +02:00
} // createChild
private:
bool done_sort_;
}; // class ForEachHandler
} // namespace XSLT
} // namespace Arabica
#endif