summaryrefslogtreecommitdiff
path: root/libexslt/dynamic.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2002-05-30 21:36:59 +0000
committerDaniel Veillard <veillard@src.gnome.org>2002-05-30 21:36:59 +0000
commit765957430fd4b748c2d8f70ee546308fad4359f8 (patch)
tree0bfb731b03dab66fedac30a14387f416d3b75699 /libexslt/dynamic.c
parent52a0b2ad40bcde4926878b6260f02d052944b61f (diff)
downloadlibxslt-765957430fd4b748c2d8f70ee546308fad4359f8.tar.gz
libxslt-765957430fd4b748c2d8f70ee546308fad4359f8.tar.bz2
libxslt-765957430fd4b748c2d8f70ee546308fad4359f8.zip
applied a patch from Mark Vakoc to implement the EXSLT object
* win32/Makefile.msvc libexslt/Makefile.am libexslt/date.c libexslt/dynamic.c libexslt/exslt.c libexslt/exslt.h: applied a patch from Mark Vakoc to implement the EXSLT object dyn:evaluate(string) extension function, and a small fix to date.c Daniel
Diffstat (limited to 'libexslt/dynamic.c')
-rw-r--r--libexslt/dynamic.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/libexslt/dynamic.c b/libexslt/dynamic.c
new file mode 100644
index 00000000..c3443dcc
--- /dev/null
+++ b/libexslt/dynamic.c
@@ -0,0 +1,96 @@
+/*
+ * dynamic.c: Implementation of the EXSLT -- Dynamic module
+ *
+ * References:
+ * http://www.exslt.org/dyn/dyn.html
+ *
+ * See Copyright for the status of this software.
+ *
+ * Authors:
+ * Mark Vakoc <mark_vakoc@jdedwards.com>
+ * Thomas Broyer <tbroyer@ltgt.net>
+ *
+ * TODO:
+ * elements:
+ * functions:
+ * min
+ * max
+ * sum
+ * map
+ * closure
+ */
+
+#define IN_LIBEXSLT
+#include "libexslt/libexslt.h"
+
+#if defined(WIN32) && !defined (__CYGWIN__)
+#include <win32config.h>
+#else
+#include "config.h"
+#endif
+
+#include <libxml/tree.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+
+#include <libxslt/xsltconfig.h>
+#include <libxslt/xsltutils.h>
+#include <libxslt/xsltInternals.h>
+#include <libxslt/extensions.h>
+
+#include "exslt.h"
+
+/**
+ * exsltDynEvaluateFunction:
+ * @ctxt: an XPath parser context
+ * @nargs: the number of arguments
+ *
+ * Evaluates the string as an XPath expression and returns the result
+ * value, which may be a boolean, number, string, node set, result tree
+ * fragment or external object.
+ */
+
+void
+exsltDynEvaluateFunction(xmlXPathParserContextPtr ctxt, int nargs) {
+ xmlChar *str = NULL;
+ xmlXPathObjectPtr ret = NULL;
+
+ if (ctxt == NULL)
+ return;
+ if (nargs != 1) {
+ xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt), NULL, NULL);
+ xsltGenericError(xsltGenericErrorContext,
+ "dyn:evalute() : invalid number of args %d\n", nargs);
+ ctxt->error = XPATH_INVALID_ARITY;
+ return;
+ }
+ str = xmlXPathPopString(ctxt);
+ /* return an empty node-set if an empty string is passed in */
+ if (!str||!xmlStrlen(str)) {
+ if (str) xmlFree(str);
+ valuePush(ctxt,xmlXPathNewNodeSet(NULL));
+ return;
+ }
+ ret = xmlXPathEval(str,ctxt->context);
+ if (ret)
+ valuePush(ctxt,ret);
+ else {
+ xsltGenericError(xsltGenericErrorContext,
+ "dyn:evaluate() : unable to evaluate expression '%s'\n",str);
+ valuePush(ctxt,xmlXPathNewNodeSet(NULL));
+ }
+ xmlFree(str);
+ return;
+}
+/**
+ * exsltDynRegister:
+ *
+ * Registers the EXSLT - Dynamic module
+ */
+
+void
+exsltDynRegister (void) {
+ xsltRegisterExtModuleFunction ((const xmlChar *) "evaluate",
+ EXSLT_DYNAMIC_NAMESPACE,
+ exsltDynEvaluateFunction);
+}