2007-07-19 19:01:42 +02:00
|
|
|
#ifndef XSLT_FOR_EACH_HPP
|
|
|
|
#define XSLT_FOR_EACH_HPP
|
|
|
|
|
|
|
|
#include "xslt_item.hpp"
|
|
|
|
#include "xslt_sort.hpp"
|
|
|
|
|
|
|
|
namespace Arabica
|
|
|
|
{
|
|
|
|
namespace XSLT
|
|
|
|
{
|
|
|
|
|
2012-11-04 23:34:40 +01:00
|
|
|
template<class stringT, class adaptorT>
|
2012-11-08 17:18:49 +01:00
|
|
|
class ForEach : public ItemContainer<stringT, adaptorT>,
|
2012-11-05 10:18:08 +01:00
|
|
|
public Sortable<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-06 08:50:57 +01:00
|
|
|
typedef Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> XPathExpressionPtr;
|
|
|
|
typedef Arabica::XPath::XPathValue<string_type, string_adaptor> XPathValue;
|
|
|
|
typedef Arabica::XPath::NodeSet<string_type, string_adaptor> NodeSet;
|
|
|
|
typedef DOM::Node<string_type, string_adaptor> DOMNode;
|
|
|
|
|
|
|
|
ForEach(const XPathExpressionPtr& select) :
|
2012-11-05 10:22:05 +01:00
|
|
|
Sortable<stringT, adaptorT>(),
|
2007-07-19 19:01:42 +02:00
|
|
|
select_(select)
|
|
|
|
{
|
|
|
|
} // ForEach
|
|
|
|
|
|
|
|
virtual ~ForEach()
|
|
|
|
{
|
|
|
|
} // ForEach
|
|
|
|
|
2012-11-06 08:50:57 +01:00
|
|
|
virtual void execute(const DOMNode& node,
|
2012-11-08 18:13:33 +01:00
|
|
|
ExecutionContext<string_type, string_adaptor>& context) const
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
2012-11-06 08:50:57 +01:00
|
|
|
XPathValue sel = select_->evaluate(node, context.xpathContext());
|
2007-11-22 22:54:51 +01:00
|
|
|
if(sel.type() != Arabica::XPath::NODE_SET)
|
|
|
|
throw SAX::SAXException("xsl:for-each must select a node set");
|
|
|
|
|
2012-11-06 08:50:57 +01:00
|
|
|
NodeSet nodes = sel.asNodeSet();
|
2013-01-05 22:26:35 +01:00
|
|
|
this->sort(node, nodes, context);
|
2007-07-19 19:01:42 +02:00
|
|
|
|
2012-11-08 18:13:33 +01:00
|
|
|
LastFrame<string_type, string_adaptor> last(context, nodes.size());
|
2007-07-19 19:01:42 +02:00
|
|
|
for(size_t n = 0, e = nodes.size(); n != e; ++n)
|
|
|
|
{
|
2012-11-08 18:13:33 +01:00
|
|
|
ChainStackFrame<string_type, string_adaptor> frame(context);
|
2007-07-19 19:01:42 +02:00
|
|
|
context.setPosition(nodes[n], n+1);
|
2013-01-05 22:26:35 +01:00
|
|
|
this->execute_children(nodes[n], context);
|
2007-07-19 19:01:42 +02:00
|
|
|
} // for ...
|
|
|
|
} // execute
|
|
|
|
|
|
|
|
private:
|
2012-11-06 08:50:57 +01:00
|
|
|
XPathExpressionPtr select_;
|
2007-07-19 19:01:42 +02:00
|
|
|
}; // class ForEach
|
|
|
|
|
|
|
|
} // namespace XSLT
|
|
|
|
} // namespace Arabica
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|