arabica/examples/XSLT/mangle.cpp

79 lines
1.9 KiB
C++
Raw Normal View History

2007-07-19 18:58:57 +02:00
#pragma warning(disable : 4250)
#include <iostream>
#include <string>
#include <sstream>
2007-09-05 00:55:47 +02:00
#include <SAX/InputSource.hpp>
#include <DOM/SAX2DOM/SAX2DOM.hpp>
2007-11-19 23:11:05 +01:00
#include <DOM/io/Stream.hpp>
2007-07-19 18:58:57 +02:00
#include <XSLT/XSLT.hpp>
2007-09-05 13:47:13 +02:00
Arabica::DOM::Document<std::string> buildDOM(const std::string& xml);
2007-07-19 18:58:57 +02:00
int main(int argc, const char* argv[])
{
if(argc != 3)
{
std::cout << "mangle is an (in-development) XSLT processor\n"
<< argv[0] << " xmlfile xsltfile" << std::endl;
return 0;
} // if ...
Arabica::XSLT::StylesheetCompiler compiler;
std::ostringstream errors;
try
{
Arabica::SAX::InputSource<std::string> source(argv[2]);
2007-07-19 18:58:57 +02:00
std::auto_ptr<Arabica::XSLT::Stylesheet> stylesheet = compiler.compile(source);
if(stylesheet.get() == 0)
{
std::cerr << "Couldn't compile stylesheet: " << compiler.error() << std::endl;
return -1;
} // if ...
stylesheet->set_error_output(errors);
2007-09-05 13:47:13 +02:00
Arabica::DOM::Document<std::string> document = buildDOM(argv[1]);
2007-07-19 18:58:57 +02:00
if(document == 0)
{
std::cerr << "Could not parse XML source" << std::endl;
return 0;
} // if ...
2008-09-16 09:31:30 +02:00
//document.normalize();
2007-07-19 18:58:57 +02:00
stylesheet->execute(document);
2007-11-19 23:11:05 +01:00
/*
2007-11-19 23:11:05 +01:00
std::cout << "==============" << std::endl;
Arabica::XSLT::DOMSink output;
stylesheet->set_output(output);
stylesheet->execute(document);
Arabica::DOM::Node<std::string> node = output.node();
std::cout << node << std::endl;
*/
2007-07-19 18:58:57 +02:00
}
catch(const std::runtime_error& ex)
{
std::cerr << ex.what() << std::endl;
} // catch
std::cerr << "\n\n" << errors.str() << std::endl;
return 0;
} // main
2007-09-05 13:47:13 +02:00
Arabica::DOM::Document<std::string> buildDOM(const std::string& filename)
2007-07-19 18:58:57 +02:00
{
Arabica::SAX::InputSource<std::string> is(filename);
2007-09-05 13:47:13 +02:00
Arabica::SAX2DOM::Parser<std::string> parser;
2007-07-19 18:58:57 +02:00
parser.parse(is);
return parser.getDocument();
} // buildDOM