XSLTProc.cpp

XSLTProc program; a simple clone of libxslt's xsltproc. Binary should be installed as ui-gxmlcpp-xsltproc.

// Local configuration
#include "config.h"
// STDC++
#include <iostream>
#include <cassert>
// C++ libraries
#include <ui-gxmlcpp/Conf.hpp>
#include <ui-gxmlcpp/Tree.hpp>
#include <ui-gxmlcpp/XSLTree.hpp>
#include <ui-gxmlcpp/XSLTransTree.hpp>
int main(int argc, char** argv)
{
try
{
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " XSL-FILE XML-FILE" << std::endl;
exit(1);
}
// libxml2/xslt global configuration
UI::GXML::Conf conf;
conf.setEXSLT();
// Parse xsl and xml trees
UI::GXML::XSLTree xslTree(UI::GXML::Tree::File_, argv[1]);
UI::GXML::Tree xmlTree(UI::GXML::Tree::File_, argv[2]);
// Get xsl translation result (with parameter example; this program should be updated to accept params via arguments)
UI::GXML::XSLTransTree xslTransTree(xslTree, xmlTree, UI::GXML::XSLTransTree::Params().add("example_only_param1", "value1").add("example_only_param2", "value2"));
// Get xsl translation result dump
// Note: For simplicity (i.e., if you don't need to hold/cache/work
// with the result) you could also simply use Tree::dump())
UI::GXML::XSLTransTree::Dump dump(xslTransTree);
// Output xsl translation dump
std::cerr << "Encoding is: " << dump.getEncoding() << std::endl;
std::cout << dump.get();
}
catch (std::exception const & e)
{
std::cerr << "Error: " << e.what() << std::endl;
}
}
Conf.hpp
Tree.hpp
XSLTransTree.hpp
XSLTree.hpp
UI::GXML::Conf
libxml2/libxslt configuration helper.
Definition Conf.hpp:26
UI::GXML::Conf::setEXSLT
Conf & setEXSLT()
Register exslt functions for use with xsl transformations.
Definition Conf.cpp:71
UI::GXML::Tree
XML tree.
Definition Tree.hpp:31
UI::GXML::XSLTransTree::Dump
XSLTransTree serializer.
Definition XSLTransTree.hpp:67
UI::GXML::XSLTransTree::Dump::getEncoding
std::string getEncoding() const
See XSLTree::getOutputEncoding().
Definition XSLTransTree.cpp:103
UI::GXML::XSLTransTree::Params
Parameter abstraction for xsl translations.
Definition XSLTransTree.hpp:49
UI::GXML::XSLTransTree
XSL translation result tree.
Definition XSLTransTree.hpp:36
UI::GXML::XSLTree
XSL (stylesheet) Tree.
Definition XSLTree.hpp:28