1 /******************************************************************************
2 * $id: mapfile.c 7854 2008-08-14 19:22:48Z dmorissette $
3 *
4 * Project: MapServer
5 * Purpose: High level Map file parsing code.
6 * Author: Steve Lime and the MapServer team.
7 *
8 ******************************************************************************
9 * Copyright (c) 1996-2005 Regents of the University of Minnesota.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies of this Software or works derived from this Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
28 ****************************************************************************/
29 #include "mapserver.h"
30
31 #ifdef USE_XMLMAPFILE
32
33 #include <libxslt/xslt.h>
34 #include "libexslt/exslt.h"
35 #include <libxslt/transform.h>
36 #include <libxslt/xsltInternals.h>
37 #include <libxslt/extensions.h>
38 #include <libxslt/xsltutils.h>
39
40 extern int xmlLoadExtDtdDefaultValue;
41
msTransformXmlMapfile(const char * stylesheet,const char * xmlMapfile,FILE * tmpfile)42 int msTransformXmlMapfile(const char *stylesheet, const char *xmlMapfile, FILE *tmpfile)
43 {
44 xsltStylesheetPtr cur = NULL;
45 int status = MS_FAILURE;
46 xmlDocPtr doc, res;
47
48 exsltRegisterAll();
49 xsltRegisterTestModule();
50
51 xmlSubstituteEntitiesDefault(1);
52 xmlLoadExtDtdDefaultValue = 1;
53
54 cur = xsltParseStylesheetFile((const xmlChar *)stylesheet);
55 if (cur == NULL) {
56 msSetError(MS_MISCERR, "Failed to load xslt stylesheet", "msTransformXmlMapfile()");
57 goto done;
58 }
59
60 doc = xmlParseFile(xmlMapfile);
61 if (doc == NULL) {
62 msSetError(MS_MISCERR, "Failed to load xml mapfile", "msTransformXmlMapfile()");
63 goto done;
64 }
65
66 res = xsltApplyStylesheet(cur, doc, NULL);
67 if (res == NULL) {
68 msSetError(MS_MISCERR, "Failed to apply style sheet to %s", "msTransformXmlMapfile()", xmlMapfile);
69 goto done;
70 }
71
72 if ( xsltSaveResultToFile(tmpfile, res, cur) != -1 )
73 status = MS_SUCCESS;
74
75 done:
76 if (cur)
77 xsltFreeStylesheet(cur);
78 if (res)
79 xmlFreeDoc(res);
80 if (doc)
81 xmlFreeDoc(doc);
82
83 xsltCleanupGlobals();
84 xmlCleanupParser();
85
86 return status;
87 }
88
89 #endif
90