arabica/include/XSLT/impl/xslt_apply_templates.hpp

61 lines
1.7 KiB
C++
Raw Normal View History

2007-07-19 19:01:42 +02:00
#ifndef ARABICA_XSLT_APPLY_TEMPLATES_HPP
#define ARABICA_XSLT_APPLY_TEMPLATES_HPP
#include "xslt_stylesheet.hpp"
#include "xslt_sort.hpp"
#include "xslt_with_param.hpp"
namespace Arabica
{
namespace XSLT
{
class ApplyTemplates : public Item,
public Sortable,
public WithParamable
{
public:
ApplyTemplates(Arabica::XPath::XPathExpressionPtr<std::string> select,
2007-10-26 21:12:27 +02:00
const std::pair<std::string, std::string>& mode) :
2007-07-19 19:01:42 +02:00
select_(select),
mode_(mode)
{
} // ApplyTemplates
virtual void execute(const DOM::Node<std::string>& node, ExecutionContext& context) const
{
ParamPasser passer(*this, node, context);
2007-07-19 19:01:42 +02:00
if(!has_sort() && select_ == 0)
{
if(node.hasChildNodes())
context.stylesheet().applyTemplates(node.getChildNodes(), context, mode_);
return;
}
Arabica::XPath::NodeSet<std::string> nodes;
if(select_ == 0)
for(DOM::Node<std::string> n = node.getFirstChild(); n != 0; n = n.getNextSibling())
nodes.push_back(n);
else
2007-08-22 14:23:38 +02:00
{
Arabica::XPath::XPathValuePtr<std::string> value = select_->evaluate(node, context.xpathContext());
if(value->type() != Arabica::XPath::NODE_SET)
throw std::runtime_error("apply-templates select expression is not a node-set");
nodes = value->asNodeSet();
}
2007-07-19 19:01:42 +02:00
sort(node, nodes, context);
context.stylesheet().applyTemplates(nodes, context, mode_);
} // execute
private:
Arabica::XPath::XPathExpressionPtr<std::string> select_;
2007-10-26 21:12:27 +02:00
const std::pair<std::string, std::string> mode_;
2007-07-19 19:01:42 +02:00
}; // class ApplyTemplates
} // namespace XSLT
} // namespace Arabica
#endif // ARABICA_XSLT_APPLY_TEMPLATES_HPP