--- /dev/null
+gdome_xslt.o
--- /dev/null
+INCLUDES = `gdome-config --cflags` `xslt-config --cflags`
+
+gdome_xslt.o: gdome_xslt.c
+ gcc -c $(INCLUDES) $<
+
+clean:
+ rm -f gdome_xslt.o
--- /dev/null
+/* This file implements a XSLT engine working on Gdome documents. In fact,
+ * it just maps Gdome documents to libxml documents back and forth, and
+ * applyes the transformation on libxml documents using libxlt.
+ *
+ * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
+ * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
+ *
+ * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please send an email to <sacerdot@cs.unibo.it>
+ */
+
+#include <stdio.h>
+#include <libgdome/gdome.h>
+#include <libxslt/xsltconfig.h>
+#include <libxslt/xslt.h>
+#include <libxslt/xsltutils.h>
+#include <libxslt/transform.h>
+#include <libxslt/imports.h>
+
+// Begin of Gdome internals exposed
+typedef struct _Gdome_xml_Document Gdome_xml_Document;
+struct _Gdome_xml_Document {
+ GdomeDocument super;
+ const GdomeDocumentVtab* vtab;
+ int refcnt;
+ xmlDocPtr n;
+ GdomeAccessType accessType;
+};
+
+GdomeNode* gdome_xml_n_mkref(xmlNode* n);
+// End of Gdome internals exposed
+
+// Begin of the abstraction of Gdome internals. Uses the Gdome internals exposed
+xmlDocPtr libxml_of_gdome(GdomeDocument* doc)
+{
+ return ((Gdome_xml_Document*)doc)->n;
+}
+
+GdomeDocument* gdome_of_libxml(xmlDocPtr n)
+{
+ return (GdomeDocument*)gdome_xml_n_mkref((xmlNode*)n);
+}
+// End of the abstraction of Gdome internals. Uses the Gdome internals exposed.
+
+
+
+// From now on no Gdome internal should be used directly.
+
+xsltStylesheetPtr processStylesheet(GdomeDocument* style)
+{
+ xmlDocPtr style_copy;
+ xmlDocPtr style_libxml;
+
+ if (style == NULL) {
+ return NULL;
+ }
+ style_libxml = libxml_of_gdome(style);
+ style_copy = xmlCopyDoc(style_libxml, 1);
+ style_copy->URL = xmlStrdup(style_libxml->URL);
+
+ xsltSetGenericDebugFunc(NULL, NULL);
+
+ return xsltParseStylesheetDoc(style_copy);
+}
+
+GdomeDocument* applyStylesheet(GdomeDocument* source, xsltStylesheetPtr style_libxslt, const char** params)
+{
+ xmlDocPtr source_libxml;
+ xmlDocPtr output_libxml;
+
+ if (source == NULL) return NULL;
+ source_libxml = libxml_of_gdome(source);
+
+ xsltSetGenericDebugFunc(NULL, NULL);
+
+ output_libxml = xsltApplyStylesheet(style_libxslt,
+ source_libxml,
+ params);
+
+ if (output_libxml == NULL) return NULL;
+
+ return gdome_of_libxml(output_libxml);
+}
--- /dev/null
+/* This file implements a XSLT engine working on Gdome documents. In fact,
+ * it just maps Gdome documents to libxml documents back and forth, and
+ * applyes the transformation on libxml documents using libxlt.
+ *
+ * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
+ * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
+ *
+ * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please send an email to <sacerdot@cs.unibo.it>
+ */
+
+
+xsltStylesheetPtr processStylesheet(GdomeDocument* style);
+
+GdomeDocument* applyStylesheet(GdomeDocument* source, xsltStylesheetPtr style_libxslt, const char** params);
--- /dev/null
+INCLUDES = `gdome-config --cflags` `xslt-config --cflags` -I $(GDOMEXSLTPATH)
+LIBS = `gdome-config --libs` `xslt-config --libs`
+
+GDOMEXSLTPATH = ../gdome_xslt
+
+test: test.c
+ gcc -o $@ $(INCLUDES) $(LIBS) $(GDOMEXSLTPATH)/gdome_xslt.o $<
+
+clean:
+ rm -f test
--- /dev/null
+/* This file is a test for the XSLT engine working on Gdome documents.
+ *
+ * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please send an email to <sacerdot@cs.unibo.it>
+ */
+
+#include <stdio.h>
+#include <libgdome/gdome.h>
+#include <libxslt/xsltconfig.h>
+#include <libxslt/xslt.h>
+#include <libxslt/imports.h>
+
+#include "gdome_xslt.h"
+
+GdomeDocument* loadDocument(GdomeDOMImplementation *domimpl, char *uri)
+{
+ GdomeDocument *doc;
+ GdomeException exc;
+
+ doc = gdome_di_createDocFromURI(domimpl, uri, GDOME_LOAD_PARSING, &exc);
+ if (doc == NULL) {
+ fprintf (stderr,
+ "DOMImplementation.createDocFromURI: failed\n\tException #%d\n",
+ exc);
+ }
+
+ return doc;
+}
+
+int saveDocument(GdomeDOMImplementation *domimpl, GdomeDocument* doc, char *uri)
+{
+ GdomeException exc;
+
+ if (!gdome_di_saveDocToFile (domimpl, doc, uri, GDOME_SAVE_STANDARD, &exc)) {
+ fprintf (stderr,
+ "DOMImplementation.saveDocToFile: failed\n\tException #%d\n",
+ exc);
+ return 0;
+ }
+
+ return 1;
+}
+
+
+int main(void)
+{
+ GdomeDOMImplementation *domimpl;
+ GdomeDocument *input;
+ GdomeDocument *style;
+ xsltStylesheetPtr style_libxslt;
+ GdomeDocument *output;
+ GdomeException exc;
+ const char* params[] = {"parameter1", "'value1'",
+ "parameter2", "'value2'",
+ "parameter3", "'value3'",
+ NULL};
+
+ domimpl = gdome_di_mkref();
+
+ if (!(input = loadDocument(domimpl, "../../test_files/input.xml"))) return 1;
+ if (!(style = loadDocument(domimpl, "../../test_files/stylesheet.xsl"))) return 1;
+
+ style_libxslt = processStylesheet(style);
+
+ output = applyStylesheet(input, style_libxslt, params);
+
+ if (!(saveDocument(domimpl, output, "../../test_files/output.xml"))) return 1;
+
+ xsltFreeStylesheet(style_libxslt);
+ gdome_di_freeDoc (domimpl, input, &exc);
+ gdome_di_freeDoc (domimpl, style, &exc);
+ gdome_di_freeDoc (domimpl, output, &exc);
+ gdome_di_unref (domimpl, &exc);
+
+ printf("The test was successful iff ../../test_files/output.xml.correct is\n");
+ printf("equal to ../../test_files/output.xml\n");
+
+ return 0;
+}
--- /dev/null
+META
+Makefile
+config.cache
+config.log
+config.status
+configure
+gdome_xslt.cma
+gdome_xslt.cmi
+gdome_xslt.cmo
+gdome_xslt.cmx
+gdome_xslt.cmxa
+gdome_xslt.o
+gdome_xslt_init.cmi
+gdome_xslt_init.cmo
+gdome_xslt_init.cmx
+gdome_xslt_init.o
+i_gdome_xslt.cmi
+i_gdome_xslt.cmo
+i_gdome_xslt.cmx
+i_gdome_xslt.o
+ml_gdome_xslt.o
--- /dev/null
+gdome_xslt_init.cmo: i_gdome_xslt.cmo gdome_xslt_init.cmi
+gdome_xslt_init.cmx: i_gdome_xslt.cmx gdome_xslt_init.cmi
+gdome_xslt.cmo: i_gdome_xslt.cmo gdome_xslt.cmi
+gdome_xslt.cmx: i_gdome_xslt.cmx gdome_xslt.cmi
+gdome_xslt.cmi: i_gdome_xslt.cmo
--- /dev/null
+requires="gdome2"
+version="@VERSION@"
+archive(byte)="gdome_xslt_init.cmo gdome_xslt.cma"
+archive(native)="gdome_xslt_init.cmx gdome_xslt.cmxa"
+linkopts=""
--- /dev/null
+PACKAGE = @PACKAGE@
+VERSION = @VERSION@
+INCLUDEDIR = @OCAML_INCLUDE_DIR@
+CGDOMEXSLTPATH = ../../C/gdome_xslt
+PREFIX =
+OBJECTS_C = ml_gdome_xslt.o
+OBJECTS = i_gdome_xslt.cmo gdome_xslt.cmo
+OBJECTS_NOT_IN_ARCHIVE = gdome_xslt_init.cmo
+OBJECTS_OPT = i_gdome_xslt.cmx gdome_xslt.cmx
+OBJECTS_OPT_NOT_IN_ARCHIVE = gdome_xslt_init.cmx
+INST = META gdome_xslt_init.cmi i_gdome_xslt.cmi gdome_xslt.cmi gdome_xslt_init.cmo gdome_xslt.mli gdome_xslt_init.mli
+INSTOPT = gdome_xslt_init.cmx gdome_xslt_init.o
+DIST_FILES = \
+ AUTHORS COPYING ChangeLog LICENSE Makefile.in NEWS README \
+ configure.in ml_gdome_xslt.c gdome_xslt_init.ml i_gdome_xslt.ml \
+ gdome_xslt.ml META.in
+DOC_FILES = AUTHORS COPYING ChangeLog NEWS README
+REQUIRES = gdome2
+PREDICATES =
+MLFLAGS = -labels
+
+OCAMLC = ocamlfind ocamlc $(MLFLAGS)
+OCAMLOPT = ocamlfind ocamlopt $(MLFLAGS)
+OCAMLDEP = ocamldep
+
+ARCHIVE = $(PACKAGE).cma
+ARCHIVE_A = $(PACKAGE).a
+ARCHIVE_SO = dll$(PACKAGE).so
+ARCHIVE_OPT = $(PACKAGE).cmxa
+
+all: $(ARCHIVE) $(ARCHIVE_SO) $(OBJECTS_NOT_IN_ARCHIVE)
+
+opt: $(OBJECTS_C) $(ARCHIVE_OPT) $(ARCHIVE_A) $(ARCHIVE_SO) $(OBJECTS_OPT_NOT_IN_ARCHIVE)
+
+dist:
+ rm -rf $(PACKAGE)-$(VERSION)
+ mkdir $(PACKAGE)-$(VERSION)
+ cp $(DIST_FILES) $(DOC_FILES) $(PACKAGE)-$(VERSION)
+ tar cvfz $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)
+ rm -rf $(PACKAGE)-$(VERSION)
+
+ml_gdome_xslt.o: ml_gdome_xslt.c
+ gcc -c -I$(INCLUDEDIR) `gdome-config --cflags` `ocamlfind query -i-format gdome2` -I$(CGDOMEXSLTPATH) $<
+
+.SUFFIXES: .cmo .cmi .cmx .ml .mli
+
+.ml.cmo:
+ $(OCAMLC) -package "$(REQUIRES)" -predicates "$(PREDICATES)" \
+ -c $<
+.mli.cmi:
+ $(OCAMLC) -package "$(REQUIRES)" -predicates "$(PREDICATES)" \
+ -c $<
+.ml.cmx:
+ $(OCAMLOPT) -package "$(REQUIRES)" -predicates "$(PREDICATES)" \
+ -c $<
+
+depend: *.ml *.mli
+ $(OCAMLDEP) *.ml *.mli >.depend
+include .depend
+
+$(ARCHIVE): $(OBJECTS) $(ARCHIVE_SO)
+ $(OCAMLC) -a -package "$(REQUIRES)" \
+ -predicates "$(PREDICATES)" -o $@ $^ \
+ -cclib "`gdome-config --libs`" -dllib -l$(PACKAGE)
+$(ARCHIVE_OPT) $(ARCHIVE_A): $(OBJECTS_OPT)
+ INSTPATH=`ocamlfind query gdome2` ; \
+ $(OCAMLOPT) -a -package "$(REQUIRES)" \
+ -predicates "$(PREDICATES)" -o $@ $^ \
+ -cclib "`gdome-config --libs`" \
+ -cclib "`echo $$INSTPATH | sed "s/\\(.*\\)\\/gdome2/\\1/"`/$(PACKAGE)/$(ARCHIVE_SO)"
+
+$(ARCHIVE_SO): $(OBJECTS_C)
+ gcc -shared -o $@ $< $(CGDOMEXSLTPATH)/gdome_xslt.o -lmlgdome -lxslt -L `ocamlfind query gdome2` -Xlinker -rpath -Xlinker `ocamlfind query gdome2`
+
+
+
+install:
+ test ! -f $(ARCHIVE_OPT) || extra="$(ARCHIVE_A) $(ARCHIVE_OPT) $(INSTOPT)" ; \
+ ocamlfind install $(PACKAGE) $(ARCHIVE) $(ARCHIVE_SO) $(INST) $$extra
+
+uninstall:
+ ocamlfind remove $(PACKAGE)
+
+clean:
+ rm -f *.o *.cm? $(ARCHIVE) $(ARCHIVE_A) $(ARCHIVE_SO) $(ARCHIVE_OPT)
+
+distclean: clean
+ rm -f config.log config.cache config.status Makefile META
--- /dev/null
+AC_INIT(gdome_xslt.ml)
+
+PACKAGE=gdome_xslt
+
+GDOMEXSLT_MAJOR_VERSION=0
+GDOMEXSLT_MINOR_VERSION=0
+GDOMEXSLT_MICRO_VERSION=1
+GDOMEXSLT_VERSION=$GDOMEXSLT_MAJOR_VERSION.$GDOMEXSLT_MINOR_VERSION.$GDOMEXSLT_MICRO_VERSION
+VERSION=$GDOMEXSLT_VERSION
+
+AC_CHECK_PROG(HAVE_OCAMLC, ocamlc, yes, no)
+if test $HAVE_OCAMLC = "no"; then
+ AC_MSG_ERROR(could not find ocamlc in PATH, please make sure ocaml is installed)
+fi
+
+AC_CHECK_PROG(HAVE_OCAMLFIND, ocamlfind, yes, no)
+if test $HAVE_OCAMLFIND = "no"; then
+ AC_MSG_ERROR(could not find ocamlfind in PATH, please make sure findlib is installed)
+fi
+
+AC_MSG_CHECKING("for gdome2")
+ocamlfind query gdome2 ||
+ AC_MSG_ERROR(gdome2 not installed (according to findlib))
+
+AC_MSG_CHECKING("for the ocaml library dir")
+OCAML_LIB_DIR=`ocamlc -where`
+AC_MSG_RESULT($OCAML_LIB_DIR)
+
+AC_CHECK_FILE(/usr/include/caml/mlvalues.h,
+ OCAML_INCLUDE_DIR=/usr/include/caml,
+ OCAML_INCLUDE_DIR=$OCAML_LIB_DIR/caml
+)
+
+AC_SUBST(PACKAGE)
+AC_SUBST(VERSION)
+AC_SUBST(OCAML_INCLUDE_DIR)
+
+AC_OUTPUT([
+ Makefile
+ META
+])
--- /dev/null
+(* This file is part of an ocaml binding of an XSLT engine working on Gdome
+ * documents.
+ *
+ * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
+ * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
+ *
+ * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please send an email to <sacerdot@cs.unibo.it>
+ *)
+
+let processStylesheet style =
+ I_gdome_xslt.processStylesheet style#as_Document
+;;
+
+let applyStylesheet ~source ~stylesheet ~params =
+ let res =
+ I_gdome_xslt.applyStylesheet ~source:(source#as_Document) ~stylesheet
+ ~params
+ in
+ new Gdome.document res
+;;
--- /dev/null
+(* This file is part of an ocaml binding of an XSLT engine working on Gdome
+ * documents.
+ *
+ * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
+ * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
+ *
+ * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please send an email to <sacerdot@cs.unibo.it>
+ *)
+
+(* processStylesheet stylesheet *)
+(* Process a stylesheet so that it can be subsequently used *)
+(* with applyStylesheet. *)
+val processStylesheet :
+ Gdome.document -> I_gdome_xslt.processed_stylesheet
+
+(* applyStylesheet source stylesheet params *)
+(* Applies a processed stylesheet to a source document, using *)
+(* the given list of parameters (couples name,value) *)
+val applyStylesheet :
+ source: Gdome.document ->
+ stylesheet:I_gdome_xslt.processed_stylesheet ->
+ params:(string * string) list -> Gdome.document
--- /dev/null
+(* This file is part of an ocaml binding of an XSLT engine working on Gdome
+ * documents.
+ *
+ * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
+ * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
+ *
+ * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please send an email to <sacerdot@cs.unibo.it>
+ *)
+
+exception ProcessStylesheetException
+exception ApplyStylesheetException
+
+let _ =
+ Callback.register_exception
+ "ProcessStylesheetException" ProcessStylesheetException
+;;
+
+let _ =
+ Callback.register_exception
+ "ApplyStylesheetException" ApplyStylesheetException
+;;
+
+I_gdome_xslt.setXsltMaxDepth 2000;;
--- /dev/null
+(* This file is part of an ocaml binding of an XSLT engine working on Gdome
+ * documents.
+ *
+ * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
+ * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
+ *
+ * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please send an email to <sacerdot@cs.unibo.it>
+ *)
+
+(**************************** WARNING!!! ***********************************)
+(*** ***)
+(*** This file must always be linked with any code using gdome_xslt and ***)
+(*** must be linked as the first file. It is responsible of initializing ***)
+(*** the whole binding, registering some ocaml values to the C level. ***)
+(*** ***)
+(***************************************************************************)
+
+exception ProcessStylesheetException
+exception ApplyStylesheetException
--- /dev/null
+(* This file is part of an ocaml binding of an XSLT engine working on Gdome
+ * documents.
+ *
+ * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
+ * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
+ *
+ * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please send an email to <sacerdot@cs.unibo.it>
+ *)
+
+type processed_stylesheet
+
+external setXsltMaxDepth : int -> unit = "setXsltMaxDepth"
+
+external processStylesheet: [> `Document] GdomeT.t -> processed_stylesheet = "ml_processStylesheet"
+external applyStylesheet : source:[> `Document] GdomeT.t -> stylesheet:processed_stylesheet -> params:(string * string) list -> TDocument.t = "ml_applyStylesheet"
--- /dev/null
+/* This file is part of an ocaml binding of an XSLT engine working on Gdome
+ * documents.
+ *
+ * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
+ * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
+ *
+ * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please send an email to <sacerdot@cs.unibo.it>
+ */
+
+#include <assert.h>
+
+#include <caml/memory.h>
+#include <caml/custom.h>
+#include <caml/callback.h>
+
+#include <libxslt/xsltconfig.h>
+#include <libxslt/imports.h>
+
+#include "mlgdomevalue.h"
+#include "gdome_xslt.h"
+
+xsltStylesheetPtr XsltStylesheetPtr_val(value);
+
+static void ml_xsltFreeStylesheet(value v)
+{
+ xsltFreeStylesheet(XsltStylesheetPtr_val(v));
+}
+
+xsltStylesheetPtr XsltStylesheetPtr_val(value v)
+{
+ CAMLparam1(v);
+ xsltStylesheetPtr res = *((xsltStylesheetPtr*) Data_custom_val(v));
+ CAMLreturn(res);
+}
+
+value Val_XsltStylesheetPtr(xsltStylesheetPtr obj)
+{
+ CAMLparam0();
+ CAMLlocal1(v);
+ static struct custom_operations ops = {
+ "http://www.cs.unibo.it/helm/gdome_xslt/XsltStylesheetPtr",
+ ml_xsltFreeStylesheet,
+ custom_compare_default,
+ custom_hash_default,
+ custom_serialize_default,
+ custom_deserialize_default
+ };
+
+ v = alloc_custom(&ops, sizeof(xsltStylesheetPtr), 0, 1);
+ *((xsltStylesheetPtr*) Data_custom_val(v)) = obj;
+
+ CAMLreturn(v);
+}
+
+value ml_processStylesheet(value style)
+{
+ CAMLparam1(style);
+ xsltStylesheetPtr res;
+ res = processStylesheet(Document_val(style));
+ if (res == NULL) {
+ value* excp;
+ excp = caml_named_value("ProcessStylesheetException");
+ assert(excp != NULL);
+ raise_constant(*excp);
+ }
+ CAMLreturn(Val_XsltStylesheetPtr(res));
+}
+
+value setXsltMaxDepth(value depth)
+{
+ CAMLparam1(depth);
+ xsltMaxDepth = Int_val(depth);
+ CAMLreturn0;
+}
+
+value ml_applyStylesheet(value source, value style, value params)
+{
+ CAMLparam3(source,style,params);
+ CAMLlocal1(list);
+ GdomeDocument* res;
+ int i;
+ const char** c_params;
+
+ i = 0 ; list = params;
+ while(list != Val_int(0)) {
+ list = Field(list,1);
+ i++;
+ }
+ c_params = (const char **)malloc(sizeof(char *) * (i * 2 + 1));
+
+ i = 0; list = params;
+ while(list != Val_int(0)) {
+ c_params[i] = String_val(Field(Field(list,0),0));
+ c_params[i+1] = String_val(Field(Field(list,0),1));
+ list = Field(list,1);
+ i+=2;
+ }
+ c_params[i] = NULL;
+ res = applyStylesheet(Document_val(source),
+ XsltStylesheetPtr_val(style),
+ c_params);
+ free(c_params);
+ if (res == NULL) {
+ value* excp;
+ excp = caml_named_value("ApplyStylesheetException");
+ assert(excp != NULL);
+ raise_constant(*excp);
+ }
+ CAMLreturn(Val_Document(res));
+}
--- /dev/null
+/* This file is part of an ocaml binding of an XSLT engine working on Gdome
+ * documents.
+ *
+ * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
+ * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
+ *
+ * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please send an email to <sacerdot@cs.unibo.it>
+ */
+
+xsltStylesheetPtr XsltStylesheetPtr_val(value);
+value Val_XsltStylesheetPtr(xsltStylesheetPtr);
+
+value ml_processStylesheet(value style);
+value ml_applyStylesheet(value source, value style, value params);
--- /dev/null
+test.cmi
+test.cmo
+test.cmx
+test.o
+test
+test.opt
--- /dev/null
+REQUIRES = gdome_xslt
+PREDICATES =
+OCAMLOPTIONS = -package "$(REQUIRES)" -predicates "$(PREDICATES)"
+OCAMLC = ocamlfind ocamlc $(OCAMLOPTIONS)
+OCAMLOPT = ocamlfind ocamlopt $(OCAMLOPTIONS)
+
+all: test
+opt: test.opt
+
+test: test.ml
+ $(OCAMLC) -linkpkg -o $@ $<
+
+test.opt: test.ml
+ $(OCAMLOPT) -linkpkg -o $@ $<
+
+clean:
+ rm -f test test.opt test.cmi test.cmo text.cmx
--- /dev/null
+(* This file is part of an ocaml binding of an XSLT engine working on Gdome
+ * documents.
+ *
+ * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
+ * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
+ *
+ * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please send an email to <sacerdot@cs.unibo.it>
+ *)
+
+let domImpl = Gdome.domImplementation () in
+ let input =
+ domImpl#createDocumentFromURI ~uri:"../../test_files/input.xml" ()
+ and style =
+ domImpl#createDocumentFromURI ~uri:"../../test_files/stylesheet.xsl" ()
+ in
+ (* First of all, let's try the exception handling machinery *)
+ let _ =
+ try
+ ignore (Gdome_xslt.processStylesheet input) ;
+ assert false (* previous line should rise an exception *)
+ with
+ Gdome_xslt_init.ProcessStylesheetException -> ()
+ in
+ let pstyle = Gdome_xslt.processStylesheet style in
+ let output =
+ Gdome_xslt.applyStylesheet input pstyle
+ ["parameter1","'value1'" ;
+ "parameter2","'value2'" ;
+ "parameter3","'value3'"
+ ]
+ in
+ let res =
+ domImpl#saveDocumentToFile ~doc:output ~name:"../../test_files/output.xml"
+ ()
+ in
+ if not res then
+ prerr_endline "Error saving to document ../../test_files/output.xml"
+ else
+ begin
+ print_endline
+ "The test was successful iff ../../test_files/output.xml.correct is" ;
+ print_endline "equal to ../../test_files/output.xml"
+ end
+;;
--- /dev/null
+output.xml
--- /dev/null
+<?xml version="1.0"?>
+<input>
+ <msg>It works!</msg>
+</input>
--- /dev/null
+<?xml version="1.0"?>
+<output><parameter>value2</parameter><parameter>value3</parameter><parameter>value1</parameter>
+ <msg>It works!</msg>
+</output>
--- /dev/null
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:param name="parameter1"/>
+<xsl:param name="parameter2"/>
+<xsl:param name="parameter3"/>
+
+<xsl:template match="/">
+ <output>
+ <parameter><xsl:value-of select="$parameter2"/></parameter>
+ <parameter><xsl:value-of select="$parameter3"/></parameter>
+ <parameter><xsl:value-of select="$parameter1"/></parameter>
+ <xsl:apply-templates/>
+ </output>
+</xsl:template>
+
+<xsl:template match="msg">
+ <xsl:copy-of select="."/>
+</xsl:template>
+
+</xsl:stylesheet>