[glom] Move some XSLT-processing code around.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Move some XSLT-processing code around.
- Date: Mon, 17 Oct 2011 16:27:38 +0000 (UTC)
commit 854ba701db0a79a52b16db65a97300b4b3e3e7be
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Oct 17 17:58:46 2011 +0200
Move some XSLT-processing code around.
* glom/mode_data/box_data.h: Remove declaration of non-implemented
and unused xslt_process() method.
* glom/xsl_utils.[h|cc]: Move xslt_process() in to the .cc file as a
static function.
ChangeLog | 9 ++++
glom/mode_data/box_data.h | 1 -
glom/xsl_utils.cc | 107 +++++++++++++++++++++++----------------------
glom/xsl_utils.h | 1 -
4 files changed, 63 insertions(+), 55 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 601f968..0fa586b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2011-10-17 Murray Cumming <murrayc murrayc com>
+ Move some XSLT-processing code around.
+
+ * glom/mode_data/box_data.h: Remove declaration of non-implemented
+ and unused xslt_process() method.
+ * glom/xsl_utils.[h|cc]: Move xslt_process() in to the .cc file as a
+ static function.
+
+2011-10-17 Murray Cumming <murrayc murrayc com>
+
Move some Report code around.
* glom/mode_data/box_data_manyrecords.cc: print_layout():
diff --git a/glom/mode_data/box_data.h b/glom/mode_data/box_data.h
index aae9f7e..e009254 100644
--- a/glom/mode_data/box_data.h
+++ b/glom/mode_data/box_data.h
@@ -120,7 +120,6 @@ private:
void on_python_requested_start_new_record();
protected:
- static Glib::ustring xslt_process(const xmlpp::Document& xml_document, const std::string& filepath_xslt);
#ifndef GLOM_ENABLE_CLIENT_ONLY
virtual Dialog_Layout* create_layout_dialog() const = 0;
diff --git a/glom/xsl_utils.cc b/glom/xsl_utils.cc
index 69aa56e..2ee52b7 100644
--- a/glom/xsl_utils.cc
+++ b/glom/xsl_utils.cc
@@ -65,6 +65,60 @@ namespace
namespace Glom
{
+
+static Glib::ustring xslt_process(const xmlpp::Document& xml_document, const std::string& filepath_xslt)
+{
+ //Debug output:
+ //std::cout << "XML before XSLT processing: " << std::endl;
+ //std::cout << " ";
+ //xmlpp::Document& nonconst = const_cast<xmlpp::Document&>(xml_document);
+ //nonconst.write_to_stream_formatted(std::cout);
+ //std::cout << std::endl;
+
+ Glib::ustring result;
+
+ //Use libxslt to transform the XML:
+ xmlDocPtr style = xmlReadFile(filepath_xslt.c_str(), 0, 0);
+ if(style)
+ {
+ //We need this to be able to use the exsl: functions, even if we declare the namespace at the start of the xsl.
+ //We don't need this anymore - we use xsl:copy-of instead of exsl:node-set (which didn't work as expected anyway):
+ //exsltRegisterAll();
+
+ //Parse the stylesheet:
+ xsltStylesheetPtr cur = xsltParseStylesheetDoc(style);
+ if(cur)
+ {
+ //Use the parsed stylesheet on the XML:
+ xmlDocPtr pDocOutput = xsltApplyStylesheet(cur, const_cast<xmlDoc*>(xml_document.cobj()), 0);
+ xsltFreeStylesheet(cur);
+
+ //Get the output text:
+ xmlChar* buffer = 0;
+ int length = 0;
+ xmlIndentTreeOutput = 1; //Format the output with extra white space. TODO: Is there a better way than this global variable?
+ xmlDocDumpFormatMemoryEnc(pDocOutput, &buffer, &length, 0, 0);
+
+ if(buffer)
+ {
+ // Create a Glib::ustring copy of the buffer
+
+ // Here we force the use of Glib::ustring::ustring( InputIterator begin, InputIterator end )
+ // instead of Glib::ustring::ustring( const char*, size_type ) because it
+ // expects the length of the string in characters, not in bytes.
+ result = Glib::ustring( reinterpret_cast<const char *>(buffer), reinterpret_cast<const char *>(buffer + length) );
+
+ // Deletes the original buffer
+ xmlFree(buffer);
+ }
+
+ xmlFreeDoc(pDocOutput);
+ }
+ }
+
+ return result;
+}
+
void GlomXslUtils::transform_and_open(const xmlpp::Document& xml_document, const Glib::ustring& xsl_file_path, Gtk::Window* parent_window)
{
//Use libxslt to convert the XML to HTML:
@@ -136,57 +190,4 @@ void GlomXslUtils::transform_and_open(const xmlpp::Document& xml_document, const
#endif //G_OS_WIN32
}
-Glib::ustring GlomXslUtils::xslt_process(const xmlpp::Document& xml_document, const std::string& filepath_xslt)
-{
- //Debug output:
- //std::cout << "XML before XSLT processing: " << std::endl;
- //std::cout << " ";
- //xmlpp::Document& nonconst = const_cast<xmlpp::Document&>(xml_document);
- //nonconst.write_to_stream_formatted(std::cout);
- //std::cout << std::endl;
-
- Glib::ustring result;
-
- //Use libxslt to transform the XML:
- xmlDocPtr style = xmlReadFile(filepath_xslt.c_str(), 0, 0);
- if(style)
- {
- //We need this to be able to use the exsl: functions, even if we declare the namespace at the start of the xsl.
- //We don't need this anymore - we use xsl:copy-of instead of exsl:node-set (which didn't work as expected anyway):
- //exsltRegisterAll();
-
- //Parse the stylesheet:
- xsltStylesheetPtr cur = xsltParseStylesheetDoc(style);
- if(cur)
- {
- //Use the parsed stylesheet on the XML:
- xmlDocPtr pDocOutput = xsltApplyStylesheet(cur, const_cast<xmlDoc*>(xml_document.cobj()), 0);
- xsltFreeStylesheet(cur);
-
- //Get the output text:
- xmlChar* buffer = 0;
- int length = 0;
- xmlIndentTreeOutput = 1; //Format the output with extra white space. TODO: Is there a better way than this global variable?
- xmlDocDumpFormatMemoryEnc(pDocOutput, &buffer, &length, 0, 0);
-
- if(buffer)
- {
- // Create a Glib::ustring copy of the buffer
-
- // Here we force the use of Glib::ustring::ustring( InputIterator begin, InputIterator end )
- // instead of Glib::ustring::ustring( const char*, size_type ) because it
- // expects the length of the string in characters, not in bytes.
- result = Glib::ustring( reinterpret_cast<const char *>(buffer), reinterpret_cast<const char *>(buffer + length) );
-
- // Deletes the original buffer
- xmlFree(buffer);
- }
-
- xmlFreeDoc(pDocOutput);
- }
- }
-
- return result;
-}
-
} //namespace Glom
diff --git a/glom/xsl_utils.h b/glom/xsl_utils.h
index fc7d872..a497733 100644
--- a/glom/xsl_utils.h
+++ b/glom/xsl_utils.h
@@ -43,7 +43,6 @@ namespace GlomXslUtils
{
void transform_and_open(const xmlpp::Document& xml_document, const Glib::ustring& xsl_file_path, Gtk::Window* parent_window = 0);
-Glib::ustring xslt_process(const xmlpp::Document& xml_document, const std::string& filepath_xslt);
} //namespace GlomXslUtils
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]