[LIBXSLT] Update to version 1.1.32. CORE-14291
[reactos.git] / dll / 3rdparty / libxslt / keys.c
index d28aea6..9170538 100644 (file)
@@ -9,24 +9,7 @@
  * daniel@veillard.com
  */
 
-#define IN_LIBXSLT
-#include "libxslt.h"
-
-#include <string.h>
-
-#include <libxml/xmlmemory.h>
-#include <libxml/tree.h>
-#include <libxml/valid.h>
-#include <libxml/hash.h>
-#include <libxml/xmlerror.h>
-#include <libxml/parserInternals.h>
-#include <libxml/xpathInternals.h>
-#include "xslt.h"
-#include "xsltInternals.h"
-#include "xsltutils.h"
-#include "imports.h"
-#include "templates.h"
-#include "keys.h"
+#include "precomp.h"
 
 #ifdef WITH_XSLT_DEBUG
 #define WITH_XSLT_DEBUG_KEYS
@@ -37,9 +20,9 @@ xsltInitDocKeyTable(xsltTransformContextPtr ctxt, const xmlChar *name,
                     const xmlChar *nameURI);
 
 /************************************************************************
- *                                                                     *
- *                     Type functions                                  *
- *                                                                     *
+ *                                                                     *
+ *                     Type functions                                  *
+ *                                                                     *
  ************************************************************************/
 
 /**
@@ -158,7 +141,7 @@ xsltFreeKeyTable(xsltKeyTablePtr keyt) {
     if (keyt->nameURI != NULL)
        xmlFree(keyt->nameURI);
     if (keyt->keys != NULL)
-       xmlHashFree(keyt->keys, 
+       xmlHashFree(keyt->keys,
                    (xmlHashDeallocator) xmlXPathFreeNodeSet);
     memset(keyt, -1, sizeof(xsltKeyTable));
     xmlFree(keyt);
@@ -182,9 +165,9 @@ xsltFreeKeyTableList(xsltKeyTablePtr keyt) {
 }
 
 /************************************************************************
- *                                                                     *
- *             The interpreter for the precompiled patterns            *
- *                                                                     *
+ *                                                                     *
+ *             The interpreter for the precompiled patterns            *
+ *                                                                     *
  ************************************************************************/
 
 
@@ -311,8 +294,8 @@ xsltAddKey(xsltStylesheetPtr style, const xmlChar *name,
                end = skipPredicate(match, end);
                if (end <= 0) {
                    xsltTransformError(NULL, style, inst,
-                                      "key pattern is malformed: %s",
-                                      key->match);
+                       "xsl:key : 'match' pattern is malformed: %s",
+                       key->match);
                    if (style != NULL) style->errors++;
                    goto error;
                }
@@ -321,7 +304,7 @@ xsltAddKey(xsltStylesheetPtr style, const xmlChar *name,
        }
        if (current == end) {
            xsltTransformError(NULL, style, inst,
-                              "key pattern is empty\n");
+                              "xsl:key : 'match' pattern is empty\n");
            if (style != NULL) style->errors++;
            goto error;
        }
@@ -344,6 +327,12 @@ xsltAddKey(xsltStylesheetPtr style, const xmlChar *name,
        }
        current = end;
     }
+    if (pattern == NULL) {
+        xsltTransformError(NULL, style, inst,
+                           "xsl:key : 'match' pattern is empty\n");
+        if (style != NULL) style->errors++;
+        goto error;
+    }
 #ifdef WITH_XSLT_DEBUG_KEYS
     xsltGenericDebug(xsltGenericDebugContext,
        "   resulting pattern %s\n", pattern);
@@ -356,17 +345,25 @@ xsltAddKey(xsltStylesheetPtr style, const xmlChar *name,
     *   Maybe a search for "$", if it occurs outside of quotation
     *   marks, could be sufficient.
     */
+#ifdef XML_XPATH_NOVAR
+    key->comp = xsltXPathCompileFlags(style, pattern, XML_XPATH_NOVAR);
+#else
     key->comp = xsltXPathCompile(style, pattern);
+#endif
     if (key->comp == NULL) {
        xsltTransformError(NULL, style, inst,
-               "xsl:key : XPath pattern compilation failed '%s'\n",
+               "xsl:key : 'match' pattern compilation failed '%s'\n",
                         pattern);
        if (style != NULL) style->errors++;
     }
+#ifdef XML_XPATH_NOVAR
+    key->usecomp = xsltXPathCompileFlags(style, use, XML_XPATH_NOVAR);
+#else
     key->usecomp = xsltXPathCompile(style, use);
+#endif
     if (key->usecomp == NULL) {
        xsltTransformError(NULL, style, inst,
-               "xsl:key : XPath pattern compilation failed '%s'\n",
+               "xsl:key : 'use' expression compilation failed '%s'\n",
                         use);
        if (style != NULL) style->errors++;
     }
@@ -387,10 +384,13 @@ xsltAddKey(xsltStylesheetPtr style, const xmlChar *name,
        prev->next = key;
     }
     key->next = NULL;
+    key = NULL;
 
 error:
     if (pattern != NULL)
        xmlFree(pattern);
+    if (key != NULL)
+        xsltFreeKeyDef(key);
     return(0);
 }
 
@@ -744,6 +744,7 @@ fprintf(stderr, "xsltInitCtxtKey %s : %d\n", keyDef->name, ctxt->keyInitLevel);
        cur = matchList->nodeTab[i];
        if (! IS_XSLT_REAL_NODE(cur))
            continue;
+        ctxt->node = cur;
        xpctxt->node = cur;
        /*
        * Process the 'use' of the xsl:key.