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)
7 * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * For more information, please send an email to <sacerdot@cs.unibo.it>
28 #include <caml/memory.h>
29 #include <caml/custom.h>
30 #include <caml/callback.h>
32 #include <libxslt/xsltconfig.h>
33 #include <libxslt/imports.h>
35 #include "mlgdomevalue.h"
36 #include "gdome_xslt.h"
38 xsltStylesheetPtr XsltStylesheetPtr_val(value);
40 static void ml_xsltFreeStylesheet(value v)
42 xsltFreeStylesheet(XsltStylesheetPtr_val(v));
45 xsltStylesheetPtr XsltStylesheetPtr_val(value v)
48 xsltStylesheetPtr res = *((xsltStylesheetPtr*) Data_custom_val(v));
52 value Val_XsltStylesheetPtr(xsltStylesheetPtr obj)
56 static struct custom_operations ops = {
57 "http://www.cs.unibo.it/helm/gdome_xslt/XsltStylesheetPtr",
58 ml_xsltFreeStylesheet,
59 custom_compare_default,
61 custom_serialize_default,
62 custom_deserialize_default
65 v = alloc_custom(&ops, sizeof(xsltStylesheetPtr), 0, 1);
66 *((xsltStylesheetPtr*) Data_custom_val(v)) = obj;
71 value ml_processStylesheet(value style)
74 xsltStylesheetPtr res;
75 res = processStylesheet(Document_val(style));
78 excp = caml_named_value("ProcessStylesheetException");
80 raise_constant(*excp);
82 CAMLreturn(Val_XsltStylesheetPtr(res));
85 value setXsltMaxDepth(value depth)
88 xsltMaxDepth = Int_val(depth);
92 value ml_applyStylesheet(value source, value style, value params)
94 CAMLparam3(source,style,params);
98 const char** c_params;
100 i = 0 ; list = params;
101 while(list != Val_int(0)) {
102 list = Field(list,1);
105 c_params = (const char **)malloc(sizeof(char *) * (i * 2 + 1));
107 i = 0; list = params;
108 while(list != Val_int(0)) {
109 c_params[i] = String_val(Field(Field(list,0),0));
110 c_params[i+1] = String_val(Field(Field(list,0),1));
111 list = Field(list,1);
115 res = applyStylesheet(Document_val(source),
116 XsltStylesheetPtr_val(style),
121 excp = caml_named_value("ApplyStylesheetException");
122 assert(excp != NULL);
123 raise_constant(*excp);
125 CAMLreturn(Val_Document(res));