1 /* This file implements a XSLT engine working on Gdome documents. In fact,
2 * it just maps Gdome documents to libxml documents back and forth, and
3 * applyes the transformation on libxml documents using libxlt.
5 * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
6 * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
9 * Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
10 * Stefano Zacchiroli <zack@cs.unibo.it>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * For more information, please send an email to {sacerdot,zack}@cs.unibo.it
30 #include <libgdome/gdome.h>
31 #include <libxslt/xsltconfig.h>
32 #include <libxslt/xslt.h>
33 #include <libxslt/xsltutils.h>
34 #include <libxslt/transform.h>
35 #include <libxslt/imports.h>
36 #include "gdome_xslt.h"
38 // Begin of Gdome internals exposed
39 typedef struct _Gdome_xml_Document Gdome_xml_Document;
40 struct _Gdome_xml_Document {
42 const GdomeDocumentVtab* vtab;
45 GdomeAccessType accessType;
48 GdomeNode* gdome_xml_n_mkref(xmlNode* n);
49 // End of Gdome internals exposed
51 // Begin of the abstraction of Gdome internals. Uses the Gdome internals exposed
52 xmlDocPtr libxml_of_gdome(GdomeDocument* doc)
54 return ((Gdome_xml_Document*)doc)->n;
57 GdomeDocument* gdome_of_libxml(xmlDocPtr n)
59 return (GdomeDocument*)gdome_xml_n_mkref((xmlNode*)n);
61 // End of the abstraction of Gdome internals. Uses the Gdome internals exposed.
65 // From now on no Gdome internal should be used directly.
67 /******************************/
68 /* XSLT stylesheet Processing */
69 /******************************/
71 xsltStylesheetPtr processStylesheet(GdomeDocument* style)
74 xmlDocPtr style_libxml;
79 style_libxml = libxml_of_gdome(style);
80 style_copy = xmlCopyDoc(style_libxml, 1);
81 style_copy->URL = xmlStrdup(style_libxml->URL);
83 xsltSetGenericDebugFunc(NULL, NULL);
85 return xsltParseStylesheetDoc(style_copy);
88 /*******************************/
89 /* XSLT stylesheet Application */
90 /*******************************/
92 GdomeDocument* applyStylesheet(GdomeDocument* source, xsltStylesheetPtr
93 style_libxslt, const char** params)
95 xmlDocPtr source_libxml;
96 xmlDocPtr output_libxml;
98 if (source == NULL) return NULL;
99 source_libxml = libxml_of_gdome(source);
101 xsltSetGenericDebugFunc(NULL, NULL);
103 output_libxml = xsltApplyStylesheet(style_libxslt, source_libxml,
106 if (output_libxml == NULL) return NULL;
108 return gdome_of_libxml(output_libxml);
115 int saveResultToFilename (const char* name, GdomeDocument* result,
116 xsltStylesheetPtr style_libxslt, int compression)
118 xmlDocPtr result_libxml;
120 if (result == NULL) return -1;
121 result_libxml = libxml_of_gdome(result);
123 xsltSetGenericDebugFunc(NULL, NULL);
125 return xsltSaveResultToFilename(name, result_libxml,
126 style_libxslt, compression);
129 int saveResultToFile (FILE* file, GdomeDocument* result,
130 xsltStylesheetPtr style_libxslt)
132 xmlDocPtr result_libxml;
134 if (result == NULL) return -1;
135 result_libxml = libxml_of_gdome(result);
137 xsltSetGenericDebugFunc(NULL, NULL);
139 return xsltSaveResultToFile(file, result_libxml, style_libxslt);
142 int saveResultToFd (int fd, GdomeDocument* result, xsltStylesheetPtr
145 xmlDocPtr result_libxml;
147 if (result == NULL) return -1;
148 result_libxml = libxml_of_gdome(result);
150 xsltSetGenericDebugFunc(NULL, NULL);
152 return xsltSaveResultToFd(fd, result_libxml, style_libxslt);