/* Wrapper for xsltApplyStylesheet */ xmlDocPtr mxslt_doc_xml_apply_stylesheet(mxslt_doc_t * mxslt_doc, xsltStylesheetPtr style, xmlDocPtr doc, const char ** params) { xmlDocPtr retval; xsltTransformContextPtr userCtxt; userCtxt=xsltNewTransformContext(style, doc); if(userCtxt == NULL) return NULL; xsltSetCtxtParseOptions(userCtxt, MXSLT_XSLT_OPTIONS); /* XXX I don't like this much :| ... I consider this an hack */ /* userCtxt->_private=(void *)mxslt_doc; */ userCtxt->outputFile=mxslt_doc->localfile; #ifndef MXSLT_DISABLE_EXTENSIONS xsltRegisterExtElement(userCtxt, (xmlChar *)"header-set", (xmlChar *)MXSLT_NS_URI, mxslt_transform_header); xsltRegisterExtElement(userCtxt, (xmlChar *)"value-of", (xmlChar *)MXSLT_NS_URI, mxslt_transform_value_of); xsltRegisterExtElement(userCtxt, (xmlChar *)"header-set", (xmlChar *)MXSLT_OBSOLETE_NS_URI, mxslt_transform_header); xsltRegisterExtElement(userCtxt, (xmlChar *)"value-of", (xmlChar *)MXSLT_OBSOLETE_NS_URI, mxslt_transform_value_of); #endif retval=xsltApplyStylesheetUser(style, doc, params, NULL, NULL, userCtxt); xsltFreeTransformContext(userCtxt); return retval; }
void * _gda_xslt_extension_init (xsltTransformContextPtr ctxt, const xmlChar * URI) { int res; GdaXsltIntCont *data; #ifdef GDA_DEBUG_NO g_print ("_gda_xslt_extension_init"); #endif if (!URI || strcmp ((gchar*) URI, GDA_XSLT_EXTENSION_URI)) { #ifdef GDA_DEBUG_NO g_print ("called for another URI, exit"); #endif return NULL; } data = calloc (1, sizeof (GdaXsltIntCont)); if (data == NULL) { #ifdef GDA_DEBUG_NO g_print ("no memory"); #endif return NULL; } #ifdef GDA_DEBUG_NO g_print ("initialize result_sets hash"); #endif data->result_sets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); res = xsltRegisterExtFunction (ctxt, (const xmlChar *) GDA_XSLT_FUNC_GETVALUE, URI, gda_xslt_getvalue_function); res = xsltRegisterExtFunction (ctxt, (const xmlChar *) GDA_XSLT_FUNC_GETXMLVALUE, URI, gda_xslt_getxmlvalue_function); res |= xsltRegisterExtFunction (ctxt, (const xmlChar *) GDA_XSLT_FUNC_CHECKIF, URI, gda_xslt_checkif_function); res |= xsltRegisterExtFunction (ctxt, (const xmlChar *) GDA_XSLT_FUNC_GETNODESET, URI, gda_xslt_getnodeset_function); if (res != 0) { g_error ("failed to xsltRegisterExtFunction = [%d]", res); } res = xsltRegisterExtElement (ctxt, (const xmlChar *) GDA_XSLT_ELEM_SECTION, URI, (xsltTransformFunction) gda_xslt_section_element); if (res != 0) { g_error ("failed to xsltRegisterExtElement = [%d]", res); } return data; }
void yelp_transform_start (YelpTransform *transform, xmlDocPtr document, gchar **params) { transform->inputDoc = document; transform->context = xsltNewTransformContext (transform->stylesheet, transform->inputDoc); if (!transform->context) { YelpError *error = yelp_error_new (_("Broken Transformation"), _("An unknown error occurred while attempting to " "transform the document.")); transform_set_error (transform, error); return; } transform->params = g_strdupv (params); transform->context->_private = transform; if (!exslt_registered) { exsltRegisterAll (); exslt_registered = TRUE; } xsltRegisterExtElement (transform->context, BAD_CAST "document", BAD_CAST YELP_NAMESPACE, (xsltTransformFunction) xslt_yelp_document); xsltRegisterExtElement (transform->context, BAD_CAST "cache", BAD_CAST YELP_NAMESPACE, (xsltTransformFunction) xslt_yelp_cache); xsltRegisterExtFunction (transform->context, BAD_CAST "input", BAD_CAST YELP_NAMESPACE, (xmlXPathFunction) xslt_yelp_input); transform->mutex = g_mutex_new (); g_mutex_lock (transform->mutex); transform->running = TRUE; transform->thread = g_thread_create ((GThreadFunc) transform_run, transform, FALSE, NULL); g_mutex_unlock (transform->mutex); }
int registerBasicFunctions(xsltTransformContextPtr ctxt, const xmlChar *URI, int fromR) { struct Entries { const char *name; xmlXPathEvalFunc fun; }; struct Entries entries[] = { {"init", RXSLT_init}, {"call", RXSLT_call}, {"callI", RXSLT_callI}, {"eval", RXSLT_eval}, {"source", RXSLT_source}, {"register", RXSLT_register}, {"exists", RXSLT_exists}, {"library", RXSLT_library}, {"nullEval", RXSLT_nullEval}, {"evalWithOutput", RXSLT_evalWithOutput}, {"length", RXSLT_length}, {"as", RXSLT_as}, {"class", RXSLT_class} }; int n = sizeof(entries)/sizeof(entries[0]), i; if(fromR || R_alreadyInitialized) entries[0].fun = RXSLT_noop; #ifdef XSLT_DEBUG fprintf(stderr, "registering %d functions for %s\n", (fromR ? n-1 : n), R_URI);fflush(stderr); #endif for(i = 0 ; i < n; i++) { #ifdef XSLT_DEBUG fprintf(stderr, "registering %s\n", entries[i].name);fflush(stderr); #endif if(ctxt) xsltRegisterExtFunction(ctxt, entries[i].name, R_URI, entries[i].fun); else xsltRegisterExtModuleFunction((const xmlChar *) entries[i].name, (const xmlChar *) R_URI, entries[i].fun); } xsltRegisterExtElement(ctxt, "eval", R_URI, REvalFunctionDefn); return(n); }
static void transform_run (YelpTransform *transform) { YelpTransformPrivate *priv = GET_PRIV (transform); debug_print (DB_FUNCTION, "entering\n"); priv->stylesheet = xsltParseStylesheetFile (BAD_CAST (priv->stylesheet_file)); if (priv->stylesheet == NULL) { g_mutex_lock (&priv->mutex); if (priv->error) g_error_free (priv->error); priv->error = g_error_new (YELP_ERROR, YELP_ERROR_PROCESSING, _("The XSLT stylesheet ‘%s’ is either missing or not valid."), priv->stylesheet_file); g_object_ref (transform); g_idle_add ((GSourceFunc) transform_error, transform); g_mutex_unlock (&priv->mutex); return; } priv->context = xsltNewTransformContext (priv->stylesheet, priv->input); if (priv->context == NULL) { g_mutex_lock (&priv->mutex); if (priv->error) g_error_free (priv->error); priv->error = g_error_new (YELP_ERROR, YELP_ERROR_PROCESSING, _("The XSLT stylesheet ‘%s’ is either missing or not valid."), priv->stylesheet_file); g_object_ref (transform); g_idle_add ((GSourceFunc) transform_error, transform); g_mutex_unlock (&priv->mutex); return; } priv->context->_private = transform; xsltRegisterExtElement (priv->context, BAD_CAST "document", BAD_CAST YELP_NAMESPACE, (xsltTransformFunction) xslt_yelp_document); xsltRegisterExtElement (priv->context, BAD_CAST "cache", BAD_CAST YELP_NAMESPACE, (xsltTransformFunction) xslt_yelp_cache); xsltRegisterExtFunction (priv->context, BAD_CAST "input", BAD_CAST YELP_NAMESPACE, (xmlXPathFunction) xslt_yelp_aux); priv->output = xsltApplyStylesheetUser (priv->stylesheet, priv->input, (const char **) priv->params, NULL, NULL, priv->context); g_mutex_lock (&priv->mutex); priv->running = FALSE; if (!priv->cancelled) { g_idle_add ((GSourceFunc) transform_final, transform); g_mutex_unlock (&priv->mutex); } else { g_mutex_unlock (&priv->mutex); g_object_unref (transform); } }