2010-01-11 10:28:48 +01:00
|
|
|
#ifdef _MSC_VER
|
2012-11-21 07:59:40 +01:00
|
|
|
#pragma warning(disable : 4250 4244)
|
2010-01-11 10:28:48 +01:00
|
|
|
#endif
|
2007-07-19 18:58:57 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <XSLT/XSLT.hpp>
|
|
|
|
|
2012-11-21 07:59:40 +01: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 ...
|
|
|
|
|
2024-09-10 13:09:36 +02:00
|
|
|
try
|
2007-07-19 18:58:57 +02:00
|
|
|
{
|
2012-11-21 07:59:40 +01:00
|
|
|
Arabica::SAX::InputSource<std::string> source(argv[2]);
|
2024-09-10 13:09:36 +02:00
|
|
|
Arabica::XSLT::StylesheetCompiler<std::string> compiler;
|
2020-04-16 00:05:47 +02:00
|
|
|
std::unique_ptr<Arabica::XSLT::Stylesheet<std::string> > stylesheet = compiler.compile(source);
|
2007-07-19 18:58:57 +02:00
|
|
|
if(stylesheet.get() == 0)
|
|
|
|
{
|
|
|
|
std::cerr << "Couldn't compile stylesheet: " << compiler.error() << std::endl;
|
|
|
|
return -1;
|
|
|
|
} // if ...
|
|
|
|
|
2024-09-10 13:09:36 +02:00
|
|
|
stylesheet->set_error_output(std::cerr);
|
2007-07-19 18:58:57 +02:00
|
|
|
|
2012-11-21 07:59:40 +01: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 ...
|
|
|
|
stylesheet->execute(document);
|
|
|
|
}
|
|
|
|
catch(const std::runtime_error& ex)
|
|
|
|
{
|
|
|
|
std::cerr << ex.what() << std::endl;
|
|
|
|
} // catch
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} // main
|
|
|
|
|
2012-11-21 07:59:40 +01:00
|
|
|
Arabica::DOM::Document<std::string> buildDOM(const std::string & filename)
|
2007-07-19 18:58:57 +02:00
|
|
|
{
|
2012-11-21 07:59:40 +01:00
|
|
|
Arabica::SAX::InputSource<std::string> is(filename);
|
|
|
|
Arabica::SAX2DOM::Parser<std::string> parser;
|
2007-07-19 18:58:57 +02:00
|
|
|
parser.parse(is);
|
|
|
|
|
|
|
|
return parser.getDocument();
|
|
|
|
} // buildDOM
|
|
|
|
|