summaryrefslogtreecommitdiff
path: root/project2/transformHtml.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/transformHtml.cpp')
-rw-r--r--project2/transformHtml.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/project2/transformHtml.cpp b/project2/transformHtml.cpp
new file mode 100644
index 0000000..eae1c27
--- /dev/null
+++ b/project2/transformHtml.cpp
@@ -0,0 +1,30 @@
+#include "transformHtml.h"
+#include "logger.h"
+#include <libxml++/document.h>
+#include <libxslt/xsltutils.h>
+#include <libxslt/transform.h>
+
+class TransformXmlToHtml : public TransformImpl<xmlpp::Document, HtmlDocument> {
+ public:
+ void transform(const xmlpp::Document * cdata, HtmlDocument * result) const
+ {
+ xmlpp::Document * data = const_cast<xmlpp::Document *>(cdata);
+ typedef boost::shared_ptr<xsltStylesheet> XsltStyleSheetPtr;
+ XsltStyleSheetPtr cur = XsltStyleSheetPtr(xsltParseStylesheetFile(BAD_CAST stylesheet.c_str()), xsltFreeStylesheet);
+ if (!cur) {
+ throw xmlpp::exception("Failed to load stylesheet");
+ }
+ result->doc = xsltApplyStylesheet(cur.get(), data->cobj(), NULL);
+ if (!result) {
+ throw xmlpp::exception("Failed to perform transformation");
+ }
+ }
+ void configure(const xmlpp::Element * e)
+ {
+ stylesheet = e->get_attribute_value("style");
+ }
+ private:
+ Glib::ustring stylesheet;
+};
+DECLARE_TRANSFORM(TransformXmlToHtml)
+