1 | <![CDATA[
|
---|
2 | /*
|
---|
3 | * libxslt_tutorial.c: demo program for the XSL Transformation 1.0 engine
|
---|
4 | *
|
---|
5 | * based on xsltproc.c, by [email protected]
|
---|
6 | * by John Fleck
|
---|
7 | *
|
---|
8 | * This program is free software; you can redistribute it and/or modify
|
---|
9 | * it under the terms of the GNU General Public License as published by
|
---|
10 | * the Free Software Foundation; either version 2 of the License, or
|
---|
11 | * (at your option) any later version.
|
---|
12 | *
|
---|
13 | * This program is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | * GNU General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU General Public License
|
---|
19 | * along with this program; if not, write to the Free Software
|
---|
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA.
|
---|
21 | *
|
---|
22 | */
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * Sun GPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
26 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
27 | * the General Public License version 2 (GPLv2) at this time for any software where
|
---|
28 | * a choice of GPL license versions is made available with the language indicating
|
---|
29 | * that GPLv2 or any later version may be used, or where a choice of which version
|
---|
30 | * of the GPL is applied is otherwise unspecified.
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include <string.h>
|
---|
34 | #include <libxml/xmlmemory.h>
|
---|
35 | #include <libxml/debugXML.h>
|
---|
36 | #include <libxml/HTMLtree.h>
|
---|
37 | #include <libxml/xmlIO.h>
|
---|
38 | #include <libxml/DOCBparser.h>
|
---|
39 | #include <libxml/xinclude.h>
|
---|
40 | #include <libxml/catalog.h>
|
---|
41 | #include <libxslt/xslt.h>
|
---|
42 | #include <libxslt/xsltInternals.h>
|
---|
43 | #include <libxslt/transform.h>
|
---|
44 | #include <libxslt/xsltutils.h>
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 | extern int xmlLoadExtDtdDefaultValue;
|
---|
49 |
|
---|
50 | static void usage(const char *name) {
|
---|
51 | printf("Usage: %s [options] stylesheet file [file ...]\n", name);
|
---|
52 | printf(" --param name value : pass a (parameter,value) pair\n");
|
---|
53 |
|
---|
54 | }
|
---|
55 |
|
---|
56 | int
|
---|
57 | main(int argc, char **argv) {
|
---|
58 | int i;
|
---|
59 | const char *params[16 + 1];
|
---|
60 | int nbparams = 0;
|
---|
61 | xsltStylesheetPtr cur = NULL;
|
---|
62 | xmlDocPtr doc, res;
|
---|
63 |
|
---|
64 | if (argc <= 1) {
|
---|
65 | usage(argv[0]);
|
---|
66 | return(1);
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | for (i = 1; i < argc; i++) {
|
---|
71 | if (argv[i][0] != '-')
|
---|
72 | break;
|
---|
73 | if ((!strcmp(argv[i], "-param")) ||
|
---|
74 | (!strcmp(argv[i], "--param"))) {
|
---|
75 | i++;
|
---|
76 | params[nbparams++] = argv[i++];
|
---|
77 | params[nbparams++] = argv[i];
|
---|
78 | if (nbparams >= 16) {
|
---|
79 | fprintf(stderr, "too many params\n");
|
---|
80 | return (1);
|
---|
81 | }
|
---|
82 | } else {
|
---|
83 | fprintf(stderr, "Unknown option %s\n", argv[i]);
|
---|
84 | usage(argv[0]);
|
---|
85 | return (1);
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | params[nbparams] = NULL;
|
---|
90 | xmlSubstituteEntitiesDefault(1);
|
---|
91 | xmlLoadExtDtdDefaultValue = 1;
|
---|
92 | cur = xsltParseStylesheetFile((const xmlChar *)argv[i]);
|
---|
93 | i++;
|
---|
94 | doc = xmlParseFile(argv[i]);
|
---|
95 | res = xsltApplyStylesheet(cur, doc, params);
|
---|
96 | xsltSaveResultToFile(stdout, res, cur);
|
---|
97 |
|
---|
98 | xsltFreeStylesheet(cur);
|
---|
99 | xmlFreeDoc(res);
|
---|
100 | xmlFreeDoc(doc);
|
---|
101 |
|
---|
102 | xsltCleanupGlobals();
|
---|
103 | xmlCleanupParser();
|
---|
104 | return(0);
|
---|
105 |
|
---|
106 | }
|
---|
107 | ]]>
|
---|