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>
|
2007-07-19 19:01:42 +02:00
|
|
|
class ForEach : public ItemContainer,
|
|
|
|
public Sortable
|
|
|
|
{
|
|
|
|
public:
|
2012-11-04 23:34:40 +01:00
|
|
|
typedef stringT string_type;
|
|
|
|
typedef adaptorT string_adaptor;
|
|
|
|
|
2012-11-03 10:37:13 +01:00
|
|
|
ForEach(const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor>& select) :
|
2007-07-19 19:01:42 +02:00
|
|
|
Sortable(),
|
|
|
|
select_(select)
|
|
|
|
{
|
|
|
|
} // ForEach
|
|
|
|
|
|
|
|
virtual ~ForEach()
|
|
|
|
{
|
|
|
|
} // ForEach
|
|
|
|
|
2012-11-03 10:37:13 +01:00
|
|
|
virtual void execute(const DOM::Node<string_type, string_adaptor>& node,
|
|
|
|
ExecutionContext& context) const
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
2012-11-03 10:37:13 +01:00
|
|
|
Arabica::XPath::XPathValue<string_type, string_adaptor> 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-03 10:37:13 +01:00
|
|
|
Arabica::XPath::NodeSet<string_type, string_adaptor> nodes = sel.asNodeSet();
|
2007-07-19 19:01:42 +02:00
|
|
|
sort(node, nodes, context);
|
|
|
|
|
|
|
|
LastFrame last(context, nodes.size());
|
|
|
|
for(size_t n = 0, e = nodes.size(); n != e; ++n)
|
|
|
|
{
|
2007-11-01 23:28:20 +01:00
|
|
|
ChainStackFrame frame(context);
|
2007-07-19 19:01:42 +02:00
|
|
|
context.setPosition(nodes[n], n+1);
|
|
|
|
execute_children(nodes[n], context);
|
|
|
|
} // for ...
|
|
|
|
} // execute
|
|
|
|
|
|
|
|
private:
|
2012-11-03 10:37:13 +01:00
|
|
|
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> select_;
|
2007-07-19 19:01:42 +02:00
|
|
|
}; // class ForEach
|
|
|
|
|
|
|
|
} // namespace XSLT
|
|
|
|
} // namespace Arabica
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|