1 // This file is part of a XSLT engine working on Gdome documents. In fact,
2 // it just maps Gdome documents to libxml documents back and forth, and
3 // applies the transformation on libxml documents using libxlt.
5 // Copyright (C) 2002: Luca Padovani <lpadovan@cs.unibo.it>
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Lesser General Public License for more details.
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 // For more information, please send an email to lpadovan@cs.unibo.it
28 #include <GdomeSmartDOM.hh>
30 #include "GdomeSmartDOMXSLTStylesheet.hh"
32 namespace GdomeSmartDOM {
34 XSLTStylesheet::XSLTStylesheet(const Document& doc)
37 GdomeDocument* _doc = gdome_cast_doc(doc.gdome_object());
39 stylesheet = processStylesheet(_doc);
40 GdomeException _exc = 0;
41 gdome_doc_unref(_doc, &_exc);
45 XSLTStylesheet::~XSLTStylesheet()
49 xsltFreeStylesheet(stylesheet);
55 XSLTStylesheet::apply(const Document& source, const std::vector< std::pair<GdomeString,GdomeString> >& params) const
59 char** _params = (char**) malloc(sizeof(char*) * (2 * params.size() + 1));
60 for (unsigned i = 0; i < params.size(); i++)
62 std::string param = params[i].first;
63 _params[2 * i] = strdup(param.c_str());
64 std::string value = params[i].second;
65 _params[2 * i + 1] = strdup(value.c_str());
67 _params[2 * params.size()] = 0;
69 GdomeDocument* _source = gdome_cast_doc(source.gdome_object());
71 GdomeDocument* _result = applyStylesheet(_source, stylesheet, const_cast<const char**>(_params));
73 GdomeException _exc = 0;
74 gdome_doc_unref(_source, &_exc);
77 for (unsigned i = 0; i < 2 * params.size(); i++) free(_params[i]);
80 Document result(_result);
81 gdome_doc_unref(_result, &_exc);
88 XSLTStylesheet::save(const Document& doc, const std::string& filename) const
91 GdomeException _exc = 0;
92 GdomeDocument* _doc = gdome_cast_doc(doc.gdome_object());
94 if (saveResultToFilename(filename.c_str(), _doc, stylesheet, 0) < 0) throw SaveException();
95 gdome_doc_unref(_doc, &_exc);
100 XSLTStylesheet::save(const Document& doc, FILE* f) const
103 GdomeException _exc = 0;
104 GdomeDocument* _doc = gdome_cast_doc(doc.gdome_object());
106 if (saveResultToFile(f, _doc, stylesheet) < 0) throw SaveException();
107 gdome_doc_unref(_doc, &_exc);
112 XSLTStylesheet::save(const Document& doc, int fd) const
115 GdomeException _exc = 0;
116 GdomeDocument* _doc = gdome_cast_doc(doc.gdome_object());
118 if (saveResultToFd(fd, _doc, stylesheet) < 0) throw SaveException();
119 gdome_doc_unref(_doc, &_exc);