[xslt] [PATCH] 0.11.0 to do params by callback function
- From: Luke Kenneth Casson Leighton <lkcl samba-tng org>
- To: XSLT Mailing List <xslt gnome org>
- Subject: [xslt] [PATCH] 0.11.0 to do params by callback function
- Date: Fri, 15 Jun 2001 11:23:59 +0200
hiya,
well... i have params already stored in apr_tables.
having already created the tables from xml nodes / props,
i _really_ didn't fancy turning those back into a char **!
so, a la "pull" methodology that dv writes, here's a patch
that allows a fn+state to be passed in to obtain params
for xsltApplyStylesheet.
luke
diff -r -u libxslt-0.11.0/libxslt/transform.c libxslt-0.11.0-mod/libxslt/transform.c
--- libxslt-0.11.0/libxslt/transform.c Tue May 29 02:55:06 2001
+++ libxslt-0.11.0-mod/libxslt/transform.c Thu Jun 14 20:31:49 2001
@@ -2572,6 +2572,33 @@
xmlDocPtr
xsltApplyStylesheet(xsltStylesheetPtr style, xmlDocPtr doc,
const char **params) {
+ struct xsltEvalParamState param_state;
+
+ param_state.params = params;
+ param_state.indx = 0;
+
+ return xsltApplyStylesheetParamFn(style,doc,
+ xsltEvalNextParam, ¶m_state);
+}
+
+/**
+ * xsltApplyStylesheetParamFn:
+ * @style: a parsed XSLT stylesheet
+ * @doc: a parsed XML document
+ * @get_param_fn: a function that takes state, param name and value
+ * that returns 0 to indicate no more parameters.
+ * @get_param_state: state info to be passed to get_param_fn, should
+ * it need it.
+ *
+ * Apply the stylesheet to the document
+ * NOTE: This may lead to a non-wellformed output XML wise !
+ *
+ * Returns the result document or NULL in case of error
+ */
+xmlDocPtr
+xsltApplyStylesheetParamFn(xsltStylesheetPtr style, xmlDocPtr doc,
+ int (*get_param_fn)(void *, const xmlChar **, const xmlChar **),
+ void *get_param_state) {
xmlDocPtr res = NULL;
xsltTransformContextPtr ctxt = NULL;
xmlNodePtr root;
@@ -2648,8 +2675,8 @@
ctxt->output = res;
ctxt->insert = (xmlNodePtr) res;
ctxt->globalVars = xmlHashCreate(20);
- if (params != NULL)
- xsltEvalUserParams(ctxt, params);
+ if (get_param_fn != NULL)
+ xsltEvalUserParamsFromFn(ctxt, get_param_fn, get_param_state);
xsltEvalGlobalVariables(ctxt);
ctxt->node = (xmlNodePtr) doc;
varsPush(ctxt, NULL);
diff -r -u libxslt-0.11.0/libxslt/transform.h libxslt-0.11.0-mod/libxslt/transform.h
--- libxslt-0.11.0/libxslt/transform.h Mon Mar 26 02:55:06 2001
+++ libxslt-0.11.0-mod/libxslt/transform.h Thu Jun 14 20:30:23 2001
@@ -19,6 +19,12 @@
/*
* Interfaces
*/
+xmlDocPtr xsltApplyStylesheetParamFn(xsltStylesheetPtr style,
+ xmlDocPtr doc,
+ int (*)(void *,
+ const xmlChar **,
+ const xmlChar **),
+ void *get_param_state);
xmlDocPtr xsltApplyStylesheet (xsltStylesheetPtr style,
xmlDocPtr doc,
const char **params);
diff -r -u libxslt-0.11.0/libxslt/variables.c libxslt-0.11.0-mod/libxslt/variables.c
--- libxslt-0.11.0/libxslt/variables.c Wed May 23 02:55:07 2001
+++ libxslt-0.11.0-mod/libxslt/variables.c Thu Jun 14 20:29:03 2001
@@ -614,6 +614,33 @@
}
/**
+ * next_txt_param:
+ * @_pstate: the state info with which we can get name/value tuples
+ * @name: the next name
+ * @value: the next value
+ *
+ * Obtain the current name/value tuple, if there is one,
+ * and prepare the 'state' info ready to get the next
+ * name/value tuple, on the next call to next_txt_param
+ * with the same 'state' info.
+ *
+ * Returns 0 in case of success, -1 in case of error
+ */
+int
+xsltEvalNextParam(void *_pstate, const xmlChar **name, const xmlChar **value)
+{
+ struct xsltEvalParamState *p = _pstate;
+
+ if (p->params[p->indx] == NULL)
+ return -1;
+
+ (*name) = (const xmlChar *)p->params[p->indx++];
+ (*value) = (const xmlChar *)p->params[p->indx++];
+
+ return 0;
+}
+
+/**
* xsltEvalUserParams:
* @ctxt: the XSLT transformation context
* @params: a NULL terminated arry of parameters names/values tuples
@@ -624,7 +651,34 @@
* Returns 0 in case of success, -1 in case of error
*/
int
-xsltEvalUserParams(xsltTransformContextPtr ctxt, const char **params) {
+xsltEvalUserParams(xsltTransformContextPtr ctxt, const char **params)
+{
+ struct xsltEvalParamState param_state;
+
+ param_state.params = params;
+ param_state.indx = 0;
+
+ return xsltEvalUserParamsFromFn(ctxt, xsltEvalNextParam, ¶m_state);
+}
+
+/**
+ * xsltEvalUserParamsFromFn:
+ * @ctxt: the XSLT transformation context
+ * @get_param_fn: a function that takes state, param name and value
+ * that returns 0 to indicate no more parameters.
+ * @get_param_state: state info to be passed to get_param_fn, should
+ * it need it.
+ *
+ * Evaluate the global variables of a stylesheet. This need to be
+ * done on parsed stylesheets before starting to apply transformations
+ *
+ * Returns 0 in case of success, -1 in case of error
+ */
+int
+xsltEvalUserParamsFromFn(xsltTransformContextPtr ctxt,
+ int (*get_param_fn)(void *, const xmlChar **, const xmlChar **),
+ void *get_param_state)
+{
xsltStylesheetPtr style;
int indx = 0;
const xmlChar *name;
@@ -637,13 +691,11 @@
if (ctxt == NULL)
return(-1);
- if (params == NULL)
+ if (get_param_fn == NULL)
return(0);
style = ctxt->style;
- while (params[indx] != NULL) {
- name = (const xmlChar *)params[indx++];
- value = (const xmlChar *)params[indx++];
+ while (get_param_fn(get_param_state, &name, &value) == 0) {
if ((name == NULL) || (value == NULL))
break;
diff -r -u libxslt-0.11.0/libxslt/variables.h libxslt-0.11.0-mod/libxslt/variables.h
--- libxslt-0.11.0/libxslt/variables.h Fri May 18 02:55:15 2001
+++ libxslt-0.11.0-mod/libxslt/variables.h Thu Jun 14 20:18:55 2001
@@ -38,6 +38,12 @@
int xsltEvalGlobalVariables (xsltTransformContextPtr ctxt);
int xsltEvalUserParams (xsltTransformContextPtr ctxt,
const char **params);
+
+int xsltEvalUserParamsFromFn (xsltTransformContextPtr ctxt,
+ int (*)(void *,
+ const xmlChar **,
+ const xmlChar **),
+ void *get_param_state);
void xsltParseGlobalVariable (xsltStylesheetPtr style,
xmlNodePtr cur);
void xsltParseGlobalParam (xsltStylesheetPtr style,
@@ -57,6 +63,20 @@
xmlXPathObjectPtr xsltXPathVariableLookup (void *ctxt,
const xmlChar *name,
const xmlChar *ns_uri);
+/*
+ * Help for xsltEvalUserParams
+ */
+
+struct xsltEvalParamState
+{
+ const char **params;
+ int indx;
+};
+
+int xsltEvalNextParam (void *_pstate,
+ const xmlChar **name,
+ const xmlChar **value);
+
#ifdef __cplusplus
}
#endif
Only in libxslt-0.11.0: libxslt.spec
Only in libxslt-0.11.0-mod/tests/REC: .memdump
Only in libxslt-0.11.0-mod/tests/REC1: .memdump
Only in libxslt-0.11.0-mod/tests/REC2: .memdump
Only in libxslt-0.11.0-mod/tests/XSLTMark: .memdump
Only in libxslt-0.11.0-mod/tests/XSLTMark: db100.xml
Only in libxslt-0.11.0-mod/tests/XSLTMark: db1000.xml
Only in libxslt-0.11.0-mod/tests/XSLTMark: db10000.xml
Only in libxslt-0.11.0-mod/tests/docbook: .memdump
Only in libxslt-0.11.0-mod/tests/documents: .memdump
Only in libxslt-0.11.0-mod/tests/general: .memdump
Only in libxslt-0.11.0-mod/tests/general: result.bug-25-
Only in libxslt-0.11.0-mod/tests/multiple: .memdump
Only in libxslt-0.11.0-mod/tests/namespaces: .memdump
Only in libxslt-0.11.0-mod/tests/numbers: .memdump
Only in libxslt-0.11.0-mod/tests/xmlspec: .memdump
Only in libxslt-0.11.0-mod/: xsltConf.sh
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]