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

90 lines
3.5 KiB
C++
Raw Normal View History

2007-07-19 19:01:42 +02:00
#ifndef ARABICA_XSLT_INLINE_ELEMENT_HANDLER_HPP
#define ARABICA_XSLT_INLINE_ELEMENT_HANDLER_HPP
#include "../xslt_inline_element.hpp"
#include "xslt_item_container_handler.hpp"
#include "xslt_constants.hpp"
2007-07-19 19:01:42 +02:00
namespace Arabica
{
namespace XSLT
{
2012-11-04 18:22:47 +01:00
template<class string_type, class string_adaptor>
class InlineElementHandler : public ItemContainerHandler<InlineElement<string_type, string_adaptor> >
2007-07-19 19:01:42 +02:00
{
public:
2012-11-04 18:22:47 +01:00
InlineElementHandler(CompilationContext<string_type, string_adaptor>& context) :
ItemContainerHandler<InlineElement<string_type, string_adaptor> >(context)
2007-07-19 19:01:42 +02:00
{
} // InlineElementHandler
protected:
2012-11-04 18:22:47 +01:00
virtual InlineElement<string_type, string_adaptor>* 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-04 18:22:47 +01:00
std::vector<InlineAttribute<string_type, string_adaptor> > inlineAtts;
2010-01-10 23:02:43 +01:00
for(int i = 0; i != atts.getLength(); ++i)
2007-07-19 19:01:42 +02:00
{
if(atts.getQName(i).find("xmlns:") == 0)
continue;
if(atts.getURI(i) == StylesheetConstant::NamespaceURI())
continue;
2007-07-19 19:01:42 +02:00
if(!context().isRemapped(atts.getURI(i)))
2012-11-04 18:22:47 +01:00
inlineAtts.push_back(InlineAttribute<string_type, string_adaptor>(atts.getQName(i),
atts.getURI(i),
context().xpath_attribute_value_template(atts.getValue(i))));
2007-07-19 19:01:42 +02:00
else
{
2012-11-04 18:22:47 +01:00
std::pair<string_type, string_type> remap = context().remappedNamespace(atts.getURI(i));
if(remap.first.empty() && !remap.second.empty())
remap.first = context().autoNamespacePrefix();
2012-11-04 18:22:47 +01:00
string_type name = remap.first + ":" + atts.getLocalName(i);
inlineAtts.push_back(InlineAttribute<string_type, string_adaptor>(name,
remap.second,
context().xpath_attribute_value_template(atts.getValue(i))));
2007-07-19 19:01:42 +02:00
} // if ...
} // for ...
if(!context().isRemapped(namespaceURI))
2012-11-04 18:22:47 +01:00
return new InlineElement<string_type, string_adaptor>(qName, namespaceURI, inlineAtts);
2007-07-19 19:01:42 +02:00
2012-11-04 18:22:47 +01:00
const std::pair<string_type, string_type>& remap = context().remappedNamespace(namespaceURI);
string_type name = remap.first + ":" + localName;
return new InlineElement<string_type, string_adaptor>(name, remap.second, inlineAtts);
2007-07-19 19:01:42 +02:00
} // createContainer
}; // class InlineElementHandler
2012-11-04 18:22:47 +01:00
template<class string_type, class string_adaptor>
class LREStylesheetHandler : public InlineElementHandler<string_type, string_adaptor>
{
2012-11-04 18:22:47 +01:00
typedef InlineElementHandler<string_type, string_adaptor> baseT;
public:
2012-11-04 18:22:47 +01:00
LREStylesheetHandler(CompilationContext<string_type, string_adaptor>& context, Template* lreStylesheet) :
baseT(context),
lreStylesheet_(lreStylesheet)
{
} // LREStylesheetHandler
2012-11-04 18:22:47 +01:00
virtual void endElement(const string_type& namespaceURI,
const string_type& localName,
const string_type& qName)
{
2012-11-04 18:22:47 +01:00
baseT::context().stylesheet().add_template(lreStylesheet_);
baseT::endElement(namespaceURI, localName, qName);
} // endElement
private:
Template* lreStylesheet_;
}; // class LREStylesheetHandler
2007-07-19 19:01:42 +02:00
} // namespace XSLT
} // namespace Arabica
#endif