arabica/include/XSLT/impl/xslt_for_each.hpp

63 lines
1.6 KiB
C++
Raw Normal View History

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,
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-03 10:37:13 +01:00
ExecutionContext& 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());
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();
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)
{
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-06 08:50:57 +01:00
XPathExpressionPtr select_;
2007-07-19 19:01:42 +02:00
}; // class ForEach
} // namespace XSLT
} // namespace Arabica
#endif