closing bug #56517, fixed a number of problems in the patterns
authorDaniel Veillard <veillard@src.gnome.org>
Sat, 23 Jun 2001 12:24:49 +0000 (12:24 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Sat, 23 Jun 2001 12:24:49 +0000 (12:24 +0000)
* libxslt/pattern.c: closing bug #56517, fixed a number of
  problems in the patterns compilations, priorities and debug
* libxslt/transform.c: improved the template debug message
* tests/docs/Makefile.am tests/general/Makefile.am
  tests/general/bug-39-* tests/docs/bug-39-*: added a specific
  regression test for #56517
Daniel

ChangeLog
libxslt/pattern.c
libxslt/transform.c
tests/docs/Makefile.am
tests/docs/bug-39-.xml [new file with mode: 0644]
tests/general/Makefile.am
tests/general/bug-39-.out [new file with mode: 0644]
tests/general/bug-39-.xsl [new file with mode: 0644]

index 7ecd03f..64445e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Jun 23 14:20:01 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+       * libxslt/pattern.c: closing bug #56517, fixed a number of
+         problems in the patterns compilations, priorities and debug
+       * libxslt/transform.c: improved the template debug message
+       * tests/docs/Makefile.am tests/general/Makefile.am
+         tests/general/bug-39-* tests/docs/bug-39-*: added a specific
+         regression test for #56517
+
 Fri Jun 22 16:17:23 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
        * libxslt/xslt.c: avoid a stupid bug when compiling with
index 50ff468..bc2c214 100644 (file)
@@ -79,6 +79,7 @@ struct _xsltStepOp {
 struct _xsltCompMatch {
     struct _xsltCompMatch *next; /* siblings in the name hash */
     float priority;              /* the priority */
+    const xmlChar *pattern;       /* the pattern */
     const xmlChar *mode;         /* the mode */
     const xmlChar *modeURI;      /* the mode URI */
     xsltTemplatePtr template;    /* the associated template */
@@ -145,6 +146,8 @@ xsltFreeCompMatch(xsltCompMatchPtr comp) {
 
     if (comp == NULL)
        return;
+    if (comp->pattern != NULL)
+       xmlFree((xmlChar *)comp->pattern);
     if (comp->mode != NULL)
        xmlFree((xmlChar *)comp->mode);
     if (comp->modeURI != NULL)
@@ -1459,11 +1462,6 @@ xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) {
        return(NULL);
     }
 
-#ifdef WITH_XSLT_DEBUG_PATTERN
-    xsltGenericDebug(xsltGenericDebugContext,
-                    "xsltCompilePattern : parsing '%s'\n", pattern);
-#endif
-
     ctxt = xsltNewParserContext();
     if (ctxt == NULL)
        return(NULL);
@@ -1494,10 +1492,17 @@ xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) {
 
        ctxt->comp = element;
        ctxt->base = xmlStrndup(&pattern[start], end - start);
+       if (ctxt->base == NULL)
+           goto error;
        ctxt->cur = &(ctxt->base)[current - start];
+       element->pattern = ctxt->base;
+
+#ifdef WITH_XSLT_DEBUG_PATTERN
+       xsltGenericDebug(xsltGenericDebugContext,
+                        "xsltCompilePattern : parsing '%s'\n",
+                        element->pattern);
+#endif
        xsltCompileLocationPathPattern(ctxt);
-       if (ctxt->base)
-           xmlFree((xmlChar *)ctxt->base);
        if (ctxt->error)
            goto error;
 
@@ -1514,9 +1519,11 @@ xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) {
            (element->steps[0].value != NULL) &&
            (element->steps[1].op == XSLT_OP_END)) {
            element->priority = 0;
+#if 0
        } else if ((element->steps[0].op == XSLT_OP_ROOT) &&
                   (element->steps[1].op == XSLT_OP_END)) {
            element->priority = 0;
+#endif
        } else if ((element->steps[0].op == XSLT_OP_PI) &&
                   (element->steps[0].value != NULL) &&
                   (element->steps[1].op == XSLT_OP_END)) {
@@ -1544,6 +1551,11 @@ xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) {
        } else {
            element->priority = 0.5;
        }
+#ifdef WITH_XSLT_DEBUG_PATTERN
+       xsltGenericDebug(xsltGenericDebugContext,
+                    "xsltCompilePattern : parsed %s, default priority %f\n",
+                        element->pattern, element->priority);
+#endif
        if (pattern[end] == '|')
            end++;
        current = end;
@@ -1587,24 +1599,25 @@ xsltAddTemplate(xsltStylesheetPtr style, xsltTemplatePtr cur,
                const xmlChar *mode, const xmlChar *modeURI) {
     xsltCompMatchPtr pat, list, *top = NULL, next;
     const xmlChar *name = NULL;
+    float priority;              /* the priority */
 
     if ((style == NULL) || (cur == NULL) || (cur->match == NULL))
        return(-1);
 
+    priority = cur->priority;
     pat = xsltCompilePattern(cur->match, style->doc, cur->elem);
     while (pat) {
        next = pat->next;
        pat->next = NULL;
+       name = NULL;
        
        pat->template = cur;
        if (mode != NULL)
            pat->mode = xmlStrdup(mode);
        if (modeURI != NULL)
            pat->modeURI = xmlStrdup(modeURI);
-       if (cur->priority == XSLT_PAT_NO_PRIORITY)
-           cur->priority = pat->priority;
-       else
-           pat->priority = cur->priority;
+       if (priority != XSLT_PAT_NO_PRIORITY)
+           pat->priority = priority;
 
        /*
         * insert it in the hash table list corresponding to its lookup name
@@ -1726,11 +1739,11 @@ xsltAddTemplate(xsltStylesheetPtr style, xsltTemplatePtr cur,
        if (mode)
            xsltGenericDebug(xsltGenericDebugContext,
                         "added pattern : '%s' mode '%s' priority %f\n",
-                            pat->template->match, pat->mode, pat->priority);
+                            pat->pattern, pat->mode, pat->priority);
        else
            xsltGenericDebug(xsltGenericDebugContext,
                         "added pattern : '%s' priority %f\n",
-                            pat->template->match, pat->priority);
+                            pat->pattern, pat->priority);
 #endif
 
        pat = next;
@@ -1756,6 +1769,7 @@ xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
     xsltTemplatePtr ret = NULL;
     const xmlChar *name = NULL;
     xsltCompMatchPtr list = NULL;
+    float priority;
 
     if ((ctxt == NULL) || (node == NULL))
        return(NULL);
@@ -1767,6 +1781,7 @@ xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
     }
 
     while ((curstyle != NULL) && (curstyle != style)) {
+       priority = XSLT_PAT_NO_PRIORITY;
        /* TODO : handle IDs/keys here ! */
        if (curstyle->templatesHash != NULL) {
            /*
@@ -1813,6 +1828,7 @@ xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
            if (xsltTestCompMatch(ctxt, list, node,
                                  ctxt->mode, ctxt->modeURI)) {
                ret = list->template;
+               priority = list->priority;
                break;
            }
            list = list->next;
@@ -1861,7 +1877,7 @@ xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
 
        }
        while ((list != NULL) &&
-              ((ret == NULL)  || (list->priority > ret->priority))) {
+              ((ret == NULL)  || (list->priority > priority))) {
            if (xsltTestCompMatch(ctxt, list, node,
                                  ctxt->mode, ctxt->modeURI)) {
                ret = list->template;
@@ -1872,7 +1888,7 @@ xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
        if (node->_private != NULL) {
            list = curstyle->keyMatch;
            while ((list != NULL) &&
-                  ((ret == NULL)  || (list->priority > ret->priority))) {
+                  ((ret == NULL)  || (list->priority > priority))) {
                if (xsltTestCompMatch(ctxt, list, node,
                                      ctxt->mode, ctxt->modeURI)) {
                    ret = list->template;
index 8b24e99..b41ea59 100644 (file)
@@ -890,8 +890,8 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
     if (node->type == XML_ATTRIBUTE_NODE) {
 #ifdef WITH_XSLT_DEBUG_PROCESS
        xsltGenericDebug(xsltGenericDebugContext,
-            "xsltProcessOneNode: applying template for attribute %s\n",
-                        node->name);
+            "xsltProcessOneNode: applying template '%s' for attribute %s\n",
+                        template->match, node->name);
 #endif
        templPush(ctxt, template);
        xsltApplyOneTemplate(ctxt, node, template->content, 1);
@@ -900,10 +900,12 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
 #ifdef WITH_XSLT_DEBUG_PROCESS
        if (node->type == XML_DOCUMENT_NODE)
            xsltGenericDebug(xsltGenericDebugContext,
-            "xsltProcessOneNode: applying template for /\n");
+            "xsltProcessOneNode: applying template '%s' for /\n",
+                            template->match);
        else 
            xsltGenericDebug(xsltGenericDebugContext,
-            "xsltProcessOneNode: applying template for %s\n", node->name);
+            "xsltProcessOneNode: applying template '%s' for %s\n",
+                            template->match, node->name);
 #endif
        oldNode = ctxt->node;
        ctxt->node = node;
index a834bde..867c61c 100644 (file)
@@ -42,6 +42,7 @@ EXTRA_DIST =  \
        bug-36-.xml \
        bug-37-.xml \
        bug-38-.xml \
+       bug-39-.xml \
        character.xml \
        array.xml \
        items.xml
diff --git a/tests/docs/bug-39-.xml b/tests/docs/bug-39-.xml
new file mode 100644 (file)
index 0000000..ae743eb
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version='1.0'?>
+<x>
+</x>
index 3ab5c7c..c2da73d 100644 (file)
@@ -44,6 +44,7 @@ EXTRA_DIST = \
     bug-37-inc.out bug-37-inc.xsl \
     array.out array.xsl \
     bug-38-.out bug-38-.xsl \
+    bug-39-.out bug-39-.xsl \
     character.out character.xsl \
     character2.out character2.xsl \
     itemschoose.out itemschoose.xsl \
diff --git a/tests/general/bug-39-.out b/tests/general/bug-39-.out
new file mode 100644 (file)
index 0000000..ba9b93e
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<root>Matched /* or y template
+</root>
diff --git a/tests/general/bug-39-.xsl b/tests/general/bug-39-.xsl
new file mode 100644 (file)
index 0000000..96b8d3a
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version='1.0'?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'>
+
+<xsl:template match="/">
+  <root>
+    <xsl:apply-templates />
+  </root>
+</xsl:template>
+
+<xsl:template match="x">
+  <xsl:text>Matched x template</xsl:text>
+  <xsl:apply-templates />
+</xsl:template>
+
+<!-- Case 1: y=0.0 /*=0.0, even though /* should be 0.5 -->
+<!-- works if split up to: 
+<xsl:template match="/*"> or of course you reverse the order
+so the y pattern is screwed instead
+-->
+<xsl:template match="y|/*">
+  <xsl:text>Matched /* or y template</xsl:text>
+  <xsl:apply-templates />
+</xsl:template>
+
+<!--
+Case 2: Here, both should have 5.0 priority but /* seems to have 0.0!
+<xsl:template match="y|/*" priority="5.0">
+  <xsl:text>Matched /* or y template</xsl:text>
+  <xsl:apply-templates />
+</xsl:template>
+-->
+
+</xsl:stylesheet>