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 xsltStylesheetPtr processStylesheet(GdomeDocument* style)
70 xmlDocPtr style_libxml;
75 style_libxml = libxml_of_gdome(style);
76 style_copy = xmlCopyDoc(style_libxml, 1);
77 style_copy->URL = xmlStrdup(style_libxml->URL);
79 xsltSetGenericDebugFunc(NULL, NULL);
81 return xsltParseStylesheetDoc(style_copy);
84 GdomeDocument* applyStylesheet(GdomeDocument* source, xsltStylesheetPtr style_libxslt, const char** params)
86 xmlDocPtr source_libxml;
87 xmlDocPtr output_libxml;
89 if (source == NULL) return NULL;
90 source_libxml = libxml_of_gdome(source);
92 xsltSetGenericDebugFunc(NULL, NULL);
94 output_libxml = xsltApplyStylesheet(style_libxslt,
98 if (output_libxml == NULL) return NULL;
100 return gdome_of_libxml(output_libxml);
103 /***************** serialization functions *****************/
105 int saveResultToFilename (const char* name,
106 GdomeDocument* result,
107 xsltStylesheetPtr style_libxslt,
110 xmlDocPtr result_libxml;
112 if (result == NULL) return -1;
113 result_libxml = libxml_of_gdome(result);
115 xsltSetGenericDebugFunc(NULL, NULL);
117 return xsltSaveResultToFilename(name,
123 int saveResultToFile (FILE* file,
124 GdomeDocument* result,
125 xsltStylesheetPtr style_libxslt)
127 xmlDocPtr result_libxml;
129 if (result == NULL) return -1;
130 result_libxml = libxml_of_gdome(result);
132 xsltSetGenericDebugFunc(NULL, NULL);
134 return xsltSaveResultToFile(file,
139 int saveResultToFd (int fd,
140 GdomeDocument* result,
141 xsltStylesheetPtr style_libxslt)
143 xmlDocPtr result_libxml;
145 if (result == NULL) return -1;
146 result_libxml = libxml_of_gdome(result);
148 xsltSetGenericDebugFunc(NULL, NULL);
150 return xsltSaveResultToFd(fd,