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

69 lines
2 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
{
class ForEachHandler : public ItemContainerHandler<ForEach>
{
public:
ForEachHandler(CompilationContext<std::string>& context) :
2007-07-19 19:01:42 +02:00
ItemContainerHandler<ForEach>(context),
done_sort_(false)
{
} // ForEachHandler
protected:
2010-01-10 23:02:43 +01:00
virtual ForEach* createContainer(const std::string& /* namespaceURI */,
const std::string& /* localName */,
2007-07-19 19:01:42 +02:00
const std::string& qName,
const SAX::Attributes<std::string>& 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 } };
2007-07-19 19:01:42 +02:00
std::string select = gatherAttributes(qName, atts, rules)["select"];
return new ForEach(context().xpath_expression(select));
2007-07-19 19:01:42 +02:00
} // createContainer
virtual bool createChild(const std::string& namespaceURI,
const std::string& localName,
const std::string& qName,
const SAX::Attributes<std::string>& 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_)
{
context().push(0,
new SortHandler(context(), *container()),
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;
return ItemContainerHandler<ForEach>::createChild(namespaceURI, localName, qName, atts);
} // createChild
private:
bool done_sort_;
}; // class ForEachHandler
} // namespace XSLT
} // namespace Arabica
#endif