arabica/include/XSLT/impl/xslt_processing_instruction.hpp

72 lines
2 KiB
C++
Raw Normal View History

2007-07-19 19:01:42 +02:00
#ifndef ARABICA_XSLT_PROCESSING_INSTRUCTION_HPP
#define ARABICA_XSLT_PROCESSING_INSTRUCTION_HPP
#include <XML/strings.hpp>
#include <text/UnicodeCharacters.hpp>
2007-07-19 19:01:42 +02:00
#include "xslt_item.hpp"
namespace Arabica
{
namespace XSLT
{
2012-11-04 23:34:40 +01:00
template<class stringT, class adaptorT>
2012-11-08 17:18:49 +01:00
class ProcessingInstruction : public ItemContainer<stringT, adaptorT>
2007-07-19 19:01:42 +02:00
{
public:
2012-11-04 23:34:40 +01:00
typedef stringT string_type;
typedef adaptorT string_adaptor;
2012-11-04 14:04:08 +01:00
ProcessingInstruction(const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor>& name) :
2007-07-19 19:01:42 +02:00
name_(name)
{
} // ProcessingInstruction
virtual ~ProcessingInstruction() { }
2012-11-08 18:13:33 +01:00
virtual void execute(const DOM::Node<string_type, string_adaptor>& node, ExecutionContext<string_type, string_adaptor>& context) const
2007-07-19 19:01:42 +02:00
{
2012-11-04 14:04:08 +01:00
string_type name = name_->evaluateAsString(node, context.xpathContext());
validate_name(name);
2007-07-19 19:01:42 +02:00
context.sink().start_processing_instruction(name);
execute_children(node, context);
context.sink().end_processing_instruction();
} // execute
private:
2012-11-04 14:04:08 +01:00
void validate_name(const string_type& name) const
{
if(name.empty())
throw SAX::SAXException("xsl:processing-instruction : name attribute must evaluate to a valid name");
2012-11-04 14:04:08 +01:00
if(!Arabica::XML::is_ncname<string_adaptor>(name))
throw SAX::SAXException("xsl:processing-instruction : '" + name + "' is not valid as the name");
if(name.length() != 3)
return;
typedef Arabica::text::Unicode<char> UnicodeT;
if((name[0] != UnicodeT::CAPITAL_X) &&
(name[0] != UnicodeT::LOWERCASE_X))
return;
if((name[1] != UnicodeT::CAPITAL_M) &&
(name[1] != UnicodeT::LOWERCASE_M))
return;
if((name[2] != UnicodeT::CAPITAL_L) &&
(name[2] != UnicodeT::LOWERCASE_L))
return;
throw SAX::SAXException("xsl:processing-instruction name can not be 'xml'");
} // validate_name
2012-11-04 14:04:08 +01:00
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> name_;
2007-07-19 19:01:42 +02:00
}; // class ProcessingInstruction
} // namespace XSLT
} // namespace Arabica
#endif