Fixes the problems exposed by #73880 those ought to be computed at
authorDaniel Veillard <veillard@src.gnome.org>
Fri, 8 Mar 2002 13:55:08 +0000 (13:55 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Fri, 8 Mar 2002 13:55:08 +0000 (13:55 +0000)
* libxslt/pattern.c: Fixes the problems exposed by #73880
  those ought to be computed at stylesheet compile time, not
  at run-time, and the computation was wrong.
* libxslt/transform.c: get rid of fake nodes coming from node-set
  transformations. At least if they are still produced they will
  become easy to spot as resulting document won't be well-formed.
Daniel

ChangeLog
libxslt/pattern.c
libxslt/transform.c
libxslt/variables.c
python/Makefile.am

index 4cd83e9..47b4d5a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Fri Mar  8 14:51:59 CET 2002 Daniel Veillard <daniel@veillard.com>
+
+       * libxslt/pattern.c: Fixes the problems exposed by #73880
+         those ought to be computed at stylesheet compile time, not
+         at run-time, and the computation was wrong.
+       * libxslt/transform.c: get rid of fake nodes coming from node-set
+          transformations. At least if they are still produced they will
+         become easy to spot as resulting document won't be well-formed.
+
 Thu Mar  7 17:01:21 CET 2002 Daniel Veillard <daniel@veillard.com>
 
        * libxslt/extensions.c: fixed bug #73791 related to extension
index 86551cf..61c9b49 100644 (file)
@@ -268,6 +268,9 @@ xsltCompMatchAdd(xsltParserContextPtr ctxt, xsltCompMatchPtr comp,
        comp->steps[comp->nbStep].lenExtra =
            xsltAllocateExtra(ctxt->style);
     }
+    if (op == XSLT_OP_PREDICATE) {
+       comp->steps[comp->nbStep].comp = xmlXPathCompile(value);
+    }
     comp->nbStep++;
     return (0);
 }
