This commit is contained in:
Jez Higgins 2012-11-02 23:07:17 +00:00
parent 3743972b0a
commit 7d76185a44
4 changed files with 23 additions and 22 deletions

View file

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

View file

@ -9,19 +9,20 @@ namespace Arabica
namespace XSLT
{
class ValueOfHandler : public SAX::DefaultHandler<std::string>
template<class string_type, class string_adaptor>
class ValueOfHandler : public SAX::DefaultHandler<string_type, string_adaptor>
{
public:
ValueOfHandler(CompilationContext<std::string>& context) :
ValueOfHandler(CompilationContext<string_type, string_adaptor>& context) :
context_(context),
valueOf_(0)
{
} // ValueOfHandler
virtual void startElement(const std::string& /* namespaceURI */,
const std::string& /* localName */,
const std::string& qName,
const SAX::Attributes<std::string>& atts)
virtual void startElement(const string_type& /* namespaceURI */,
const string_type& /* localName */,
const string_type& qName,
const SAX::Attributes<string_type, string_adaptor>& atts)
{
if(valueOf_ == 0)
{
@ -29,31 +30,31 @@ public:
{ "disable-output-escaping", false, No, AllowedYesNo },
{ 0, false, 0, 0 } };
std::map<std::string, std::string> attrs = gatherAttributes(qName, atts, rules);
valueOf_ = new ValueOf(context_.xpath_expression(attrs["select"]),
attrs["disable-output-escaping"] == Yes);
std::map<string_type, string_type> attrs = gatherAttributes(qName, atts, rules);
valueOf_ = new ValueOf<string_type, string_adaptor>(context_.xpath_expression(attrs["select"]),
attrs["disable-output-escaping"] == Yes);
return;
} // if(valueOf_ == 0)
throw SAX::SAXException(qName + " can not contain elements");
} // startElement
virtual void endElement(const std::string& /* namespaceURI */,
const std::string& /* localName */,
const std::string& /* qName */)
virtual void endElement(const string_type& /* namespaceURI */,
const string_type& /* localName */,
const string_type& /* qName */)
{
context_.parentContainer().add_item(valueOf_);
context_.pop();
} // endElement
virtual void characters(const std::string& ch)
virtual void characters(const string_type& ch)
{
verifyNoCharacterData(ch, "xsl:value-of");
} // characters
private:
CompilationContext<std::string>& context_;
ValueOf* valueOf_;
CompilationContext<string_type, string_adaptor>& context_;
ValueOf<string_type, string_adaptor>* valueOf_;
}; // class ValueOfHandler
} //namespace XSLT

View file

@ -15,8 +15,6 @@ template<class string_type, class string_adaptor>
class StylesheetParser
{
public:
typedef string_type string_type;
typedef string_adaptor string_adaptor;
typedef SAX::ContentHandler<string_type, string_adaptor> ContentHandlerT;
typedef SAX::InputSource<string_type, string_adaptor> InputSourceT;
typedef SAX::XMLReader<string_type, string_adaptor> XMLReaderT;

View file

@ -8,17 +8,19 @@ namespace Arabica
namespace XSLT
{
template<class string_type, class string_adaptor>
class ValueOf : public Item
{
public:
ValueOf(Arabica::XPath::XPathExpressionPtr<std::string> expr,
ValueOf(Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> expr,
bool disable_output_escaping) :
expr_(expr),
disable_(disable_output_escaping)
{
} // ValueOf
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
{
if(disable_)
context.sink().disableOutputEscaping(true);
@ -30,8 +32,8 @@ public:
} // execute
private:
Arabica::XPath::XPathExpressionPtr<std::string> expr_;
bool disable_;
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> expr_;
const bool disable_;
}; // class ValueOf
} // namespace XSLT