2001-01-07 14:01:28 +00:00
|
|
|
/*
|
|
|
|
* xsltproc.c: user program for the XSL Transformation 1.0 engine
|
|
|
|
*
|
|
|
|
* See Copyright for the status of this software.
|
|
|
|
*
|
|
|
|
* Daniel.Veillard@imag.fr
|
|
|
|
*/
|
|
|
|
|
2001-01-07 15:17:08 +00:00
|
|
|
#include <string.h>
|
2001-02-05 18:29:06 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
2001-01-11 20:13:26 +00:00
|
|
|
#include <libxml/xmlversion.h>
|
2001-01-07 15:17:08 +00:00
|
|
|
#include <libxml/xmlmemory.h>
|
2001-01-11 20:13:26 +00:00
|
|
|
#include <libxml/debugXML.h>
|
2001-01-18 15:13:25 +00:00
|
|
|
#include <libxml/HTMLtree.h>
|
2001-01-07 14:01:28 +00:00
|
|
|
#include <libxslt/xslt.h>
|
|
|
|
#include <libxslt/xsltInternals.h>
|
2001-01-11 20:13:26 +00:00
|
|
|
#include <libxslt/transform.h>
|
2001-01-17 13:29:19 +00:00
|
|
|
#include <libxslt/xsltutils.h>
|
2001-01-07 14:01:28 +00:00
|
|
|
|
2001-02-05 18:29:06 +00:00
|
|
|
extern int xmlLoadExtDtdDefaultValue;
|
|
|
|
|
2001-01-07 14:01:28 +00:00
|
|
|
static int debug = 0;
|
2001-01-18 15:13:25 +00:00
|
|
|
static int repeat = 0;
|
2001-02-05 18:29:06 +00:00
|
|
|
static int timing = 0;
|
2001-02-18 14:47:20 +00:00
|
|
|
static int novalid = 0;
|
|
|
|
static int noout = 0;
|
2001-01-07 14:01:28 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv) {
|
2001-01-07 15:17:08 +00:00
|
|
|
int i;
|
2001-01-22 10:52:35 +00:00
|
|
|
xsltStylesheetPtr cur = NULL;
|
2001-01-11 20:13:26 +00:00
|
|
|
xmlDocPtr doc, res;
|
2001-02-05 18:29:06 +00:00
|
|
|
struct timeval begin, end;
|
2001-01-07 14:01:28 +00:00
|
|
|
|
2001-02-18 14:47:20 +00:00
|
|
|
if (argc <= 1) {
|
|
|
|
printf("Usage: %s [options] stylesheet file [file ...]\n", argv[0]);
|
|
|
|
printf(" Options:\n");
|
|
|
|
printf(" --verbose or -v: show logs of what's happening\n");
|
|
|
|
printf(" --timing: display the time used\n");
|
|
|
|
printf(" --repeat: run the transformation 100 times\n");
|
|
|
|
printf(" --debug: dump the tree of the result instead\n");
|
|
|
|
printf(" --novalid: skip the Dtd loading phase\n");
|
|
|
|
printf(" --noout: do not dump the result\n");
|
2001-02-18 15:41:57 +00:00
|
|
|
printf(" --maxdepth val : increase the maximum depth\n");
|
2001-02-18 14:47:20 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2001-01-18 15:13:25 +00:00
|
|
|
/* --repeat : repeat 100 times, for timing or profiling */
|
2001-01-07 14:01:28 +00:00
|
|
|
LIBXML_TEST_VERSION
|
|
|
|
for (i = 1; i < argc ; i++) {
|
2001-02-18 14:47:20 +00:00
|
|
|
#ifdef LIBXML_DEBUG_ENABLED
|
2001-01-17 13:29:19 +00:00
|
|
|
if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) {
|
2001-01-07 14:01:28 +00:00
|
|
|
debug++;
|
2001-02-18 14:47:20 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if ((!strcmp(argv[i], "-v")) ||
|
2001-01-17 13:29:19 +00:00
|
|
|
(!strcmp(argv[i], "-verbose")) ||
|
|
|
|
(!strcmp(argv[i], "--verbose"))) {
|
|
|
|
xsltSetGenericDebugFunc(stderr, NULL);
|
2001-01-18 15:13:25 +00:00
|
|
|
} else if ((!strcmp(argv[i], "-repeat")) ||
|
|
|
|
(!strcmp(argv[i], "--repeat"))) {
|
|
|
|
repeat++;
|
2001-02-18 14:47:20 +00:00
|
|
|
} else if ((!strcmp(argv[i], "-novalid")) ||
|
|
|
|
(!strcmp(argv[i], "--novalid"))) {
|
|
|
|
novalid++;
|
|
|
|
} else if ((!strcmp(argv[i], "-noout")) ||
|
|
|
|
(!strcmp(argv[i], "--noout"))) {
|
|
|
|
noout++;
|
2001-02-05 18:29:06 +00:00
|
|
|
} else if ((!strcmp(argv[i], "-timing")) ||
|
|
|
|
(!strcmp(argv[i], "--timing"))) {
|
|
|
|
timing++;
|
2001-02-18 15:41:57 +00:00
|
|
|
} else if ((!strcmp(argv[i], "-maxdepth")) ||
|
|
|
|
(!strcmp(argv[i], "--maxdepth"))) {
|
|
|
|
int value;
|
|
|
|
i++;
|
|
|
|
if (sscanf(argv[i], "%d", &value) == 1) {
|
|
|
|
if (value > 0)
|
|
|
|
xsltMaxDepth = value;
|
|
|
|
}
|
2001-01-17 13:29:19 +00:00
|
|
|
}
|
2001-01-07 14:01:28 +00:00
|
|
|
}
|
|
|
|
xmlSubstituteEntitiesDefault(1);
|
2001-02-18 14:47:20 +00:00
|
|
|
if (novalid == 0)
|
|
|
|
xmlLoadExtDtdDefaultValue = 1;
|
|
|
|
else
|
|
|
|
xmlLoadExtDtdDefaultValue = 0;
|
2001-01-07 14:01:28 +00:00
|
|
|
for (i = 1; i < argc ; i++) {
|
2001-02-18 15:41:57 +00:00
|
|
|
if ((!strcmp(argv[i], "-maxdepth")) ||
|
|
|
|
(!strcmp(argv[i], "--maxdepth"))) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2001-01-07 14:01:28 +00:00
|
|
|
if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
|
2001-02-05 18:29:06 +00:00
|
|
|
if (timing)
|
|
|
|
gettimeofday(&begin, NULL);
|
2001-01-11 20:13:26 +00:00
|
|
|
cur = xsltParseStylesheetFile((const xmlChar *)argv[i]);
|
2001-02-05 18:29:06 +00:00
|
|
|
if (timing) {
|
|
|
|
long msec;
|
|
|
|
gettimeofday(&end, NULL);
|
|
|
|
msec = end.tv_sec - begin.tv_sec;
|
|
|
|
msec *= 1000;
|
|
|
|
msec += (end.tv_usec - begin.tv_usec) / 1000;
|
|
|
|
fprintf(stderr, "Parsing stylesheet %s took %ld ms\n",
|
|
|
|
argv[i], msec);
|
|
|
|
}
|
2001-01-12 17:36:18 +00:00
|
|
|
if (cur != NULL) {
|
2001-01-15 14:34:02 +00:00
|
|
|
if (cur->indent == 1)
|
2001-01-12 17:36:18 +00:00
|
|
|
xmlIndentTreeOutput = 1;
|
|
|
|
else
|
|
|
|
xmlIndentTreeOutput = 0;
|
|
|
|
i++;
|
|
|
|
}
|
2001-01-22 18:39:41 +00:00
|
|
|
break;
|
|
|
|
|
2001-01-07 14:01:28 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-22 18:39:41 +00:00
|
|
|
if (cur != NULL) {
|
|
|
|
for (;i < argc ; i++) {
|
2001-02-05 18:29:06 +00:00
|
|
|
if (timing)
|
|
|
|
gettimeofday(&begin, NULL);
|
2001-01-22 18:39:41 +00:00
|
|
|
doc = xmlParseFile(argv[i]);
|
|
|
|
if (doc == NULL) {
|
|
|
|
fprintf(stderr, "unable to parse %s\n", argv[i]);
|
|
|
|
continue;
|
2001-01-18 15:13:25 +00:00
|
|
|
}
|
2001-02-05 18:29:06 +00:00
|
|
|
if (timing) {
|
|
|
|
long msec;
|
|
|
|
gettimeofday(&end, NULL);
|
|
|
|
msec = end.tv_sec - begin.tv_sec;
|
|
|
|
msec *= 1000;
|
|
|
|
msec += (end.tv_usec - begin.tv_usec) / 1000;
|
|
|
|
fprintf(stderr, "Parsing document %s took %ld ms\n",
|
|
|
|
argv[i], msec);
|
|
|
|
}
|
2001-01-22 18:39:41 +00:00
|
|
|
if (repeat) {
|
|
|
|
int j;
|
|
|
|
for (j = 0;j < 99; j++) {
|
|
|
|
res = xsltApplyStylesheet(cur, doc);
|
|
|
|
xmlFreeDoc(res);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
doc = xmlParseFile(argv[i]);
|
|
|
|
}
|
|
|
|
}
|
2001-02-05 18:29:06 +00:00
|
|
|
if (timing)
|
|
|
|
gettimeofday(&begin, NULL);
|
2001-01-22 18:39:41 +00:00
|
|
|
res = xsltApplyStylesheet(cur, doc);
|
2001-02-05 18:29:06 +00:00
|
|
|
if (timing) {
|
|
|
|
long msec;
|
|
|
|
gettimeofday(&end, NULL);
|
|
|
|
msec = end.tv_sec - begin.tv_sec;
|
|
|
|
msec *= 1000;
|
|
|
|
msec += (end.tv_usec - begin.tv_usec) / 1000;
|
|
|
|
fprintf(stderr, "Applying stylesheet took %ld ms\n",
|
|
|
|
msec);
|
|
|
|
}
|
2001-01-22 18:39:41 +00:00
|
|
|
xmlFreeDoc(doc);
|
|
|
|
if (res == NULL) {
|
|
|
|
fprintf(stderr, "no result for %s\n", argv[i]);
|
|
|
|
continue;
|
|
|
|
}
|
2001-02-18 14:47:20 +00:00
|
|
|
if (noout)
|
|
|
|
continue;
|
|
|
|
|
2001-01-11 20:13:26 +00:00
|
|
|
#ifdef LIBXML_DEBUG_ENABLED
|
2001-02-13 17:09:27 +00:00
|
|
|
if (debug)
|
|
|
|
xmlDebugDumpDocument(stdout, res);
|
|
|
|
else {
|
2001-01-11 20:13:26 +00:00
|
|
|
#endif
|
2001-02-13 17:09:27 +00:00
|
|
|
if (cur->methodURI == NULL) {
|
|
|
|
if (timing)
|
|
|
|
gettimeofday(&begin, NULL);
|
|
|
|
xsltSaveResultToFile(stdout, res, cur);
|
|
|
|
if (timing) {
|
|
|
|
long msec;
|
|
|
|
gettimeofday(&end, NULL);
|
|
|
|
msec = end.tv_sec - begin.tv_sec;
|
|
|
|
msec *= 1000;
|
|
|
|
msec += (end.tv_usec - begin.tv_usec) / 1000;
|
|
|
|
fprintf(stderr, "Saving result took %ld ms\n",
|
|
|
|
msec);
|
|
|
|
}
|
|
|
|
} else {
|
2001-02-17 00:58:09 +00:00
|
|
|
if (xmlStrEqual(cur->method, (const xmlChar *)"xhtml")) {
|
2001-02-13 17:09:27 +00:00
|
|
|
fprintf(stderr, "non standard output xhtml\n");
|
|
|
|
if (timing)
|
|
|
|
gettimeofday(&begin, NULL);
|
|
|
|
xsltSaveResultToFile(stdout, res, cur);
|
|
|
|
if (timing) {
|
|
|
|
long msec;
|
|
|
|
gettimeofday(&end, NULL);
|
|
|
|
msec = end.tv_sec - begin.tv_sec;
|
|
|
|
msec *= 1000;
|
|
|
|
msec += (end.tv_usec - begin.tv_usec) / 1000;
|
|
|
|
fprintf(stderr, "Saving result took %ld ms\n",
|
|
|
|
msec);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unsupported non standard output %s\n",
|
|
|
|
cur->method);
|
|
|
|
}
|
2001-02-05 18:29:06 +00:00
|
|
|
}
|
2001-02-13 17:09:27 +00:00
|
|
|
#ifdef LIBXML_DEBUG_ENABLED
|
2001-01-22 18:39:41 +00:00
|
|
|
}
|
2001-02-13 17:09:27 +00:00
|
|
|
#endif
|
2001-01-11 20:13:26 +00:00
|
|
|
|
2001-01-22 18:39:41 +00:00
|
|
|
xmlFreeDoc(res);
|
|
|
|
}
|
2001-01-11 20:13:26 +00:00
|
|
|
xsltFreeStylesheet(cur);
|
2001-01-22 18:39:41 +00:00
|
|
|
}
|
2001-01-07 14:01:28 +00:00
|
|
|
xmlCleanupParser();
|
|
|
|
xmlMemoryDump();
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|