@@ -286,6 +289,7 @@ xsltSwapTopCompMatch(xsltCompMatchPtr comp) {
     if (j > 0) {
        register xmlChar *tmp;
        register xsltOp op;
+       register xmlXPathCompExprPtr expr; 
        i = j - 1;
        tmp = comp->steps[i].value;
        comp->steps[i].value = comp->steps[j].value;
@@ -296,6 +300,9 @@ xsltSwapTopCompMatch(xsltCompMatchPtr comp) {
        op = comp->steps[i].op;
        comp->steps[i].op = comp->steps[j].op;
        comp->steps[j].op = op;
+       expr = comp->steps[i].comp;
+       comp->steps[i].comp = comp->steps[j].comp;
+       comp->steps[j].comp = expr;
     }
 }
 
@@ -313,6 +320,7 @@ xsltReverseCompMatch(xsltCompMatchPtr comp) {
     while (j > i) {
        register xmlChar *tmp;
        register xsltOp op;
+       register xmlXPathCompExprPtr expr; 
        tmp = comp->steps[i].value;
        comp->steps[i].value = comp->steps[j].value;
        comp->steps[j].value = tmp;
@@ -322,6 +330,9 @@ xsltReverseCompMatch(xsltCompMatchPtr comp) {
        op = comp->steps[i].op;
        comp->steps[i].op = comp->steps[j].op;
        comp->steps[j].op = op;
+       expr = comp->steps[i].comp;
+       comp->steps[i].comp = comp->steps[j].comp;
+       comp->steps[j].comp = expr;
        j--;
        i++;
     }
@@ -800,22 +811,9 @@ xsltTestCompMatch(xsltTransformContextPtr ctxt, xsltCompMatchPtr comp,
 
                if (step->value == NULL)
                    goto wrong_index;
+               if (step->comp == NULL)
+                   goto wrong_index;
 
-               if (step->comp == NULL) {
-                   step->comp = xmlXPathCompile(step->value);
-                   if (step->comp == NULL)
-                       goto wrong_index;
-               }
-               if (comp->nsList == NULL) {
-                   int j = 0;
-
-                   comp->nsList = xmlGetNsList(node->doc, node);
-                   if (comp->nsList != NULL) {
-                       while (comp->nsList[j] != NULL)
-                           j++;
-                   }
-                   comp->nsNr = j;
-               }
                if (!xsltEvalXPathPredicate(ctxt, step->comp, comp->nsList,
                                            comp->nsNr))
                    goto wrong_index;
@@ -1618,7 +1616,7 @@ xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc,
                   xsltTransformContextPtr runtime) {
     xsltParserContextPtr ctxt = NULL;
     xsltCompMatchPtr element, first = NULL, previous = NULL;
-    int current, start, end, level;
+    int current, start, end, level, j;
 
     if (pattern == NULL) {
        xsltPrintErrorContext(NULL, NULL, node); /* TODO */
@@ -1677,6 +1675,14 @@ xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc,
            goto error;
        ctxt->cur = &(ctxt->base)[current - start];
        element->pattern = ctxt->base;
+       element->nsList = xmlGetNsList(doc, node);
+       j = 0;
+       if (element->nsList != NULL) {
+           while (element->nsList[j] != NULL)
+               j++;
+       }
+       element->nsNr = j;
+
 
 #ifdef WITH_XSLT_DEBUG_PATTERN
        xsltGenericDebug(xsltGenericDebugContext,
index f8945cb..99f26f3 100644 (file)
@@ -654,6 +654,13 @@ xsltCopyTree(xsltTransformContextPtr ctxt, xmlNodePtr node,
         case XML_XINCLUDE_END:
             return(NULL);
     }
+    if (xmlStrEqual(node->name, (const xmlChar *) "fake node libxslt")) {
+       if (node->children != NULL)
+           copy = xsltCopyTreeList(ctxt, node->children, insert);
+       else
+           copy = NULL;
+       return(copy);
+    }
     copy = xmlCopyNode(node, 0);
     copy->doc = ctxt->output;
     if (copy != NULL) {
@@ -1009,6 +1016,16 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node,
     xsltTemplatePtr template;
     xmlNodePtr oldNode;
 
+    if (xmlStrEqual(node->name, BAD_CAST "fake node libxslt")) {
+       xmlNodePtr children;
+
+       children = node->children;
+       while (children != NULL) {
+           xsltProcessOneNode(ctxt, children, params);
+           children = children->next;
+       }
+       return;
+    }
     template = xsltGetTemplate(ctxt, node, NULL);
     /*
      * If no template is found, apply the default rule.
@@ -1951,6 +1968,9 @@ xsltCopy(xsltTransformContextPtr ctxt, xmlNodePtr node,
            case XML_HTML_DOCUMENT_NODE:
                break;
            case XML_ELEMENT_NODE:
+               if (xmlStrEqual(node->name, BAD_CAST "fake node libxslt"))
+                   return;
+
 #ifdef WITH_XSLT_DEBUG_PROCESS
                xsltGenericDebug(xsltGenericDebugContext,
                                 "xsltCopy: node %s\n", node->name);
@@ -2717,9 +2737,9 @@ xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node,
                        }
                    }
                    /* no break on purpose */
+               case XML_ELEMENT_NODE:
                case XML_DOCUMENT_NODE:
                case XML_HTML_DOCUMENT_NODE:
-               case XML_ELEMENT_NODE:
                case XML_CDATA_SECTION_NODE:
                case XML_PI_NODE:
                case XML_COMMENT_NODE:
index 81918bd..386af10 100644 (file)
@@ -359,7 +359,7 @@ xsltEvalVariable(xsltTransformContextPtr ctxt, xsltStackElemPtr elem,
            xmlNodePtr oldInsert;
 
            container = xmlNewDocNode(ctxt->document->doc, NULL,
-                                     (const xmlChar *) "fake", NULL);
+                             (const xmlChar *) "fake node libxslt", NULL);
            if (container == NULL)
                return(NULL);
 
@@ -485,7 +485,7 @@ xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt) {
            xmlNodePtr oldInsert;
 
            container = xmlNewDocNode(ctxt->document->doc, NULL,
-                                     (const xmlChar *) "fake", NULL);
+                             (const xmlChar *) "fake node libxslt", NULL);
            if (container == NULL)
                return(NULL);
 
index b034da6..83ea450 100644 (file)
@@ -27,8 +27,6 @@ mylibs = \
        $(top_builddir)/libxslt/libxslt.la \
        $(top_builddir)/libexslt/libexslt.la
 
-all: libxsltmod.so libxslt.py $(PYTHONSODV)
-
 LDADD = -lxslt -lexslt
 CFLAGS = -Wall -g
 
@@ -39,9 +37,18 @@ libxsltmod_so_SOURCES =
 libxsltmod_so_LDFLAGS = $(mylibs) $(LIBS) -shared -Wl,-soname,libxsltmod.so
 
 noinst_LTLIBRARIES = libxsltmodule.la
-libxsltmodule_la_SOURCES = libxslt.c types.c libxslt-py.c
+libxsltmodule_la_SOURCES = $(srcdir)/libxslt.c $(srcdir)/types.c $(srcdir)/libxslt-py.c
+
+GENERATE = generator.py
+API_DESC = $(top_srcdir)/doc/libxslt-api.xml $(srcdir)/libxslt-python-api.xml
+GENERATED= $(srcdir)/libxsltclass.py \
+           $(srcdir)/libxslt-export.c \
+          $(srcdir)/libxslt-py.c \
+          $(srcdir)/libxslt-py.h
 
-libxsltmod.so: $(libxsltmodule_la_OBJECTS)
+all: $(GENERATED) libxsltmod.so libxslt.py $(PYTHONSODV)
+
+libxsltmod.so: $(libxsltmodule_la_OBJECTS) libxsltmodule.la
        -(rm -f .libs/libxsltmod.so; \
          $(LINK) -o $@ $(libxsltmodule_la_OBJECTS) $(libxsltmod_so_LDFLAGS);\
          if [ -r .libs/libxsltmod.so ] ; then cp .libs/libxsltmod.so . ; fi)
@@ -57,13 +64,6 @@ install-data-local:
        -@(for doc in $(DOCS) ; \
           do @INSTALL@ -m 0644 $$doc $(DESTDIR)$(DOCS_DIR) ; done)
 
-GENERATE = generator.py
-API_DESC = $(top_srcdir)/doc/libxslt-api.xml $(srcdir)/libxslt-python-api.xml
-GENERATED= $(srcdir)/libxsltclass.py \
-           $(srcdir)/libxslt-export.c \
-          $(srcdir)/libxslt-py.c \
-          $(srcdir)/libxslt-py.h
-
 $(GENERATED): $(srcdir)/$(GENERATE) $(API_DESC)
        cd $(srcdir) && $(PYTHON) $(GENERATE)