27 #ifndef RL_XML_STYLESHEET_H
28 #define RL_XML_STYLESHEET_H
34 #include <boost/shared_array.hpp>
35 #include <libxslt/transform.h>
36 #include <libxslt/xsltInternals.h>
49 stylesheet(::xsltNewStylesheet(), ::xsltFreeStylesheet)
59 stylesheet(::xsltParseStylesheetDoc(document.
get()), ::xsltFreeStylesheet)
65 stylesheet(::xsltParseStylesheetFile(reinterpret_cast<const ::xmlChar*>(filename.c_str())), ::xsltFreeStylesheet)
75 return Document(::xsltApplyStylesheet(this->
stylesheet.get(), this->stylesheet.get()->doc,
nullptr));
78 Document apply(const ::std::map< ::std::string, ::std::string>& parameters)
80 ::std::vector<const char*> params;
82 for (::std::map< ::std::string, ::std::string>::const_iterator i = parameters.begin(); i != parameters.end(); ++i)
84 params.push_back(i->first.c_str());
85 params.push_back(i->second.c_str());
88 params.push_back(
nullptr);
90 return Document(::xsltApplyStylesheet(this->
stylesheet.get(), this->stylesheet.get()->doc, params.data()));
100 ::std::vector<const char*> params;
102 for (::std::map< ::std::string, ::std::string>::const_iterator i = parameters.begin(); i != parameters.end(); ++i)
104 params.push_back(i->first.c_str());
105 params.push_back(i->second.c_str());
108 params.push_back(
nullptr);
118 ::xmlDocDumpFormatMemory(this->
stylesheet.get()->doc, &mem, &size, format ? 1 : 0);
119 ::boost::shared_array< ::xmlChar> memory(mem, ::xmlFree);
121 return nullptr != memory.get() ?
reinterpret_cast<const char*
>(memory.get()) : ::std::string();
129 ::xmlDocDumpMemory(this->
stylesheet.get()->doc, &mem, &size);
130 ::boost::shared_array< ::xmlChar> memory(mem, ::xmlFree);
132 return nullptr != memory.get() ?
reinterpret_cast<const char*
>(memory.get()) : ::std::string();
135 ::xsltStylesheetPtr
get()
const
142 return nullptr != this->
stylesheet.get()->doc->encoding ?
reinterpret_cast<const char*
>(this->
stylesheet.get()->doc->encoding) : ::std::string();
152 return nullptr != this->
stylesheet.get()->doc->version ?
reinterpret_cast<const char*
>(this->
stylesheet.get()->doc->version) : ::std::string();
160 void save(const ::std::string& filename,
const bool& format =
true)
const
162 ::xmlSaveFormatFile(filename.c_str(), this->stylesheet.get()->doc, format ? 1 : 0);
165 void save(const ::std::string& filename, const ::std::string& encoding,
const bool& format =
true)
const
167 ::xmlSaveFormatFileEnc(filename.c_str(), this->stylesheet.get()->doc, encoding.c_str(), format ? 1 : 0);
172 int substitutions = ::xmlXIncludeProcessFlags(this->
stylesheet.get()->doc, flags);
174 if (-1 == substitutions)
176 throw Exception(::xmlGetLastError()->message);
179 return substitutions;
190 #endif // RL_XML_STYLESHEET_H