| 39 | extern int xmlLoadExtDtdDefaultValue; |
| 40 | |
| 41 | int msTransformXmlMapfile(const char *stylesheet, const char *xmlMapfile, FILE *tmpfile) |
| 42 | { |
| 43 | xsltStylesheetPtr cur = NULL; |
| 44 | int status = MS_FAILURE; |
| 45 | xmlDocPtr doc, res; |
| 46 | |
| 47 | exsltRegisterAll(); |
| 48 | xsltRegisterTestModule(); |
| 49 | |
| 50 | xmlSubstituteEntitiesDefault(1); |
| 51 | xmlLoadExtDtdDefaultValue = 1; |
| 52 | |
| 53 | cur = xsltParseStylesheetFile((const xmlChar *)stylesheet); |
| 54 | if (cur == NULL) |
| 55 | { |
| 56 | msSetError(MS_MISCERR, "Failed to load xslt stylesheet", "msTransformXmlMapfile()"); |
| 57 | goto done; |
| 58 | } |
| 59 | |
| 60 | doc = xmlParseFile(xmlMapfile); |
| 61 | if (doc == NULL) |
| 62 | { |
| 63 | msSetError(MS_MISCERR, "Failed to load xml mapfile", "msTransformXmlMapfile()"); |
| 64 | goto done; |
| 65 | } |
| 66 | |
| 67 | res = xsltApplyStylesheet(cur, doc, NULL); |
| 68 | if (res == NULL) |
| 69 | { |
| 70 | msSetError(MS_MISCERR, "Failed to apply style sheet to %s", "msTransformXmlMapfile()", xmlMapfile); |
| 71 | goto done; |
| 72 | } |
| 73 | |
| 74 | if ( xsltSaveResultToFile(tmpfile, res, cur) != -1 ) |
| 75 | status = MS_SUCCESS; |
| 76 | |
| 77 | done: |
| 78 | if (cur) |
| 79 | xsltFreeStylesheet(cur); |
| 80 | if (res) |
| 81 | xmlFreeDoc(res); |
| 82 | if (doc) |
| 83 | xmlFreeDoc(doc); |
| 84 | |
| 85 | xsltCleanupGlobals(); |
| 86 | xmlCleanupParser(); |
| 87 | |
| 88 | return status; |
| 89 | } |
| 90 | |
| 91 | #endif |