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

72 lines
2.3 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
{
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
{
2010-01-10 23:02:43 +01:00
static const ValueRule rules[] = { { "select", true, 0, 0 },
{ 0, false, 0, 0 } };
2012-11-03 10:37:13 +01:00
string_type select = gatherAttributes(qName, atts, rules)["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::NamespaceURI()) &&
(localName == "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