processing instruction

This commit is contained in:
Jez Higgins 2012-11-04 13:04:08 +00:00
parent 895bd0baf3
commit 0ea5226801
3 changed files with 20 additions and 16 deletions

View file

@ -152,7 +152,7 @@ const ChildElement* AllowedChildren()
{ "if", CreateHandler<IfHandler<std::string, Arabica::default_string_adaptor<std::string> > > },
{ "message", CreateHandler<MessageHandler>},
{ "number", CreateHandler<NotImplementedYetHandler<std::string, Arabica::default_string_adaptor<std::string> > >},
{ "processing-instruction", CreateHandler<ProcessingInstructionHandler> },
{ "processing-instruction", CreateHandler<ProcessingInstructionHandler<std::string, Arabica::default_string_adaptor<std::string> > > },
{ "text", CreateHandler<TextHandler<std::string, Arabica::default_string_adaptor<std::string> > > },
{ "value-of", CreateHandler<ValueOfHandler<std::string, Arabica::default_string_adaptor<std::string> > > },
{ "variable", CreateHandler<VariableHandler<Variable> > },

View file

@ -9,24 +9,27 @@ namespace Arabica
namespace XSLT
{
class ProcessingInstructionHandler : public ItemContainerHandler<ProcessingInstruction>
template<class string_type, class string_adaptor>
class ProcessingInstructionHandler : public ItemContainerHandler<ProcessingInstruction<string_type, string_adaptor> >
{
typedef ItemContainerHandler<ProcessingInstruction<string_type, string_adaptor> > baseT;
public:
ProcessingInstructionHandler(CompilationContext<std::string>& context) :
ItemContainerHandler<ProcessingInstruction>(context)
ProcessingInstructionHandler(CompilationContext<string_type, string_adaptor>& context) :
ItemContainerHandler<ProcessingInstruction<string_type, string_adaptor> >(context)
{
} // ProcessingInstructionHandler
virtual ProcessingInstruction* createContainer(const std::string& /* namespaceURI */,
const std::string& /* localName */,
const std::string& qName,
const SAX::Attributes<std::string>& atts)
virtual ProcessingInstruction<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)
{
static const ValueRule rules[] = { { "name", true, 0, 0 },
{ 0, false, 0, 0} };
std::string name = gatherAttributes(qName, atts, rules)["name"];
string_type name = gatherAttributes(qName, atts, rules)["name"];
return new ProcessingInstruction(ItemContainerHandler<ProcessingInstruction>::context().xpath_attribute_value_template(name));
return new ProcessingInstruction<string_type, string_adaptor>(baseT::context().xpath_attribute_value_template(name));
} // createContainer
}; // class ProcessingInstructionHandler

View file

@ -10,19 +10,20 @@ namespace Arabica
namespace XSLT
{
template<class string_type, class string_adaptor>
class ProcessingInstruction : public ItemContainer
{
public:
ProcessingInstruction(const Arabica::XPath::XPathExpressionPtr<std::string>& name) :
ProcessingInstruction(const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor>& name) :
name_(name)
{
} // ProcessingInstruction
virtual ~ProcessingInstruction() { }
virtual void execute(const DOM::Node<std::string>& node, ExecutionContext& context) const
virtual void execute(const DOM::Node<string_type, string_adaptor>& node, ExecutionContext& context) const
{
std::string name = name_->evaluateAsString(node, context.xpathContext());
string_type name = name_->evaluateAsString(node, context.xpathContext());
validate_name(name);
context.sink().start_processing_instruction(name);
@ -31,12 +32,12 @@ public:
} // execute
private:
void validate_name(const std::string& name) const
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");
if(!Arabica::XML::is_ncname<Arabica::default_string_adaptor<std::string> >(name))
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)
@ -57,7 +58,7 @@ private:
throw SAX::SAXException("xsl:processing-instruction name can not be 'xml'");
} // validate_name
Arabica::XPath::XPathExpressionPtr<std::string> name_;
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> name_;
}; // class ProcessingInstruction
} // namespace XSLT