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)
8 * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
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.
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.
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
24 * For more information, please send an email to <sacerdot@cs.unibo.it>
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>
35 // Begin of Gdome internals exposed
36 typedef struct _Gdome_xml_Document Gdome_xml_Document;
37 struct _Gdome_xml_Document {
39 const GdomeDocumentVtab* vtab;
42 GdomeAccessType accessType;
45 GdomeNode* gdome_xml_n_mkref(xmlNode* n);
46 // End of Gdome internals exposed
48 // Begin of the abstraction of Gdome internals. Uses the Gdome internals exposed
49 xmlDocPtr libxml_of_gdome(GdomeDocument* doc)
51 return ((Gdome_xml_Document*)doc)->n;
54 GdomeDocument* gdome_of_libxml(xmlDocPtr n)
56 return (GdomeDocument*)gdome_xml_n_mkref((xmlNode*)n);
58 // End of the abstraction of Gdome internals. Uses the Gdome internals exposed.
62 // From now on no Gdome internal should be used directly.
64 xsltStylesheetPtr processStylesheet(GdomeDocument* style)
67 xmlDocPtr style_libxml;
72 style_libxml = libxml_of_gdome(style);
73 style_copy = xmlCopyDoc(style_libxml, 1);
74 style_copy->URL = xmlStrdup(style_libxml->URL);
76 xsltSetGenericDebugFunc(NULL, NULL);
78 return xsltParseStylesheetDoc(style_copy);
81 GdomeDocument* applyStylesheet(GdomeDocument* source, xsltStylesheetPtr style_libxslt, const char** params)
83 xmlDocPtr source_libxml;
84 xmlDocPtr output_libxml;
86 if (source == NULL) return NULL;
87 source_libxml = libxml_of_gdome(source);
89 xsltSetGenericDebugFunc(NULL, NULL);
91 output_libxml = xsltApplyStylesheet(style_libxslt,
95 if (output_libxml == NULL) return NULL;
97 return gdome_of_libxml(output_libxml);