1 /* This file is part of an ocaml binding of an XSLT engine working on Gdome
4 * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
5 * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
8 * Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
9 * Stefano Zacchiroli <zack@cs.unibo.it>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * For more information, please send an email to {sacerdot,zack}@cs.unibo.it
30 #include <caml/memory.h>
31 #include <caml/custom.h>
32 #include <caml/callback.h>
34 #include <libxslt/xsltconfig.h>
35 #include <libxslt/imports.h>
38 #include "mlgdomevalue.h"
39 #include "gdome_xslt.h"
41 xsltStylesheetPtr XsltStylesheetPtr_val(value);
43 static void ml_xsltFreeStylesheet(value v)
45 xsltFreeStylesheet(XsltStylesheetPtr_val(v));
48 xsltStylesheetPtr XsltStylesheetPtr_val(value v)
51 xsltStylesheetPtr res = *((xsltStylesheetPtr*) Data_custom_val(v));
55 value Val_XsltStylesheetPtr(xsltStylesheetPtr obj)
59 static struct custom_operations ops = {
60 "http://www.cs.unibo.it/helm/gdome_xslt/XsltStylesheetPtr",
61 ml_xsltFreeStylesheet,
62 custom_compare_default,
64 custom_serialize_default,
65 custom_deserialize_default
68 v = alloc_custom(&ops, sizeof(xsltStylesheetPtr), 0, 1);
69 *((xsltStylesheetPtr*) Data_custom_val(v)) = obj;
74 value ml_processStylesheet(value style)
77 xsltStylesheetPtr res;
78 res = processStylesheet(Document_val(style));
81 excp = caml_named_value("ProcessStylesheetException");
83 raise_constant(*excp);
85 CAMLreturn(Val_XsltStylesheetPtr(res));
88 value setXsltMaxDepth(value depth)
91 xsltMaxDepth = Int_val(depth);
95 value ml_applyStylesheet(value source, value style, value params)
97 CAMLparam3(source,style,params);
101 const char** c_params;
103 i = 0 ; list = params;
104 while(list != Val_int(0)) {
105 list = Field(list,1);
108 c_params = (const char **)malloc(sizeof(char *) * (i * 2 + 1));
110 i = 0; list = params;
111 while(list != Val_int(0)) {
112 c_params[i] = String_val(Field(Field(list,0),0));
113 c_params[i+1] = String_val(Field(Field(list,0),1));
114 list = Field(list,1);
118 res = applyStylesheet(Document_val(source),
119 XsltStylesheetPtr_val(style),
124 excp = caml_named_value("ApplyStylesheetException");
125 assert(excp != NULL);
126 raise_constant(*excp);
128 CAMLreturn(Val_Document(res));
131 value ml_saveResultToChannel(value channel,
135 CAMLparam3(channel, result, stylesheet);
137 saveResultToFd((Channel(channel))->fd,
138 Document_val(result),
139 XsltStylesheetPtr_val(stylesheet));