arabica/include/XSLT/impl/handler/xslt_variable_handler.hpp

95 lines
2.9 KiB
C++
Raw Normal View History

2007-07-19 19:01:42 +02:00
#ifndef ARABICA_XSLT_VARIABLES_HANDLER_HPP
#define ARABICA_XSLT_VARIABLES_HANDLER_HPP
#include "../xslt_param.hpp"
#include "../xslt_variable.hpp"
#include "xslt_item_container_handler.hpp"
namespace Arabica
{
namespace XSLT
{
template<class VType>
class VariableHandler : public ItemContainerHandler<VType>
{
public:
VariableHandler(CompilationContext<std::string>& context) :
ItemContainerHandler<VType>(context),
has_select_(false),
precedence_(Precedence::FrozenPrecedence())
{
} // VariableHandler
VariableHandler(CompilationContext<std::string>& context, const Precedence& precedence) :
ItemContainerHandler<VType>(context),
has_select_(false),
precedence_(precedence)
2007-07-19 19:01:42 +02:00
{
} // VariableHandler
protected:
2010-01-11 10:02:17 +01:00
virtual VType* createContainer(const std::string& /* namespaceURI */,
const std::string& /* localName */,
2007-07-19 19:01:42 +02:00
const std::string& qName,
const SAX::Attributes<std::string>& atts)
2007-07-19 19:01:42 +02:00
{
2010-01-11 10:02:17 +01:00
static const ValueRule rules[] = { { "name", true, 0, 0 },
{ "select", false, 0, 0 },
{ 0, false, 0, 0 } };
2007-07-19 19:01:42 +02:00
std::map<std::string, std::string> attrs = gatherAttributes(qName, atts, rules);
const std::string& select = atts.getValue("select");
Arabica::XPath::XPathExpressionPtr<std::string> xpath;
if(select != "")
{
xpath = this->context().xpath_expression(select);
has_select_ = true;
} // if ...
2007-07-19 19:01:42 +02:00
std::string name = this->context().processInternalQName(attrs["name"]).clarkName();
return new VType(name, xpath, precedence_);
2007-07-19 19:01:42 +02:00
} // createContainer
virtual void characters(const std::string& ch)
{
if(has_select_)
{
for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i)
2008-08-05 16:32:40 +02:00
if(!Arabica::XML::is_space(*i))
throw SAX::SAXException("A variable or param can not have both a select attribute and text context");
}
ItemContainerHandler<VType>::characters(ch);
} // characters
private:
bool has_select_;
const Precedence precedence_;
2007-07-19 19:01:42 +02:00
}; // class VariableHandler
template<class VType>
class TopLevelVariableHandler : public VariableHandler<VType>
{
public:
TopLevelVariableHandler(CompilationContext<std::string>& context) :
VariableHandler<VType>(context, context.precedence())
2007-07-19 19:01:42 +02:00
{
} // VariableHandler
2010-01-11 10:02:17 +01:00
virtual void endElement(const std::string& /* namespaceURI */,
const std::string& /* localName */,
const std::string& /* qName */)
2007-07-19 19:01:42 +02:00
{
this->context().stylesheet().add_variable(this->container());
2007-07-19 19:01:42 +02:00
this->context().pop();
} // endElement
}; // class TopLevelVariableHandler
} // namespace XSLT
} // namespace Arabica
#endif