arabica/include/XSLT/impl/xslt_element.hpp

77 lines
2.3 KiB
C++
Raw Normal View History

2007-07-19 19:01:42 +02:00
#ifndef ARABICA_XSLT_ELEMENT_HPP
#define ARABICA_XSLT_ELEMENT_HPP
#include "xslt_item.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 Element : public ItemContainer
{
public:
2012-11-04 23:34:40 +01:00
typedef stringT string_type;
typedef adaptorT string_adaptor;
2012-11-04 09:38:48 +01:00
Element(const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor>& name,
const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor>& name_space,
const string_type& use_attribute_sets) :
2007-07-19 19:01:42 +02:00
name_(name),
namespace_(name_space),
use_attribute_sets_(use_attribute_sets)
{
} // Element
2012-11-04 09:38:48 +01:00
Element(const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor>& name,
const std::map<string_type, string_type>& namespaces,
const string_type& use_attribute_sets) :
2007-07-19 19:01:42 +02:00
name_(name),
namespaces_(namespaces),
use_attribute_sets_(use_attribute_sets)
{
} // Element
virtual ~Element() { }
2012-11-04 09:38:48 +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-04 09:38:48 +01:00
string_type name = name_->evaluateAsString(node, context.xpathContext());
if(!Arabica::XML::is_qname<string_adaptor>(name))
2007-07-19 19:01:42 +02:00
throw SAX::SAXException("xsl:element name attribute must evaluate to a valid element name");
2012-11-04 09:38:48 +01:00
string_type namesp;
2007-07-19 19:01:42 +02:00
if(namespace_ != 0)
namesp = namespace_->evaluateAsString(node, context.xpathContext());
else
{
QName qn = QName::create(name);
2012-11-04 14:09:12 +01:00
typename std::map<string_type, string_type>::const_iterator ns = namespaces_.find(qn.prefix);
if(ns == namespaces_.end())
throw SAX::SAXException("xsl:element Runtime Error - Undeclared prefix " + qn.prefix);
namesp = ns->second;
2007-07-19 19:01:42 +02:00
} // if ...
if(context.sink().start_element(name, namesp))
{
ChainStackFrame frame(context);
2007-07-19 19:01:42 +02:00
execute_children(node, context);
context.sink().end_element(name, namesp);
}
} // execute
private:
2012-11-04 09:38:48 +01:00
const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> name_;
const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> namespace_;
const std::map<string_type, string_type> namespaces_;
const string_type use_attribute_sets_;
2007-07-19 19:01:42 +02:00
}; // class Element
} // namespace XSLT
} // namespace Arabica
#endif