2007-07-19 19:01:42 +02:00
|
|
|
#ifndef ARABICA_XSLT_APPLY_TEMPLATES_HPP
|
|
|
|
#define ARABICA_XSLT_APPLY_TEMPLATES_HPP
|
|
|
|
|
2008-11-05 02:33:28 +01:00
|
|
|
#include "xslt_compiled_stylesheet.hpp"
|
2007-07-19 19:01:42 +02:00
|
|
|
#include "xslt_sort.hpp"
|
|
|
|
#include "xslt_with_param.hpp"
|
|
|
|
|
|
|
|
namespace Arabica
|
|
|
|
{
|
|
|
|
namespace XSLT
|
|
|
|
{
|
|
|
|
|
2012-11-03 10:54:07 +01:00
|
|
|
template<class string_type, class string_adaptor>
|
2007-07-19 19:01:42 +02:00
|
|
|
class ApplyTemplates : public Item,
|
2012-11-05 10:18:08 +01:00
|
|
|
public Sortable<string_type, string_adaptor>,
|
2012-11-06 09:11:27 +01:00
|
|
|
public WithParamable<string_type, string_adaptor>
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
2012-11-05 10:22:05 +01:00
|
|
|
typedef Sortable<string_type, string_adaptor> SortableT;
|
|
|
|
|
2007-07-19 19:01:42 +02:00
|
|
|
public:
|
2012-11-03 10:54:07 +01:00
|
|
|
ApplyTemplates(Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> select,
|
|
|
|
string_type& mode) :
|
2007-07-19 19:01:42 +02:00
|
|
|
select_(select),
|
|
|
|
mode_(mode)
|
|
|
|
{
|
|
|
|
} // ApplyTemplates
|
|
|
|
|
2012-11-03 10:54:07 +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-06 09:11:27 +01:00
|
|
|
ParamPasser<string_type, string_adaptor> passer(*this, node, context);
|
2007-07-19 19:01:42 +02:00
|
|
|
|
2012-11-05 10:22:05 +01:00
|
|
|
if(!SortableT::has_sort() && select_ == 0)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
|
|
|
if(node.hasChildNodes())
|
|
|
|
context.stylesheet().applyTemplates(node.getChildNodes(), context, mode_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-03 10:54:07 +01:00
|
|
|
Arabica::XPath::NodeSet<string_type, string_adaptor> nodes;
|
2007-07-19 19:01:42 +02:00
|
|
|
if(select_ == 0)
|
2012-11-03 10:54:07 +01:00
|
|
|
for(DOM::Node<string_type, string_adaptor> n = node.getFirstChild(); n != 0; n = n.getNextSibling())
|
2007-07-19 19:01:42 +02:00
|
|
|
nodes.push_back(n);
|
|
|
|
else
|
2007-08-22 14:23:38 +02:00
|
|
|
{
|
2012-11-03 10:54:07 +01:00
|
|
|
Arabica::XPath::XPathValue<string_type, string_adaptor> value = select_->evaluate(node, context.xpathContext());
|
2009-02-18 09:37:16 +01:00
|
|
|
if(value.type() != Arabica::XPath::NODE_SET)
|
2007-08-22 14:23:38 +02:00
|
|
|
throw std::runtime_error("apply-templates select expression is not a node-set");
|
2009-02-18 09:37:16 +01:00
|
|
|
nodes = value.asNodeSet();
|
2007-08-22 14:23:38 +02:00
|
|
|
}
|
2007-07-19 19:01:42 +02:00
|
|
|
sort(node, nodes, context);
|
|
|
|
context.stylesheet().applyTemplates(nodes, context, mode_);
|
|
|
|
} // execute
|
|
|
|
|
|
|
|
private:
|
2012-11-03 10:54:07 +01:00
|
|
|
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> select_;
|
|
|
|
string_type mode_;
|
2007-07-19 19:01:42 +02:00
|
|
|
}; // class ApplyTemplates
|
|
|
|
|
|
|
|
} // namespace XSLT
|
|
|
|
} // namespace Arabica
|
|
|
|
|
|
|
|
#endif // ARABICA_XSLT_APPLY_TEMPLATES_HPP
|
|
|
|
|