mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-29 08:36:45 +01:00
catching up with stuff I've done while on the train
This commit is contained in:
commit
cb5c18fd3f
10 changed files with 403 additions and 359 deletions
|
@ -33,3 +33,4 @@ arabica-2008-july.*
|
|||
vs9/mangle.sln
|
||||
*.stackdump
|
||||
*.lnk
|
||||
spec
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
namesp = namespace_->evaluateAsString(node, context.xpathContext());
|
||||
else
|
||||
{
|
||||
QName qn = QName::createQName(name);
|
||||
QName qn = QName::create(name);
|
||||
if(!qn.prefix.empty())
|
||||
{
|
||||
std::map<std::string, std::string>::const_iterator ns = namespaces_.find(qn.prefix);
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
namesp = namespace_->evaluateAsString(node, context.xpathContext());
|
||||
else
|
||||
{
|
||||
QName qn = QName::createQName(name);
|
||||
QName qn = QName::create(name);
|
||||
std::map<std::string, std::string>::const_iterator ns = namespaces_.find(qn.prefix);
|
||||
if(ns == namespaces_.end())
|
||||
throw SAX::SAXException("xsl:element Runtime Error - Undeclared prefix " + qn.prefix);
|
||||
|
|
|
@ -29,10 +29,12 @@ public:
|
|||
Arabica::XPath::NodeSet<std::string> nodes;
|
||||
|
||||
Arabica::XPath::XPathValue<std::string> a0 = arg(0, context, executionContext);
|
||||
if(a0.type() != Arabica::XPath::NODE_SET)
|
||||
load_document(a0.asString(), nodes);
|
||||
else
|
||||
if(argCount() != 1)
|
||||
throw Arabica::XPath::UnsupportedException("two arg version of document()");
|
||||
if(a0.type() != Arabica::XPath::STRING)
|
||||
throw Arabica::XPath::UnsupportedException("node-set arg version of document()");
|
||||
|
||||
load_document(a0.asString(), nodes);
|
||||
return new Arabica::XPath::NodeSetValue<std::string>(nodes);
|
||||
} // evaluate
|
||||
|
||||
|
|
348
include/XSLT/impl/xslt_output.hpp
Normal file
348
include/XSLT/impl/xslt_output.hpp
Normal file
|
@ -0,0 +1,348 @@
|
|||
#ifndef ARABICA_XSLT_OUTPUT_HPP
|
||||
#define ARABICA_XSLT_OUTPUT_HPP
|
||||
|
||||
#include <XML/escaper.hpp>
|
||||
#include <SAX/ext/LexicalHandler.hpp>
|
||||
#include "xslt_namespace_stack.hpp"
|
||||
#include "xslt_qname.hpp"
|
||||
#include "handler/xslt_constants.hpp"
|
||||
|
||||
namespace Arabica
|
||||
{
|
||||
namespace XSLT
|
||||
{
|
||||
|
||||
class Output
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, std::string> Settings;
|
||||
|
||||
protected:
|
||||
Output() :
|
||||
buffering_(0),
|
||||
pending_element_(false),
|
||||
pending_attribute_(-1),
|
||||
text_mode_(false),
|
||||
warning_sink_(0)
|
||||
{
|
||||
} // Output
|
||||
~Output()
|
||||
{
|
||||
} // ~Output
|
||||
|
||||
public:
|
||||
void start_document(const Settings& settings)
|
||||
{
|
||||
Settings::const_iterator method = settings.find("method");
|
||||
text_mode_ = (method != settings.end() && method->second == "text");
|
||||
if(text_mode_)
|
||||
do_disableOutputEscaping(true);
|
||||
|
||||
do_start_document(settings);
|
||||
} // start_document
|
||||
|
||||
void end_document()
|
||||
{
|
||||
do_end_document();
|
||||
} // end_document
|
||||
|
||||
bool start_element(const std::string& qName, const std::string& namespaceURI)
|
||||
{
|
||||
QName en = QName::create(qName, namespaceURI);
|
||||
return start_element(en.prefix, en.localName, en.namespaceURI);
|
||||
} // start_element
|
||||
|
||||
bool start_element(const std::string& prefix, const std::string& localName, const std::string& namespaceURI)
|
||||
{
|
||||
if(is_buffering())
|
||||
return false;
|
||||
|
||||
flush_element();
|
||||
|
||||
namespaceStack_.pushScope();
|
||||
if(!namespaceURI.empty())
|
||||
namespaceStack_.declareNamespace(prefix, namespaceURI);
|
||||
|
||||
std::string mapped_prefix = namespaceStack_.findPrefix(namespaceURI);
|
||||
|
||||
element_stack_.push(QName(mapped_prefix, localName, namespaceURI));
|
||||
|
||||
atts_.clear();
|
||||
pending_element_ = true;
|
||||
|
||||
namespaceStack_.pushScope();
|
||||
return true;
|
||||
} // start_element
|
||||
|
||||
void end_element(const std::string& qName, const std::string& namespaceURI)
|
||||
{
|
||||
QName en = QName::create(qName, namespaceURI);
|
||||
end_element(en.prefix, en.localName, en.namespaceURI);
|
||||
} // end_element
|
||||
|
||||
void end_element(const std::string& prefix, const std::string& localName, const std::string& namespaceURI)
|
||||
{
|
||||
if(pop_if_buffering())
|
||||
return;
|
||||
|
||||
flush_element();
|
||||
|
||||
if(!text_mode_)
|
||||
{
|
||||
std::string mapped_prefix = namespaceStack_.findPrefix(namespaceURI);
|
||||
do_end_element((!mapped_prefix.empty()) ? mapped_prefix + ':' + localName : localName, namespaceURI);
|
||||
element_stack_.pop();
|
||||
} // end_element
|
||||
|
||||
namespaceStack_.popScope();
|
||||
} // end_element
|
||||
|
||||
void start_attribute(const std::string& qName, const std::string& namespaceURI)
|
||||
{
|
||||
QName qn = QName::create(qName, namespaceURI);
|
||||
start_attribute(qn.prefix, qn.localName, qn.namespaceURI);
|
||||
} // start_attribute
|
||||
|
||||
void start_attribute(const std::string& prefix, const std::string& localName, const std::string& namespaceURI)
|
||||
{
|
||||
if(push_buffering())
|
||||
return;
|
||||
|
||||
if(!pending_element_)
|
||||
{
|
||||
warning("WARNING: Cannot write attribute, no open element");
|
||||
return;
|
||||
} // if ...
|
||||
|
||||
if(!namespaceURI.empty())
|
||||
namespaceStack_.declareNamespace(prefix, namespaceURI, true);
|
||||
|
||||
std::string mapped_prefix = namespaceStack_.findPrefix(namespaceURI);
|
||||
std::string qName = (!mapped_prefix.empty()) ? mapped_prefix + ':' + localName : localName;
|
||||
|
||||
atts_.addOrReplaceAttribute(namespaceURI,
|
||||
localName,
|
||||
qName,
|
||||
"",
|
||||
"");
|
||||
pending_attribute_ = atts_.getIndex(qName);
|
||||
} // start_attribute
|
||||
|
||||
void end_attribute()
|
||||
{
|
||||
if(pop_buffering())
|
||||
return;
|
||||
|
||||
if(pending_attribute_ == -1)
|
||||
return;
|
||||
|
||||
atts_.setValue(pending_attribute_, buffer_.str());
|
||||
|
||||
pending_attribute_ = -1;
|
||||
} // end_attribute
|
||||
|
||||
void add_attribute(const std::string& uri,
|
||||
const std::string& localName,
|
||||
const std::string& qName,
|
||||
const std::string& value)
|
||||
{
|
||||
if(!pending_element_)
|
||||
{
|
||||
warning("WARNING: Cannot write attribute, no open element");
|
||||
return;
|
||||
} // if ...
|
||||
|
||||
atts_.addAttribute(uri, localName, qName, "", value);
|
||||
} // add_attribute
|
||||
|
||||
void characters(const std::string& ch)
|
||||
{
|
||||
if(buffering_)
|
||||
{
|
||||
if(buffering_ == 1)
|
||||
buffer_ << ch;
|
||||
return;
|
||||
} // if ...
|
||||
|
||||
flush_element();
|
||||
|
||||
if(pending_attribute_ != -1)
|
||||
{
|
||||
atts_.setValue(pending_attribute_, atts_.getValue(pending_attribute_) + ch);
|
||||
return;
|
||||
} // if ...
|
||||
|
||||
if(!buffering_)
|
||||
do_characters(ch);
|
||||
} // characters
|
||||
|
||||
void start_comment()
|
||||
{
|
||||
if(push_buffering())
|
||||
return;
|
||||
|
||||
flush_element();
|
||||
} // start_comment
|
||||
|
||||
void end_comment()
|
||||
{
|
||||
if(pop_buffering())
|
||||
return;
|
||||
|
||||
if(!text_mode_)
|
||||
{
|
||||
std::string comment = escape(buffer_.str(), "--", "- -");
|
||||
if(comment.length() && *(comment.rbegin()) == '-')
|
||||
comment.append(" ");
|
||||
do_comment(comment);
|
||||
} // if ...
|
||||
} // end_comment
|
||||
|
||||
void start_processing_instruction(const std::string& target)
|
||||
{
|
||||
if(push_buffering())
|
||||
return;
|
||||
|
||||
flush_element();
|
||||
|
||||
target_ = target;
|
||||
} // start_processing_instruction
|
||||
|
||||
void end_processing_instruction()
|
||||
{
|
||||
if(pop_buffering())
|
||||
return;
|
||||
|
||||
if(!text_mode_)
|
||||
{
|
||||
std::string data = escape(buffer_.str(), "?>", "? >");
|
||||
do_processing_instruction(target_, data);
|
||||
} // if ...
|
||||
} // end_processing_instruction
|
||||
|
||||
void disableOutputEscaping(bool disable)
|
||||
{
|
||||
if(!text_mode_)
|
||||
do_disableOutputEscaping(disable);
|
||||
} // disableOutputEscaping
|
||||
|
||||
void set_warning_sink(Output& warning_sink)
|
||||
{
|
||||
warning_sink_ = &warning_sink;
|
||||
} // set_warning_sink
|
||||
|
||||
protected:
|
||||
virtual void do_start_document(const Settings& settings) = 0;
|
||||
virtual void do_end_document() = 0;
|
||||
virtual void do_start_element(const std::string& qName, const std::string& namespaceURI, const SAX::Attributes<std::string>& atts) = 0;
|
||||
virtual void do_end_element(const std::string& qName, const std::string& namespaceURI) = 0;
|
||||
virtual void do_characters(const std::string& ch) = 0;
|
||||
virtual void do_comment(const std::string& ch) = 0;
|
||||
virtual void do_processing_instruction(const std::string& target, const std::string& data) = 0;
|
||||
virtual void do_disableOutputEscaping(bool disable) = 0;
|
||||
virtual bool want_namespace_declarations() const = 0;
|
||||
|
||||
private:
|
||||
std::string escape(std::string str, const std::string& t, const std::string& r) const
|
||||
{
|
||||
std::string::size_type naughty = str.find(t);
|
||||
while(naughty != std::string::npos)
|
||||
{
|
||||
str.replace(naughty, t.length(), r, 0, r.length());
|
||||
naughty = str.find(t, naughty);
|
||||
} // while
|
||||
return str;
|
||||
} // escape
|
||||
|
||||
bool push_buffering()
|
||||
{
|
||||
bool is_buf = is_buffering();
|
||||
++buffering_;
|
||||
|
||||
if(is_buf)
|
||||
return true;
|
||||
|
||||
buffer_.str("");
|
||||
return false;
|
||||
} // push_buffering
|
||||
|
||||
bool is_buffering()
|
||||
{
|
||||
if(!buffering_)
|
||||
return false;
|
||||
warning("WARNING: non-text ignored when creating processing instruction, comment or attribute");
|
||||
return true;
|
||||
} // is_buffering
|
||||
|
||||
bool pop_if_buffering()
|
||||
{
|
||||
if(!buffering_)
|
||||
return false;
|
||||
--buffering_;
|
||||
return true;
|
||||
} // pop_if_buffering
|
||||
|
||||
bool pop_buffering()
|
||||
{
|
||||
--buffering_;
|
||||
return (buffering_ != 0); // oh, Visual Studio how I curse you warning C4800
|
||||
} // pop_buffering
|
||||
|
||||
void flush_element()
|
||||
{
|
||||
if((!pending_element_) || (pending_attribute_ != -1))
|
||||
return;
|
||||
|
||||
if(text_mode_)
|
||||
return;
|
||||
|
||||
bool want_decs = want_namespace_declarations();
|
||||
if(want_decs)
|
||||
addNamespaceDeclarations();
|
||||
namespaceStack_.popScope();
|
||||
if(want_decs)
|
||||
addNamespaceDeclarations();
|
||||
|
||||
do_start_element(element_stack_.top().qname, element_stack_.top().namespaceURI, atts_);
|
||||
pending_element_ = false;
|
||||
} // flush_element
|
||||
|
||||
void addNamespaceDeclarations()
|
||||
{
|
||||
for(NamespaceStack::Scope::const_iterator n = namespaceStack_.begin(), ne = namespaceStack_.end(); n != ne; ++n)
|
||||
{
|
||||
if(n->first == "xml")
|
||||
continue;
|
||||
|
||||
std::string qName = (n->first.empty()) ? "xmlns" : "xmlns:" + n->first;
|
||||
atts_.addAttribute("http://www.w3.org/2000/xmlns",
|
||||
n->first,
|
||||
qName,
|
||||
"",
|
||||
n->second);
|
||||
}
|
||||
} // addNamespaceDeclarations
|
||||
|
||||
void warning(const std::string& warning_message)
|
||||
{
|
||||
warning_sink_->characters(warning_message);
|
||||
warning_sink_->characters("\n");
|
||||
} // warning
|
||||
|
||||
int buffering_;
|
||||
bool pending_element_;
|
||||
int pending_attribute_;
|
||||
std::stack<QName> element_stack_;
|
||||
std::string target_;
|
||||
SAX::AttributesImpl<std::string, Arabica::default_string_adaptor<std::string> > atts_;
|
||||
std::stringstream buffer_;
|
||||
bool text_mode_;
|
||||
NamespaceStack namespaceStack_;
|
||||
Output* warning_sink_;
|
||||
}; // class Output
|
||||
|
||||
} // namespace XSLT
|
||||
} // namespace Arabica
|
||||
|
||||
#endif // ARABICA_XSLT_OUTPUT_HPP
|
||||
|
|
@ -13,38 +13,45 @@ struct QName
|
|||
std::string prefix;
|
||||
std::string localName;
|
||||
std::string namespaceURI;
|
||||
std::string qname;
|
||||
|
||||
static QName createQName(const std::string& qName)
|
||||
QName(const std::string& p,
|
||||
const std::string& lN,
|
||||
const std::string& uri) :
|
||||
prefix(p),
|
||||
localName(lN),
|
||||
namespaceURI(uri),
|
||||
qname(p.empty() ? lN : (p + ":" + lN))
|
||||
{
|
||||
} // QName
|
||||
|
||||
static QName create(const std::string& qName)
|
||||
{
|
||||
return create(qName, "");
|
||||
} // create
|
||||
|
||||
static QName create(const std::string& qName, const std::string& namespaceURI)
|
||||
{
|
||||
if(!Arabica::XML::is_qname<Arabica::default_string_adaptor<std::string> >(qName))
|
||||
throw SAX::SAXException("Bad name : " + qName);
|
||||
|
||||
static char COLON = Arabica::text::Unicode<char>::COLON;
|
||||
QName qn;
|
||||
|
||||
std::string prefix;
|
||||
std::string localName;
|
||||
|
||||
size_t colon = qName.find(COLON);
|
||||
|
||||
if(colon == std::string::npos)
|
||||
qn.localName = qName;
|
||||
localName = qName;
|
||||
else
|
||||
{
|
||||
qn.prefix = qName.substr(0, colon);
|
||||
qn.localName = qName.substr(colon+1);
|
||||
prefix = qName.substr(0, colon);
|
||||
localName = qName.substr(colon+1);
|
||||
}
|
||||
|
||||
return qn;
|
||||
} // createQName
|
||||
|
||||
static QName createQName(const std::string& qName, const std::string namespaceURI)
|
||||
{
|
||||
QName qn(createQName(qName));
|
||||
qn.namespaceURI = namespaceURI;
|
||||
|
||||
if(!qn.prefix.empty() && qn.namespaceURI.empty())
|
||||
throw SAX::SAXException("Undeclared prefix " + qn.prefix);
|
||||
return qn;
|
||||
} // createQName
|
||||
}; // QName
|
||||
|
||||
return QName(prefix, localName, namespaceURI);
|
||||
} // create
|
||||
}; // struct QName
|
||||
|
||||
} // namespace XSLT
|
||||
} // namespace Arabica
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
#include <SAX/ContentHandler.hpp>
|
||||
#include <SAX/ext/LexicalHandler.hpp>
|
||||
#include <SAX/helpers/AttributesImpl.hpp>
|
||||
#include "xslt_namespace_stack.hpp"
|
||||
#include "xslt_qname.hpp"
|
||||
#include "xslt_output.hpp"
|
||||
#include "handler/xslt_constants.hpp"
|
||||
|
||||
namespace Arabica
|
||||
|
@ -16,335 +15,6 @@ namespace Arabica
|
|||
namespace XSLT
|
||||
{
|
||||
|
||||
class Output
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, std::string> Settings;
|
||||
|
||||
protected:
|
||||
Output() :
|
||||
buffering_(0),
|
||||
pending_element_(false),
|
||||
pending_attribute_(-1),
|
||||
text_mode_(false),
|
||||
warning_sink_(0)
|
||||
{
|
||||
} // Output
|
||||
~Output()
|
||||
{
|
||||
} // ~Output
|
||||
|
||||
public:
|
||||
void start_document(const Settings& settings)
|
||||
{
|
||||
Settings::const_iterator method = settings.find("method");
|
||||
text_mode_ = (method != settings.end() && method->second == "text");
|
||||
if(text_mode_)
|
||||
do_disableOutputEscaping(true);
|
||||
|
||||
do_start_document(settings);
|
||||
} // start_document
|
||||
|
||||
void end_document()
|
||||
{
|
||||
do_end_document();
|
||||
} // end_document
|
||||
|
||||
bool start_element(const std::string& qName, const std::string& namespaceURI)
|
||||
{
|
||||
QName qn = QName::createQName(qName, namespaceURI);
|
||||
return start_element(qn.prefix, qn.localName, qn.namespaceURI);
|
||||
} // start_element
|
||||
|
||||
bool start_element(const std::string& prefix, const std::string& localName, const std::string& namespaceURI)
|
||||
{
|
||||
if(is_buffering())
|
||||
return false;
|
||||
|
||||
flush_element();
|
||||
|
||||
namespaceStack_.pushScope();
|
||||
if(!namespaceURI.empty())
|
||||
namespaceStack_.declareNamespace(prefix, namespaceURI);
|
||||
|
||||
std::string mapped_prefix = namespaceStack_.findPrefix(namespaceURI);
|
||||
name_ = (!mapped_prefix.empty()) ? mapped_prefix + ':' + localName : localName;
|
||||
namespaceURI_ = namespaceURI;
|
||||
|
||||
atts_.clear();
|
||||
pending_element_ = true;
|
||||
|
||||
namespaceStack_.pushScope();
|
||||
return true;
|
||||
} // start_element
|
||||
|
||||
void end_element(const std::string& qName, const std::string& namespaceURI)
|
||||
{
|
||||
QName qn = QName::createQName(qName, namespaceURI);
|
||||
end_element(qn.prefix, qn.localName, qn.namespaceURI);
|
||||
} // end_element
|
||||
|
||||
void end_element(const std::string& prefix, const std::string& localName, const std::string& namespaceURI)
|
||||
{
|
||||
if(pop_if_buffering())
|
||||
return;
|
||||
|
||||
flush_element();
|
||||
|
||||
if(!text_mode_)
|
||||
{
|
||||
std::string mapped_prefix = namespaceStack_.findPrefix(namespaceURI);
|
||||
do_end_element((!mapped_prefix.empty()) ? mapped_prefix + ':' + localName : localName, namespaceURI);
|
||||
} // end_element
|
||||
|
||||
namespaceStack_.popScope();
|
||||
} // end_element
|
||||
|
||||
void start_attribute(const std::string& qName, const std::string& namespaceURI)
|
||||
{
|
||||
QName qn = QName::createQName(qName, namespaceURI);
|
||||
start_attribute(qn.prefix, qn.localName, qn.namespaceURI);
|
||||
} // start_attribute
|
||||
|
||||
void start_attribute(const std::string& prefix, const std::string& localName, const std::string& namespaceURI)
|
||||
{
|
||||
if(push_buffering())
|
||||
return;
|
||||
|
||||
if(!pending_element_)
|
||||
{
|
||||
warning("WARNING: Cannot write attribute, no open element");
|
||||
return;
|
||||
} // if ...
|
||||
|
||||
if(!namespaceURI.empty())
|
||||
namespaceStack_.declareNamespace(prefix, namespaceURI, true);
|
||||
|
||||
std::string mapped_prefix = namespaceStack_.findPrefix(namespaceURI);
|
||||
std::string qName = (!mapped_prefix.empty()) ? mapped_prefix + ':' + localName : localName;
|
||||
|
||||
atts_.addOrReplaceAttribute(namespaceURI,
|
||||
localName,
|
||||
qName,
|
||||
"",
|
||||
"");
|
||||
pending_attribute_ = atts_.getIndex(qName);
|
||||
} // start_attribute
|
||||
|
||||
void end_attribute()
|
||||
{
|
||||
if(pop_buffering())
|
||||
return;
|
||||
|
||||
if(pending_attribute_ == -1)
|
||||
return;
|
||||
|
||||
atts_.setValue(pending_attribute_, buffer_.str());
|
||||
|
||||
pending_attribute_ = -1;
|
||||
} // end_attribute
|
||||
|
||||
void add_attribute(const std::string& uri,
|
||||
const std::string& localName,
|
||||
const std::string& qName,
|
||||
const std::string& value)
|
||||
{
|
||||
if(!pending_element_)
|
||||
{
|
||||
warning("WARNING: Cannot write attribute, no open element");
|
||||
return;
|
||||
} // if ...
|
||||
|
||||
atts_.addAttribute(uri, localName, qName, "", value);
|
||||
} // add_attribute
|
||||
|
||||
void characters(const std::string& ch)
|
||||
{
|
||||
if(buffering_)
|
||||
{
|
||||
if(buffering_ == 1)
|
||||
buffer_ << ch;
|
||||
return;
|
||||
} // if ...
|
||||
|
||||
flush_element();
|
||||
|
||||
if(pending_attribute_ != -1)
|
||||
{
|
||||
atts_.setValue(pending_attribute_, atts_.getValue(pending_attribute_) + ch);
|
||||
return;
|
||||
} // if ...
|
||||
|
||||
if(!buffering_)
|
||||
do_characters(ch);
|
||||
} // characters
|
||||
|
||||
void start_comment()
|
||||
{
|
||||
if(push_buffering())
|
||||
return;
|
||||
|
||||
flush_element();
|
||||
} // start_comment
|
||||
|
||||
void end_comment()
|
||||
{
|
||||
if(pop_buffering())
|
||||
return;
|
||||
|
||||
if(!text_mode_)
|
||||
{
|
||||
std::string comment = escape(buffer_.str(), "--", "- -");
|
||||
if(comment.length() && *(comment.rbegin()) == '-')
|
||||
comment.append(" ");
|
||||
do_comment(comment);
|
||||
} // if ...
|
||||
} // end_comment
|
||||
|
||||
void start_processing_instruction(const std::string& target)
|
||||
{
|
||||
if(push_buffering())
|
||||
return;
|
||||
|
||||
flush_element();
|
||||
|
||||
name_ = target;
|
||||
} // start_processing_instruction
|
||||
|
||||
void end_processing_instruction()
|
||||
{
|
||||
if(pop_buffering())
|
||||
return;
|
||||
|
||||
if(!text_mode_)
|
||||
{
|
||||
std::string data = escape(buffer_.str(), "?>", "? >");
|
||||
do_processing_instruction(name_, data);
|
||||
} // if ...
|
||||
} // end_processing_instruction
|
||||
|
||||
void disableOutputEscaping(bool disable)
|
||||
{
|
||||
if(!text_mode_)
|
||||
do_disableOutputEscaping(disable);
|
||||
} // disableOutputEscaping
|
||||
|
||||
void set_warning_sink(Output& warning_sink)
|
||||
{
|
||||
warning_sink_ = &warning_sink;
|
||||
} // set_warning_sink
|
||||
|
||||
protected:
|
||||
virtual void do_start_document(const Settings& settings) = 0;
|
||||
virtual void do_end_document() = 0;
|
||||
virtual void do_start_element(const std::string& qName, const std::string& namespaceURI, const SAX::Attributes<std::string>& atts) = 0;
|
||||
virtual void do_end_element(const std::string& qName, const std::string& namespaceURI) = 0;
|
||||
virtual void do_characters(const std::string& ch) = 0;
|
||||
virtual void do_comment(const std::string& ch) = 0;
|
||||
virtual void do_processing_instruction(const std::string& target, const std::string& data) = 0;
|
||||
virtual void do_disableOutputEscaping(bool disable) = 0;
|
||||
virtual bool want_namespace_declarations() const = 0;
|
||||
|
||||
private:
|
||||
std::string escape(std::string str, const std::string& t, const std::string& r) const
|
||||
{
|
||||
std::string::size_type naughty = str.find(t);
|
||||
while(naughty != std::string::npos)
|
||||
{
|
||||
str.replace(naughty, t.length(), r, 0, r.length());
|
||||
naughty = str.find(t, naughty);
|
||||
} // while
|
||||
return str;
|
||||
} // escape
|
||||
|
||||
bool push_buffering()
|
||||
{
|
||||
bool is_buf = is_buffering();
|
||||
++buffering_;
|
||||
|
||||
if(is_buf)
|
||||
return true;
|
||||
|
||||
buffer_.str("");
|
||||
return false;
|
||||
} // push_buffering
|
||||
|
||||
bool is_buffering()
|
||||
{
|
||||
if(!buffering_)
|
||||
return false;
|
||||
warning("WARNING: non-text ignored when creating processing instruction, comment or attribute");
|
||||
return true;
|
||||
} // is_buffering
|
||||
|
||||
bool pop_if_buffering()
|
||||
{
|
||||
if(!buffering_)
|
||||
return false;
|
||||
--buffering_;
|
||||
return true;
|
||||
} // pop_if_buffering
|
||||
|
||||
bool pop_buffering()
|
||||
{
|
||||
--buffering_;
|
||||
return (buffering_ != 0); // oh, Visual Studio how I curse you warning C4800
|
||||
} // pop_buffering
|
||||
|
||||
void flush_element()
|
||||
{
|
||||
if((!pending_element_) || (pending_attribute_ != -1))
|
||||
return;
|
||||
|
||||
if(text_mode_)
|
||||
return;
|
||||
|
||||
bool want_decs = want_namespace_declarations();
|
||||
if(want_decs)
|
||||
addNamespaceDeclarations();
|
||||
namespaceStack_.popScope();
|
||||
if(want_decs)
|
||||
addNamespaceDeclarations();
|
||||
|
||||
do_start_element(name_, namespaceURI_, atts_);
|
||||
|
||||
pending_element_ = false;
|
||||
} // flush_element
|
||||
|
||||
void addNamespaceDeclarations()
|
||||
{
|
||||
for(NamespaceStack::Scope::const_iterator n = namespaceStack_.begin(), ne = namespaceStack_.end(); n != ne; ++n)
|
||||
{
|
||||
if(n->first == "xml")
|
||||
continue;
|
||||
|
||||
std::string qName = (n->first.empty()) ? "xmlns" : "xmlns:" + n->first;
|
||||
atts_.addAttribute("http://www.w3.org/2000/xmlns",
|
||||
n->first,
|
||||
qName,
|
||||
"",
|
||||
n->second);
|
||||
}
|
||||
} // addNamespaceDeclarations
|
||||
|
||||
void warning(const std::string& warning_message)
|
||||
{
|
||||
warning_sink_->characters(warning_message);
|
||||
warning_sink_->characters("\n");
|
||||
} // warning
|
||||
|
||||
int buffering_;
|
||||
bool pending_element_;
|
||||
int pending_attribute_;
|
||||
std::string name_;
|
||||
std::string namespaceURI_;
|
||||
SAX::AttributesImpl<std::string, Arabica::default_string_adaptor<std::string> > atts_;
|
||||
std::stringstream buffer_;
|
||||
bool text_mode_;
|
||||
NamespaceStack namespaceStack_;
|
||||
Output* warning_sink_;
|
||||
}; // class Output
|
||||
|
||||
class Sink
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -62,6 +62,8 @@ public:
|
|||
std::map<std::string, std::string> attributes = gatherAttributes(qName, atts, rules);
|
||||
if(attributes["version"] != StylesheetConstant::Version())
|
||||
throw SAX::SAXException("I'm only a poor version 1.0 XSLT Transformer.");
|
||||
if(!attributes["extension-element-prefixes"].empty())
|
||||
throw SAX::SAXException("Haven't implemented extension-element-prefixes yet");
|
||||
|
||||
top_ = false;
|
||||
|
||||
|
|
|
@ -26,11 +26,13 @@
|
|||
<test-case id="match_match01" compiles="no" reason="Needs xsl:strip-space"/>
|
||||
<test-case id="match_match11" compiles="no" reason="haven't implemented id function"/>
|
||||
<test-case id="mdocs_mdocs02" runs="no" reason="haven't implemented node-set arg version of document()"/>
|
||||
<test-case id="mdocs_mdocs03" runs="no" reason="haven't implemented two arg version of document()"/>
|
||||
<test-case id="mdocs_mdocs04" runs="no" reason="haven't implemented node-set arg version of document()"/>
|
||||
<test-case id="mdocs_mdocs05" runs="no" reason="haven't implemented node-set arg version of document()"/>
|
||||
<test-case id="mdocs_mdocs06" runs="no" reason="haven't implemented node-set arg version of document()"/>
|
||||
<test-case id="mdocs_mdocs07" runs="no" reason="haven't implemented node-set arg version of document()"/>
|
||||
<test-case id="mdocs_mdocs08" runs="no" reason="haven't implemented node-set arg version of document()"/>
|
||||
<test-case id="mdocs_mdocs15" runs="no" reason="haven't implemented two arg version of document()"/>
|
||||
<test-case id="mdocs_mdocs18" runs="no" reason="haven't implemented node-set arg version of document()"/>
|
||||
<test-case id="message_message01" compare="text"/>
|
||||
<test-case id="message_message14" compiles="no" reason="Needs xsl:number"/>
|
||||
|
@ -94,6 +96,8 @@
|
|||
<test-case id="output_output113" compare="text" reason="Text output"/>
|
||||
<test-case id="position_position70" compiles="no" reason="Needs xsl:strip-space" />
|
||||
<test-case id="processorinfo_processorinfo03" skip="yes" reason="Expects Xalan URI in result"/>
|
||||
<test-case id="reluri_reluri09" runs="no"/>
|
||||
<test-case id="reluri_reluri10" runs="no"/>
|
||||
<test-case id="reluri_reluri10" runs="no"/>
|
||||
<test-case id="reluri_reluri11" runs="no"/>
|
||||
<test-case id="select_select07" compare="text" reason="Text output"/>
|
||||
|
@ -155,6 +159,7 @@
|
|||
<test-case id="AVTs__77599" compare="fragment" reason="XML Fragment output"/>
|
||||
<test-case id="Attributes__78366" compiles="no" reason="Error case: empty namespace"/>
|
||||
<test-case id="Attributes__78372" skip="yes" reason="Expected output includes newlines and tabs, but inconsistently escaped. Mangle escapes them all, as do Saxon, .NET, and Xalan (although Xalan uses decimal rather than hex numerical entities)."/>
|
||||
<test-case id="Attributes__78374" skip="yes" reason="Error is recoverable. Mangle, Saxon, Xalan all run. MSXML and .NET do not."/>
|
||||
<test-case id="Attributes__78382" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
|
||||
<test-case id="Attributes__78386" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
|
||||
<test-case id="Attributes__81430" compare="fragment" reason="XML Fragment output"/>
|
||||
|
@ -225,6 +230,8 @@
|
|||
<test-case id="BVTs_bvt037" compare="fragment"/>
|
||||
<test-case id="BVTs_bvt038" compare="fragment"/>
|
||||
<test-case id="BVTs_bvt040" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
|
||||
<test-case id="BVTs_bvt042" compare="fragment"/>
|
||||
<test-case id="BVTs_bvt043" compare="fragment"/>
|
||||
<test-case id="BVTs_bvt044" skip="yes" reason="Segfault!"/>
|
||||
<test-case id="BVTs_bvt045" skip="yes" reason="Bad result data"/>
|
||||
<test-case id="BVTs_bvt047" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
|
||||
|
@ -246,14 +253,14 @@
|
|||
<test-case id="BVTs_bvt075" compare="text"/>
|
||||
<test-case id="BVTs_bvt076" compare="text"/>
|
||||
<test-case id="BVTs_bvt078" compare="text"/>
|
||||
<test-case id="BVTs_bvt079" compare="fragment"/>
|
||||
<test-case id="BVTs_bvt079" compare="text"/>
|
||||
<test-case id="BVTs_bvt080" compare="fragment"/>
|
||||
<test-case id="BVTs_bvt081" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
|
||||
<test-case id="BVTs_bvt083" compare="fragment"/>
|
||||
<test-case id="BVTs_bvt085" skip="yes" reason="Bad result data"/>
|
||||
<test-case id="BVTs_bvt086" compare="fragment"/>
|
||||
<test-case id="BVTs_bvt086" compare="text"/>
|
||||
<test-case id="BVTs_bvt089" compare="fragment"/>
|
||||
<test-case id="BVTs_bvt090" compare="fragment"/>
|
||||
<test-case id="BVTs_bvt090" compare="text"/>
|
||||
<test-case id="BVTs_bvt092" compare="fragment"/>
|
||||
<test-case id="BVTs_bvt094" compare="text"/>
|
||||
<test-case id="BVTs_bvt095" compare="fragment"/>
|
||||
|
@ -346,6 +353,7 @@
|
|||
<test-case id="Elements__89717" compare="fragment"/>
|
||||
<test-case id="Elements__89718" compare="fragment"/>
|
||||
<test-case id="Elements__89723" compare="fragment"/>
|
||||
<test-case id="Elements_Element_UseXslElementWithNameSpaceAttrEqualToXmlnsUri" skip="yes" reason="Error is recoverable. Mangle, Saxon, Saxon8, Xalan all run. MSXML and .NET do not."/>
|
||||
<test-case id="Fallback__91817" compiles="no"/>
|
||||
<test-case id="Fallback__91818" compiles="no"/>
|
||||
<test-case id="Fallback__91819" compiles="no"/>
|
||||
|
@ -406,6 +414,7 @@
|
|||
<test-case id="Keys_Bug76935" compare="fragment"/>
|
||||
<test-case id="Keys_PerfRepro2" compiles="no" reason="needs xsl:attribute-set"/>
|
||||
<test-case id="Keys_PerfRepro3" skip="yes" reason="Runs really slowly. Come back to this later"/>
|
||||
<test-case id="Messages__91765_1" compare="fragment"/>
|
||||
<test-case id="Miscellaneous__83996" compare="text"/>
|
||||
<test-case id="Miscellaneous__84002" compare="fragment"/>
|
||||
<test-case id="Miscellaneous__84111" compiles="no"/>
|
||||
|
@ -567,6 +576,7 @@
|
|||
<test-case id="Stylesheet__91815" skip="yes" reason="Haven't implemented extension elements yet."/>
|
||||
<test-case id="Stylesheet__91816" compiles="no" reason="Bad test case. xsl:extension-element-prefixes is not allowed on xsl:value-of"/>
|
||||
<test-case id="Stylesheet_Stylsheet_ExcludeResultPrefixesOnStylesheet" skip="yes" reason="wacky ref_out encoding"/>
|
||||
<test-case id="Stylesheet_UseStylesheetWithXmlnsEqualToXmlnsUri" skip="yes" reason="Questionable test case. MSXML and Saxon both run it ok"/>
|
||||
<test-case id="Template__84581" compare="text"/>
|
||||
<test-case id="Template_MatchPatternVariation1" compare="fragment"/>
|
||||
<test-case id="Template_MatchPatternVariation2" compare="fragment"/>
|
||||
|
|
|
@ -1035,6 +1035,10 @@
|
|||
RelativePath="..\include\XSLT\impl\xslt_namespace_stack.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\include\XSLT\impl\xslt_output.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\include\XSLT\impl\xslt_param.hpp"
|
||||
>
|
||||
|
|
Loading…
Add table
Reference in a new issue