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>
|
|
|
|
{
|
2012-11-12 22:46:08 +01:00
|
|
|
typedef StylesheetConstant<string_type, string_adaptor> SC;
|
2007-07-19 19:01:42 +02:00
|
|
|
public:
|
2012-11-09 20:17:13 +01:00
|
|
|
typedef typename VType::string_type string_type;
|
|
|
|
typedef typename VType::string_adaptor string_adaptor;
|
|
|
|
typedef ItemContainerHandler<VType> baseT;
|
|
|
|
|
|
|
|
VariableHandler(CompilationContext<string_type, string_adaptor>& context) :
|
|
|
|
baseT(context),
|
2008-11-19 18:26:07 +01:00
|
|
|
has_select_(false),
|
|
|
|
precedence_(Precedence::FrozenPrecedence())
|
|
|
|
{
|
|
|
|
} // VariableHandler
|
|
|
|
|
2012-11-09 20:17:13 +01:00
|
|
|
VariableHandler(CompilationContext<string_type, string_adaptor>& context, const Precedence& precedence) :
|
|
|
|
baseT(context),
|
2008-11-19 18:26:07 +01:00
|
|
|
has_select_(false),
|
|
|
|
precedence_(precedence)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
|
|
|
} // VariableHandler
|
|
|
|
|
|
|
|
protected:
|
2012-11-09 20:17:13 +01:00
|
|
|
virtual VType* createContainer(const string_type& /* namespaceURI */,
|
|
|
|
const string_type& /* localName */,
|
|
|
|
const string_type& qName,
|
|
|
|
const SAX::Attributes<string_type, string_adaptor>& atts)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
2012-11-12 22:46:08 +01:00
|
|
|
static const ValueRule<string_type> rules[] = { { SC::name, true, 0, 0 },
|
|
|
|
{ SC::select, false, 0, 0 },
|
|
|
|
{ string_adaptor::empty_string(), false, 0, 0 } };
|
2007-07-19 19:01:42 +02:00
|
|
|
|
|
|
|
|
2012-11-09 20:17:13 +01:00
|
|
|
std::map<string_type, string_type> attrs = gatherAttributes(qName, atts, rules);
|
2007-07-19 19:01:42 +02:00
|
|
|
|
2012-11-12 22:46:08 +01:00
|
|
|
const string_type& select = atts.getValue(SC::select);
|
2012-11-09 20:17:13 +01:00
|
|
|
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> xpath;
|
2012-11-12 22:46:08 +01:00
|
|
|
if(select != string_adaptor::empty_string())
|
2008-08-02 23:58:20 +02:00
|
|
|
{
|
2012-11-09 20:17:13 +01:00
|
|
|
xpath = baseT::context().xpath_expression(select);
|
2008-08-02 23:58:20 +02:00
|
|
|
has_select_ = true;
|
|
|
|
} // if ...
|
2007-07-19 19:01:42 +02:00
|
|
|
|
2012-11-12 22:46:08 +01:00
|
|
|
string_type name = baseT::context().processInternalQName(attrs[SC::name]).clarkName();
|
2009-02-24 13:21:35 +01:00
|
|
|
return new VType(name, xpath, precedence_);
|
2007-07-19 19:01:42 +02:00
|
|
|
} // createContainer
|
2008-08-02 23:58:20 +02:00
|
|
|
|
2012-11-09 20:17:13 +01:00
|
|
|
virtual void characters(const string_type& ch)
|
2008-08-02 23:58:20 +02:00
|
|
|
{
|
|
|
|
if(has_select_)
|
|
|
|
{
|
2012-11-09 20:17:13 +01:00
|
|
|
for(string_type::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");
|
2008-08-02 23:58:20 +02:00
|
|
|
}
|
|
|
|
ItemContainerHandler<VType>::characters(ch);
|
|
|
|
} // characters
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool has_select_;
|
2008-11-19 18:26:07 +01:00
|
|
|
const Precedence precedence_;
|
2007-07-19 19:01:42 +02:00
|
|
|
}; // class VariableHandler
|
|
|
|
|
|
|
|
template<class VType>
|
|
|
|
class TopLevelVariableHandler : public VariableHandler<VType>
|
|
|
|
{
|
|
|
|
public:
|
2012-11-09 20:17:13 +01:00
|
|
|
typedef typename VType::string_type string_type;
|
|
|
|
typedef typename VType::string_adaptor string_adaptor;
|
|
|
|
typedef VariableHandler<VType> baseT;
|
|
|
|
|
|
|
|
TopLevelVariableHandler(CompilationContext<string_type, string_adaptor>& context) :
|
|
|
|
baseT(context, context.precedence())
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
|
|
|
} // VariableHandler
|
|
|
|
|
2012-11-09 20:17:13 +01:00
|
|
|
virtual void endElement(const string_type& /* namespaceURI */,
|
|
|
|
const string_type& /* localName */,
|
|
|
|
const string_type& /* qName */)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
2012-11-09 20:17:13 +01:00
|
|
|
baseT::context().stylesheet().add_variable(baseT::container());
|
|
|
|
baseT::context().pop();
|
2007-07-19 19:01:42 +02:00
|
|
|
} // endElement
|
|
|
|
|
|
|
|
}; // class TopLevelVariableHandler
|
|
|
|
|
|
|
|
} // namespace XSLT
|
|
|
|
} // namespace Arabica
|
|
|
|
#endif
|
|
|
|
|