]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.c
Initial version.
[helm.git] / helm / DEVEL / gdome_xslt / C / gdome_xslt / gdome_xslt.c
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.
4  * 
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)
7  *
8  * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
9  * 
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  * 
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  * 
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  *
24  * For more information, please send an email to <sacerdot@cs.unibo.it>
25  */
26
27 #include <stdio.h>
28 #include <libgdome/gdome.h>
29 #include <libxslt/xsltconfig.h>
30 #include <libxslt/xslt.h>
31 #include <libxslt/xsltutils.h>
32 #include <libxslt/transform.h>
33 #include <libxslt/imports.h>
34
35 // Begin of Gdome internals exposed
36 typedef struct _Gdome_xml_Document Gdome_xml_Document;
37 struct _Gdome_xml_Document {
38         GdomeDocument super;
39         const GdomeDocumentVtab* vtab;
40         int refcnt;
41         xmlDocPtr n;
42         GdomeAccessType accessType;
43 };
44
45 GdomeNode* gdome_xml_n_mkref(xmlNode* n);
46 // End of Gdome internals exposed
47
48 // Begin of the abstraction of Gdome internals. Uses the Gdome internals exposed
49 xmlDocPtr libxml_of_gdome(GdomeDocument* doc)
50 {
51    return ((Gdome_xml_Document*)doc)->n;
52 }
53
54 GdomeDocument* gdome_of_libxml(xmlDocPtr n)
55 {
56    return (GdomeDocument*)gdome_xml_n_mkref((xmlNode*)n);
57 }
58 // End of the abstraction of Gdome internals. Uses the Gdome internals exposed.
59
60
61
62 // From now on no Gdome internal should be used directly.
63
64 xsltStylesheetPtr processStylesheet(GdomeDocument* style)
65 {
66    xmlDocPtr style_copy;
67    xmlDocPtr style_libxml;
68
69    if (style == NULL) {
70       return NULL;
71    }
72    style_libxml = libxml_of_gdome(style);
73    style_copy = xmlCopyDoc(style_libxml, 1);
74    style_copy->URL = xmlStrdup(style_libxml->URL);
75
76    xsltSetGenericDebugFunc(NULL, NULL);
77
78    return xsltParseStylesheetDoc(style_copy);
79 }
80
81 GdomeDocument* applyStylesheet(GdomeDocument* source, xsltStylesheetPtr style_libxslt, const char** params)
82 {
83    xmlDocPtr source_libxml;
84    xmlDocPtr output_libxml;
85
86    if (source == NULL) return NULL;
87    source_libxml = libxml_of_gdome(source);
88
89    xsltSetGenericDebugFunc(NULL, NULL);
90
91    output_libxml = xsltApplyStylesheet(style_libxslt,
92                                        source_libxml,
93                                        params);
94
95    if (output_libxml == NULL) return NULL;
96
97    return gdome_of_libxml(output_libxml);
98 }