From 6ca5fcf67bafcee7191d074b5449fa0a88514608 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 15 Apr 2002 15:30:21 +0000 Subject: [PATCH] removed a warning added xsltRunStylesheetUser() API needed to fix #78546 * libxslt/attributes.c: removed a warning * libxslt/transform.c libxslt/transform.h win32/libxslt.def.src: added xsltRunStylesheetUser() API needed to fix #78546 * xsltproc/xsltproc.c: second part of the fix #78546 Daniel --- ChangeLog | 7 ++++ libxslt/attributes.c | 2 +- libxslt/transform.c | 95 ++++++++++++++++++++++++++++++------------- libxslt/transform.h | 8 ++++ win32/libxslt.def.src | 1 + xsltproc/xsltproc.c | 16 +++++++- 6 files changed, 98 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8204772a..70738e20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Apr 15 17:27:51 CEST 2002 Daniel Veillard + + * libxslt/attributes.c: removed a warning + * libxslt/transform.c libxslt/transform.h win32/libxslt.def.src: + added xsltRunStylesheetUser() API needed to fix #78546 + * xsltproc/xsltproc.c: second part of the fix #78546 + Mon Apr 15 15:57:28 CEST 2002 Daniel Veillard * python/Makefile.am: fixing the equivalent of #75779 diff --git a/libxslt/attributes.c b/libxslt/attributes.c index ce295d57..b1c6b751 100644 --- a/libxslt/attributes.c +++ b/libxslt/attributes.c @@ -439,7 +439,7 @@ xsltGetSAS(xsltStylesheetPtr style, const xmlChar *name, const xmlChar *ns) { static void xsltResolveSASCallback(xsltAttrElemPtr values, xsltStylesheetPtr style, const xmlChar *name, const xmlChar *ns, - const xmlChar *ignored) { + ATTRIBUTE_UNUSED const xmlChar *ignored) { xsltAttrElemPtr tmp; xsltAttrElemPtr refs; diff --git a/libxslt/transform.c b/libxslt/transform.c index 85210c75..38c5e401 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -3699,6 +3699,70 @@ xsltApplyStylesheetUser(xsltStylesheetPtr style, xmlDocPtr doc, return (res); } +/** + * xsltRunStylesheetUser: + * @style: a parsed XSLT stylesheet + * @doc: a parsed XML document + * @params: a NULL terminated arry of parameters names/values tuples + * @output: the URL/filename ot the generated resource if available + * @SAX: a SAX handler for progressive callback output (not implemented yet) + * @IObuf: an output buffer for progressive output (not implemented yet) + * @profile: profile FILE * output or NULL + * @userCtxt: user provided transform context + * + * Apply the stylesheet to the document and generate the output according + * to @output @SAX and @IObuf. It's an error to specify both @SAX and @IObuf. + * + * NOTE: This may lead to a non-wellformed output XML wise ! + * NOTE: This may also result in multiple files being generated + * NOTE: using IObuf, the result encoding used will be the one used for + * creating the output buffer, use the following macro to read it + * from the stylesheet + * XSLT_GET_IMPORT_PTR(encoding, style, encoding) + * NOTE: using SAX, any encoding specified in the stylesheet will be lost + * since the interface uses only UTF8 + * + * Returns the number of by written to the main resource or -1 in case of + * error. + */ +int +xsltRunStylesheetUser(xsltStylesheetPtr style, xmlDocPtr doc, + const char **params, const char *output, + xmlSAXHandlerPtr SAX, xmlOutputBufferPtr IObuf, + FILE * profile, xsltTransformContextPtr userCtxt) +{ + xmlDocPtr tmp; + int ret; + + if ((output == NULL) && (SAX == NULL) && (IObuf == NULL)) + return (-1); + if ((SAX != NULL) && (IObuf != NULL)) + return (-1); + + /* unsupported yet */ + if (SAX != NULL) { + XSLT_TODO /* xsltRunStylesheet xmlSAXHandlerPtr SAX */ + return (-1); + } + + tmp = xsltApplyStylesheetInternal(style, doc, params, output, profile, + userCtxt); + if (tmp == NULL) { + xsltPrintErrorContext(NULL, NULL, (xmlNodePtr) doc); + xsltGenericError(xsltGenericErrorContext, + "xsltRunStylesheet : run failed\n"); + return (-1); + } + if (IObuf != NULL) { + /* TODO: incomplete, IObuf output not progressive */ + ret = xsltSaveResultTo(IObuf, tmp, style); + } else { + ret = xsltSaveResultToFilename(output, tmp, style, 0); + } + xmlFreeDoc(tmp); + return (ret); +} + /** * xsltRunStylesheet: * @style: a parsed XSLT stylesheet @@ -3728,35 +3792,8 @@ xsltRunStylesheet(xsltStylesheetPtr style, xmlDocPtr doc, const char **params, const char *output, xmlSAXHandlerPtr SAX, xmlOutputBufferPtr IObuf) { - xmlDocPtr tmp; - int ret; - - if ((output == NULL) && (SAX == NULL) && (IObuf == NULL)) - return (-1); - if ((SAX != NULL) && (IObuf != NULL)) - return (-1); - - /* unsupported yet */ - if (SAX != NULL) { - XSLT_TODO /* xsltRunStylesheet xmlSAXHandlerPtr SAX */ - return (-1); - } - - tmp = xsltApplyStylesheetInternal(style, doc, params, output, NULL, NULL); - if (tmp == NULL) { - xsltPrintErrorContext(NULL, NULL, (xmlNodePtr) doc); - xsltGenericError(xsltGenericErrorContext, - "xsltRunStylesheet : run failed\n"); - return (-1); - } - if (IObuf != NULL) { - /* TODO: incomplete, IObuf output not progressive */ - ret = xsltSaveResultTo(IObuf, tmp, style); - } else { - ret = xsltSaveResultToFilename(output, tmp, style, 0); - } - xmlFreeDoc(tmp); - return (ret); + return(xsltRunStylesheetUser(style, doc, params, output, SAX, IObuf, + NULL, NULL)); } /** diff --git a/libxslt/transform.h b/libxslt/transform.h index 7223bd6d..c94eda66 100644 --- a/libxslt/transform.h +++ b/libxslt/transform.h @@ -60,6 +60,14 @@ int xsltRunStylesheet (xsltStylesheetPtr style, const char *output, xmlSAXHandlerPtr SAX, xmlOutputBufferPtr IObuf); +int xsltRunStylesheetUser (xsltStylesheetPtr style, + xmlDocPtr doc, + const char **params, + const char *output, + xmlSAXHandlerPtr SAX, + xmlOutputBufferPtr IObuf, + FILE * profile, + xsltTransformContextPtr userCtxt); void xsltApplyOneTemplate (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr list, diff --git a/win32/libxslt.def.src b/win32/libxslt.def.src index a7acba2a..5687cc53 100644 --- a/win32/libxslt.def.src +++ b/win32/libxslt.def.src @@ -200,6 +200,7 @@ EXPORTS xsltApplyStylesheet xsltProfileStylesheet xsltRunStylesheet + xsltRunStylesheetUser xsltApplyOneTemplate xsltDocumentElem xsltSort diff --git a/xsltproc/xsltproc.c b/xsltproc/xsltproc.c index 23660b1f..af65d486 100644 --- a/xsltproc/xsltproc.c +++ b/xsltproc/xsltproc.c @@ -331,7 +331,21 @@ xsltProcess(xmlDocPtr doc, xsltStylesheetPtr cur, const char *filename) { xmlFreeDoc(res); } else { - xsltRunStylesheet(cur, doc, params, output, NULL, NULL); + int ret; + + ctxt = xsltNewTransformContext(cur, doc); + if (ctxt == NULL) + return; + if (profile) { + ret = xsltRunStylesheetUser(cur, doc, params, output, + NULL, NULL, stderr, ctxt); + } else { + ret = xsltRunStylesheetUser(cur, doc, params, output, + NULL, NULL, NULL, ctxt); + } + if (ctxt->state == XSLT_STATE_ERROR) + errorno = 9; + xsltFreeTransformContext(ctxt); if (timing) endTimer("Running stylesheet and saving result"); xmlFreeDoc(doc);