--- libxslt-1.1.30/libexslt/crypto.c.orig	2016-05-01 07:14:50.000000000 -0400
+++ libxslt-1.1.30/libexslt/crypto.c	2017-09-27 19:15:49.446077200 -0400
@@ -121,7 +121,9 @@ exsltCryptoHex2Bin (const unsigned char
 
 #include <windows.h>
 #include <wincrypt.h>
+#if defined(_MSC_VER)
 #pragma comment(lib, "advapi32.lib")
+#endif
 
 static void
 exsltCryptoCryptoApiReportError (xmlXPathParserContextPtr ctxt,
@@ -136,7 +138,11 @@ exsltCryptoCryptoApiReportError (xmlXPat
 
     xsltTransformError (xsltXPathGetTransformContext (ctxt), NULL, NULL,
 			"exslt:crypto error (line %d). %s", line,
+#ifdef __MINGW32__
+			(LPTSTR) lpMsgBuf);
+#else
 			lpMsgBuf);
+#endif
     LocalFree (lpMsgBuf);
 }
 
@@ -159,7 +165,11 @@ exsltCryptoCryptoApiCreateHash (xmlXPath
 	goto fail;
     }
 
+#ifdef __MINGW32__
+    if (!CryptGetHashParam (hHash, HP_HASHVAL, (BYTE *) dest, &dwHashLen, 0)) {
+#else
     if (!CryptGetHashParam (hHash, HP_HASHVAL, dest, &dwHashLen, 0)) {
+#endif
 	exsltCryptoCryptoApiReportError (ctxt, __LINE__);
 	goto fail;
     }
@@ -228,8 +238,13 @@ exsltCryptoCryptoApiRc4Encrypt (xmlXPath
     }
 
     hHash = exsltCryptoCryptoApiCreateHash (ctxt, hCryptProv,
+#ifdef __MINGW32__
+					    CALG_SHA1, (LPVOID) key,
+					    RC4_KEY_LENGTH, (LPVOID) hash,
+#else
 					    CALG_SHA1, key,
 					    RC4_KEY_LENGTH, hash,
+#endif
 					    HASH_DIGEST_LENGTH);
 
     if (!CryptDeriveKey
@@ -279,8 +294,13 @@ exsltCryptoCryptoApiRc4Decrypt (xmlXPath
     }
 
     hHash = exsltCryptoCryptoApiCreateHash (ctxt, hCryptProv,
+#ifdef __MINGW32__
+					    CALG_SHA1, (LPVOID) key,
+					    RC4_KEY_LENGTH, (LPVOID) hash,
+#else
 					    CALG_SHA1, key,
 					    RC4_KEY_LENGTH, hash,
+#endif
 					    HASH_DIGEST_LENGTH);
 
     if (!CryptDeriveKey
--- libxslt-1.1.30/libexslt/date.c.orig	2017-09-28 00:05:02.427619100 -0400
+++ libxslt-1.1.30/libexslt/date.c	2017-09-28 00:23:05.676653200 -0400
@@ -748,6 +748,14 @@ exsltDateCurrent (void)
     time_t secs;
     int local_s, gm_s;
     exsltDateValPtr ret;
+#ifdef __MINGW32__
+    gmTm.tm_year = 0;
+    gmTm.tm_mon = 0;
+    gmTm.tm_mday = 0;
+    gmTm.tm_hour = 0;
+    gmTm.tm_min = 0;
+    gmTm.tm_sec = 0;
+#endif
 #ifdef HAVE_ERRNO_H
     char *source_date_epoch;
 #endif /* HAVE_ERRNO_H */
--- libxslt-1.1.30/libxslt/security.c.orig	2017-09-27 23:09:28.157210800 -0400
+++ libxslt-1.1.30/libxslt/security.c	2017-09-27 23:09:55.855876300 -0400
@@ -391,18 +391,19 @@ xsltCheckWrite(xsltSecurityPrefsPtr sec,
     }
     if ((uri->scheme == NULL) ||
 	(xmlStrEqual(BAD_CAST uri->scheme, BAD_CAST "file"))) {
-
 #if defined(WIN32) && !defined(__CYGWIN__)
-    if ((uri->path)&&(uri->path[0]=='/')&&
+	if ((uri->path)&&(uri->path[0]=='/')&&
         (uri->path[1]!='\0')&&(uri->path[2]==':'))
-    ret = xsltCheckWritePath(sec, ctxt, uri->path+1);
-    else
-#endif
+           ret = xsltCheckWritePath(sec, ctxt, uri->path+1);
+	else
+	     ret = xsltCheckWritePath(sec, ctxt, uri->path);
+#else
 
 	/*
 	 * Check if we are allowed to write this file
 	 */
 	ret = xsltCheckWritePath(sec, ctxt, uri->path);
+#endif
 	if (ret <= 0) {
 	    xmlFreeURI(uri);
 	    return(ret);
--- libxslt-1.1.30/libxslt/transform.c.orig	2017-09-26 01:32:59.668742300 -0400
+++ libxslt-1.1.30/libxslt/transform.c	2017-09-26 01:34:48.806947100 -0400
@@ -5872,7 +5872,7 @@ xsltApplyStylesheetInternal(xsltStyleshe
      */
     root = xmlDocGetRootElement(doc);
     if (root != NULL) {
-	if (((long) root->content) >= 0 && (xslDebugStatus == XSLT_DEBUG_NONE))
+	if (((intptr_t) root->content) >= 0 && (xslDebugStatus == XSLT_DEBUG_NONE))
 	    xmlXPathOrderDocElems(doc);
     }
 
--- libxslt-1.1.30/libxslt/xsltlocale.c.orig	2015-05-10 10:11:30.000000000 -0400
+++ libxslt-1.1.30/libxslt/xsltlocale.c	2017-09-27 16:49:14.619164600 -0400
@@ -194,7 +194,11 @@ xsltNewLocale(const xmlChar *languageTag
     region = xsltDefaultRegion(localeName);
     if (region == NULL) goto end;
 
+#ifdef __MINGW32__
+    strcpy((LPSTR) localeName + llen + 1, (LPSTR) region);
+#else
     strcpy(localeName + llen + 1, region);
+#endif
     locale = xslt_locale_WINAPI(localeName);
 end:
     return(locale);
@@ -389,7 +393,11 @@ xsltStrxfrm(xsltLocale locale, const xml
 #endif
 
 #ifdef XSLT_LOCALE_WINAPI
+#ifdef __MINGW32__
+    xstrlen = MultiByteToWideChar(CP_UTF8, 0, (LPSTR) string, -1, NULL, 0);
+#else
     xstrlen = MultiByteToWideChar(CP_UTF8, 0, string, -1, NULL, 0);
+#endif
     if (xstrlen == 0) {
         xsltTransformError(NULL, NULL, NULL, "xsltStrxfrm : MultiByteToWideChar check failed\n");
         return(NULL);
@@ -399,7 +407,11 @@ xsltStrxfrm(xsltLocale locale, const xml
         xsltTransformError(NULL, NULL, NULL, "xsltStrxfrm : out of memory\n");
         return(NULL);
     }
+#ifdef __MINGW32__
+    r = MultiByteToWideChar(CP_UTF8, 0, (LPSTR) string, -1, xstr, xstrlen);
+#else
     r = MultiByteToWideChar(CP_UTF8, 0, string, -1, xstr, xstrlen);
+#endif
     if (r == 0) {
         xsltTransformError(NULL, NULL, NULL, "xsltStrxfrm : MultiByteToWideChar failed\n");
         xmlFree(xstr);
@@ -486,9 +498,15 @@ xsltIterateSupportedLocales(LPSTR lcid)
     k = sscanf(lcid, "%lx", (long*)&p->lcid);
     if (k < 1) goto end;
     /*don't count terminating null character*/
+#ifdef __MINGW32__
+    k = GetLocaleInfoA(p->lcid, LOCALE_SISO639LANGNAME , (LPSTR) iso639lang , sizeof(iso639lang ));
+    if (--k < 1) goto end;
+    l = GetLocaleInfoA(p->lcid, LOCALE_SISO3166CTRYNAME, (LPSTR) iso3136ctry, sizeof(iso3136ctry));
+#else
     k = GetLocaleInfoA(p->lcid, LOCALE_SISO639LANGNAME , iso639lang , sizeof(iso639lang ));
     if (--k < 1) goto end;
     l = GetLocaleInfoA(p->lcid, LOCALE_SISO3166CTRYNAME, iso3136ctry, sizeof(iso3136ctry));
+#endif
     if (--l < 1) goto end;
 
     {  /*fill results*/
--- libxslt-1.1.30/python/libxslt.c.orig	2017-09-28 07:32:21.445272400 -0400
+++ libxslt-1.1.30/python/libxslt.c	2017-09-28 08:07:44.824318100 -0400
@@ -103,7 +103,7 @@ libxslt_xsltGetTransformContextHashCode(
         return NULL;
 
     tctxt =  (xsltTransformContextPtr) PytransformCtxt_Get(py_tctxt);
-    hash_code = (long) tctxt;
+    hash_code = (intptr_t) tctxt;
 
     ret = PyInt_FromLong(hash_code);
     return ret;
@@ -140,7 +140,7 @@ libxslt_xsltGetStylesheetHashCode(PyObje
         return NULL;
 
     style =  (xsltStylesheetPtr) Pystylesheet_Get(py_style);
-    hash_code = (long) style;
+    hash_code = (intptr_t) style;
 
     ret = PyInt_FromLong(hash_code);
     return ret;
@@ -1180,6 +1180,10 @@ void initlibxsltmod(void) {
     static int initialized = 0;
     PyObject *m;
 
+#if defined(__MINGW32__)
+    m = NULL;
+#endif
+
 #ifdef MERGED_MODULES
     initlibxml2mod();
 #endif
--- libxslt-1.1.30/xsltproc/testThreads.c.orig	2017-09-28 00:37:52.803133800 -0400
+++ libxslt-1.1.30/xsltproc/testThreads.c	2017-09-28 00:39:00.872153200 -0400
@@ -16,7 +16,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+#if !defined(_REENTRANT)
 #define _REENTRANT
+#endif
 #include <libxml/xmlversion.h>
 
 #if defined(LIBXML_THREAD_ENABLED) && defined(HAVE_PTHREAD_H)
--- libxslt-1.1.30/xsltproc/xsltproc.c.orig	2016-04-10 08:01:03.000000000 -0400
+++ libxslt-1.1.30/xsltproc/xsltproc.c	2017-09-27 23:40:16.488292500 -0400
@@ -6,6 +6,14 @@
  * daniel@veillard.com
  */
 
+/* winsock2.h must ALWAYS come before windows.h or it
+will reference the original winsock.h headers */
+#if defined(WIN32) && !defined (__CYGWIN__)
+  #if defined(_MSC_VER) || defined(__MINGW32__)
+#include <winsock2.h>
+  #endif /* _MS_VER */
+#endif
+
 #include "libxslt/libxslt.h"
 #include "libxslt/xsltconfig.h"
 #include "libexslt/exslt.h"
@@ -55,10 +63,7 @@
 #include <libexslt/exsltconfig.h>
 
 #if defined(WIN32) && !defined (__CYGWIN__)
-#if defined(_MSC_VER) || defined(__MINGW32__)
-#include <winsock2.h>
 #define gettimeofday(p1,p2)
-#endif /* _MS_VER */
 #else /* WIN32 */
 #if defined(HAVE_SYS_TIME_H)
 #include <sys/time.h>
@@ -595,7 +600,7 @@ main(int argc, char **argv)
                    (!strcmp(argv[i], "--output"))) {
             i++;
 #if defined(WIN32) || defined (__CYGWIN__)
-	    output = xmlCanonicPath(argv[i]);
+	    output = (char *) xmlCanonicPath((xmlChar *) argv[i]);
             if (output == NULL)
 #endif
 		output = (char *) xmlStrdup((xmlChar *) argv[i]);

