2007-07-19 19:01:42 +02:00
|
|
|
#ifndef ARABICA_XSLT_VARIABLE_IMPL_HPP
|
|
|
|
#define ARABICA_XSLT_VARIABLE_IMPL_HPP
|
|
|
|
|
|
|
|
#include <XPath/XPath.hpp>
|
|
|
|
#include <memory>
|
|
|
|
#include "xslt_item.hpp"
|
|
|
|
#include "xslt_execution_context.hpp"
|
|
|
|
|
|
|
|
namespace Arabica
|
|
|
|
{
|
|
|
|
namespace XSLT
|
|
|
|
{
|
|
|
|
|
2012-11-06 21:21:39 +01:00
|
|
|
template<class string_type, class string_adaptor>
|
2012-11-06 21:25:10 +01:00
|
|
|
class Variable_impl : public ItemContainer, public Variable_declaration<string_type, string_adaptor>
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
|
|
|
protected:
|
2012-11-06 21:21:39 +01:00
|
|
|
typedef Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> XPathExpressionPtr;
|
|
|
|
typedef Arabica::XPath::XPathValue<string_type, string_adaptor> XPathValue;
|
|
|
|
typedef Arabica::XPath::StringValue<string_type, string_adaptor> StringValue;
|
|
|
|
typedef Arabica::XPath::NodeSetValue<string_type, string_adaptor> NodeSetValue;
|
|
|
|
typedef Arabica::XPath::NodeSet<string_type, string_adaptor> NodeSet;
|
|
|
|
typedef DOM::Node<string_type, string_adaptor> DOMNode;
|
|
|
|
|
|
|
|
Variable_impl(const string_type& name,
|
|
|
|
const XPathExpressionPtr& select,
|
2008-11-19 18:26:07 +01:00
|
|
|
const Precedence& precedence) :
|
2007-07-19 19:01:42 +02:00
|
|
|
name_(name),
|
2008-11-19 18:26:07 +01:00
|
|
|
select_(select),
|
|
|
|
precedence_(precedence)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
|
|
|
} // Variable_impl
|
|
|
|
|
|
|
|
virtual ~Variable_impl() { }
|
|
|
|
|
|
|
|
public:
|
2012-11-06 21:21:39 +01:00
|
|
|
virtual const string_type& name() const { return name_; }
|
2007-07-19 19:01:42 +02:00
|
|
|
|
2012-11-06 21:21:39 +01:00
|
|
|
virtual XPathValue value(const DOMNode& node,
|
|
|
|
ExecutionContext& context,
|
|
|
|
DOMSink<string_type, string_adaptor>& sink) const
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
|
|
|
if(select_)
|
|
|
|
return select_->evaluate(node, context.xpathContext());
|
|
|
|
|
2009-12-15 00:55:56 +01:00
|
|
|
execute_children(node, context);
|
2007-07-19 19:01:42 +02:00
|
|
|
|
|
|
|
if(sink.node() == 0)
|
2012-11-06 21:21:39 +01:00
|
|
|
return StringValue::createValue("");
|
2007-07-19 19:01:42 +02:00
|
|
|
|
2012-11-06 21:21:39 +01:00
|
|
|
NodeSet nodeset;
|
|
|
|
for(DOMNode n = sink.node().getFirstChild(); n != 0; n = n.getNextSibling())
|
2007-07-19 19:01:42 +02:00
|
|
|
nodeset.push_back(n);
|
|
|
|
|
2012-11-06 21:21:39 +01:00
|
|
|
return NodeSetValue::createValue(nodeset);
|
2007-07-19 19:01:42 +02:00
|
|
|
} // value
|
|
|
|
|
2008-11-19 18:26:07 +01:00
|
|
|
virtual const Precedence& precedence() const { return precedence_; }
|
|
|
|
|
2007-07-19 19:01:42 +02:00
|
|
|
private:
|
2012-11-06 21:21:39 +01:00
|
|
|
string_type name_;
|
|
|
|
XPathExpressionPtr select_;
|
2008-11-19 18:26:07 +01:00
|
|
|
Precedence precedence_;
|
2007-07-19 19:01:42 +02:00
|
|
|
}; // Variable_impl
|
|
|
|
|
|
|
|
} // namespace XSLT
|
|
|
|
} // namespace Arabica
|
|
|
|
#endif // ARABICA_XSLT_VARIABLE_IMPL_HPP
|
|
|
|
|