[xslt] [PATCH] xsltproc stringparam
- From: Alexander Shigin <shigin rambler-co ru>
- To: xslt gnome org
- Subject: [xslt] [PATCH] xsltproc stringparam
- Date: Wed, 02 Dec 2009 19:11:41 +0300
The current documentation refers string parameter can't contain both
quote and double-quotes. It confuses me a while ago because it makes me
think I can't use parameters with both quotes with XSLT at all.
The attached patch allows to use both quotes and changes man page.
I can't find any test for xsltproc, if one exist I would be pleased to
add test for the case.
P. S. I think it would be pretty nice for download page
(http://xmlsoft.org/XSLT/downloads.html) to points to current git
repository instead of outdated svn one.
diff --git a/doc/xsltproc.1 b/doc/xsltproc.1
index d94e7a2..5755640 100644
--- a/doc/xsltproc.1
+++ b/doc/xsltproc.1
@@ -310,11 +310,6 @@ Error in one of the documents
Unsupported xsl:output method
.RE
.PP
-\fB8\fR
-.RS 4
-String parameter contains both quote and double\-quotes
-.RE
-.PP
\fB9\fR
.RS 4
Internal processing error
diff --git a/doc/xsltproc.xml b/doc/xsltproc.xml
index d3849e2..0742b02 100644
--- a/doc/xsltproc.xml
+++ b/doc/xsltproc.xml
@@ -512,13 +512,6 @@ the XPath expression must be UTF-8 encoded.
</varlistentry>
<varlistentry>
- <term><errorcode>8</errorcode></term>
- <listitem>
- <para>String parameter contains both quote and double-quotes</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
<term><errorcode>9</errorcode></term>
<listitem>
<para>Internal processing error</para>
diff --git a/xsltproc/xsltproc.c b/xsltproc/xsltproc.c
index e978a63..63a48e4 100644
--- a/xsltproc/xsltproc.c
+++ b/xsltproc/xsltproc.c
@@ -8,6 +8,7 @@
#include "libxslt/libxslt.h"
#include "libexslt/exslt.h"
+#include "libxslt/variables.h"
#include <stdio.h>
#ifdef HAVE_STRING_H
#include <string.h>
@@ -96,7 +97,7 @@ static int profile = 0;
static int options = XSLT_PARSE_OPTIONS;
static const char *params[MAX_PARAMETERS + 1];
static int nbparams = 0;
-static xmlChar *strparams[MAX_PARAMETERS + 1];
+static const char *strparams[MAX_PARAMETERS + 1];
static int nbstrparams = 0;
static xmlChar *paths[MAX_PATHS + 1];
static int nbpaths = 0;
@@ -104,6 +105,13 @@ static char *output = NULL;
static int errorno = 0;
static const char *writesubtree = NULL;
+static void updateContext(xsltTransformContextPtr ctxt) {
+ xsltSetCtxtParseOptions(ctxt, options);
+ if (-1 == xsltQuoteUserParams(ctxt, strparams)) {
+ fputs("can't set stringparams\n", stderr);
+ }
+}
+
/*
* Entity loading control and customization.
*/
@@ -378,9 +386,15 @@ xsltProcess(xmlDocPtr doc, xsltStylesheetPtr cur, const char *filename) {
int j;
for (j = 1; j < repeat; j++) {
- res = xsltApplyStylesheet(cur, doc, params);
+ ctxt = xsltNewTransformContext(cur, doc);
+ if (ctxt == NULL)
+ return;
+ updateContext(ctxt);
+ res = xsltApplyStylesheetUser(cur, doc, params, NULL,
+ NULL, ctxt);
xmlFreeDoc(res);
xmlFreeDoc(doc);
+ xsltFreeTransformContext(ctxt);
#ifdef LIBXML_HTML_ENABLED
if (html)
doc = htmlReadFile(filename, encoding, options);
@@ -392,7 +406,7 @@ xsltProcess(xmlDocPtr doc, xsltStylesheetPtr cur, const char *filename) {
ctxt = xsltNewTransformContext(cur, doc);
if (ctxt == NULL)
return;
- xsltSetCtxtParseOptions(ctxt, options);
+ updateContext(ctxt);
#ifdef LIBXML_XINCLUDE_ENABLED
if (xinclude)
ctxt->xinclude = 1;
@@ -461,7 +475,7 @@ xsltProcess(xmlDocPtr doc, xsltStylesheetPtr cur, const char *filename) {
ctxt = xsltNewTransformContext(cur, doc);
if (ctxt == NULL)
return;
- xsltSetCtxtParseOptions(ctxt, options);
+ updateContext(ctxt);
#ifdef LIBXML_XINCLUDE_ENABLED
if (xinclude)
ctxt->xinclude = 1;
@@ -685,30 +699,11 @@ main(int argc, char **argv)
}
} else if ((!strcmp(argv[i], "-stringparam")) ||
(!strcmp(argv[i], "--stringparam"))) {
- const xmlChar *string;
- xmlChar *value;
-
i++;
- params[nbparams++] = argv[i++];
- string = (const xmlChar *) argv[i];
- if (xmlStrchr(string, '"')) {
- if (xmlStrchr(string, '\'')) {
- fprintf(stderr,
- "stringparam contains both quote and double-quotes !\n");
- return(8);
- }
- value = xmlStrdup((const xmlChar *)"'");
- value = xmlStrcat(value, string);
- value = xmlStrcat(value, (const xmlChar *)"'");
- } else {
- value = xmlStrdup((const xmlChar *)"\"");
- value = xmlStrcat(value, string);
- value = xmlStrcat(value, (const xmlChar *)"\"");
- }
+ strparams[nbstrparams++] = argv[i++];
+ strparams[nbstrparams++] = argv[i];
- params[nbparams++] = (const char *) value;
- strparams[nbstrparams++] = value;
- if (nbparams >= MAX_PARAMETERS) {
+ if (nbstrparams >= MAX_PARAMETERS) {
fprintf(stderr, "too many params increase MAX_PARAMETERS \n");
return (2);
}
@@ -870,8 +865,6 @@ main(int argc, char **argv)
done:
if (cur != NULL)
xsltFreeStylesheet(cur);
- for (i = 0;i < nbstrparams;i++)
- xmlFree(strparams[i]);
if (output != NULL)
xmlFree(output);
xsltFreeSecurityPrefs(sec);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]