- libxslt/Makefile.am: small cleanup
authorDaniel Veillard <veillard@src.gnome.org>
Mon, 19 Feb 2001 18:46:01 +0000 (18:46 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Mon, 19 Feb 2001 18:46:01 +0000 (18:46 +0000)
- libxslt/functions.c libxslt/transform.c libxslt/xsltInternals.h:
  fixed current() I hope
Daniel

ChangeLog
libxslt/Makefile.am
libxslt/functions.c
libxslt/templates.c
libxslt/transform.c
libxslt/transform.h
libxslt/variables.c
libxslt/xsltInternals.h

index 3f42564..a3d1c92 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Feb 19 19:34:59 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+       * libxslt/Makefile.am: small cleanup
+       * libxslt/functions.c libxslt/transform.c libxslt/xsltInternals.h:
+         fixed current() I hope
+
 Mon Feb 19 18:05:47 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
        * libxslt/numbers.c libxslt/numbersInternals.h libxslt/xslt.c
index 5365bf7..27d3b3b 100644 (file)
@@ -1,5 +1,5 @@
 INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/libxslt \
-        $(LIBXML_CFLAGS) -Wall -ansi
+        $(LIBXML_CFLAGS) $(CFLAGS)
 
 lib_LTLIBRARIES = libxslt.la
 
index eec6934..d5ede7a 100644 (file)
@@ -464,13 +464,22 @@ xsltFunctionAvailableFunction(xmlXPathParserContextPtr ctxt, int nargs){
  */
 void
 xsltCurrentFunction(xmlXPathParserContextPtr ctxt, int nargs){
+    xsltTransformContextPtr tctxt;
+
     if (nargs != 0) {
         xsltGenericError(xsltGenericErrorContext,
                "document() : function uses no argument\n");
        ctxt->error = XPATH_INVALID_ARITY;
        return;
     }
-    valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node));
+    tctxt = (xsltTransformContextPtr) ctxt->context->extra;
+    if (tctxt == NULL) {
+       xsltGenericError(xsltGenericErrorContext,
+               "current() : internal error tctxt == NULL\n");
+       valuePush(ctxt, xmlXPathNewNodeSet(NULL));
+    } else {
+       valuePush(ctxt, xmlXPathNewNodeSet(tctxt->current));
+    }
 }
 
 /**
index 445862f..694357f 100644 (file)
@@ -163,7 +163,7 @@ xsltEvalTemplateString(xsltTransformContextPtr ctxt, xmlNodePtr node,
     oldInsert = ctxt->insert;
     ctxt->insert = insert;
 
-    xsltApplyOneTemplate(ctxt, node, parent->children);
+    xsltApplyOneTemplate(ctxt, node, parent->children, 0);
 
     ctxt->insert = oldInsert;
 
index fc31b95..085f236 100644 (file)
@@ -537,7 +537,7 @@ xsltCopy(xsltTransformContextPtr ctxt, xmlNodePtr node,
        case XML_HTML_DOCUMENT_NODE:
        case XML_ELEMENT_NODE:
            varsPush(ctxt, NULL);
-           xsltApplyOneTemplate(ctxt, ctxt->node, inst->children);
+           xsltApplyOneTemplate(ctxt, ctxt->node, inst->children, 0);
            xsltFreeStackElemList(varsPop(ctxt));
            break;
        default:
@@ -670,7 +670,7 @@ xsltElement(xsltTransformContextPtr ctxt, xmlNodePtr node,
     }
     
     varsPush(ctxt, NULL);
-    xsltApplyOneTemplate(ctxt, ctxt->node, inst->children);
+    xsltApplyOneTemplate(ctxt, ctxt->node, inst->children, 0);
     xsltFreeStackElemList(varsPop(ctxt));
 
     ctxt->insert = oldInsert;
@@ -1115,7 +1115,7 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
                ctxt->node = node;
                templPush(ctxt, template);
                varsPush(ctxt, NULL);
-               xsltApplyOneTemplate(ctxt, node, template->content);
+               xsltApplyOneTemplate(ctxt, node, template->content, 1);
                xsltFreeStackElemList(varsPop(ctxt));
                templPop(ctxt);
                ctxt->node = oldNode;
@@ -1148,7 +1148,7 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
                ctxt->node = node;
                templPush(ctxt, template);
                varsPush(ctxt, NULL);
-               xsltApplyOneTemplate(ctxt, node, template->content);
+               xsltApplyOneTemplate(ctxt, node, template->content, 1);
                xsltFreeStackElemList(varsPop(ctxt));
                templPop(ctxt);
                ctxt->node = oldNode;
@@ -1182,7 +1182,7 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
                    ctxt->node = node;
                    templPush(ctxt, template);
                    varsPush(ctxt, NULL);
-                   xsltApplyOneTemplate(ctxt, node, template->content);
+                   xsltApplyOneTemplate(ctxt, node, template->content, 1);
                    xsltFreeStackElemList(varsPop(ctxt));
                    templPop(ctxt);
                    ctxt->node = oldNode;
@@ -1273,7 +1273,7 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
            ctxt->node = node;
            templPush(ctxt, template);
            varsPush(ctxt, NULL);
-           xsltApplyOneTemplate(ctxt, node, template->content);
+           xsltApplyOneTemplate(ctxt, node, template->content, 1);
            xsltFreeStackElemList(varsPop(ctxt));
            templPop(ctxt);
            ctxt->node = oldNode;
@@ -1307,7 +1307,7 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
                    ctxt->node = node;
                    templPush(ctxt, template);
                    varsPush(ctxt, NULL);
-                   xsltApplyOneTemplate(ctxt, node, template->content);
+                   xsltApplyOneTemplate(ctxt, node, template->content, 1);
                    xsltFreeStackElemList(varsPop(ctxt));
                    templPop(ctxt);
                    ctxt->node = oldNode;
@@ -1342,7 +1342,7 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
                    ctxt->xpathCtxt->proximityPosition = childno;
                    templPush(ctxt, template);
                    varsPush(ctxt, NULL);
-                   xsltApplyOneTemplate(ctxt, cur, template->content);
+                   xsltApplyOneTemplate(ctxt, cur, template->content, 1);
                    xsltFreeStackElemList(varsPop(ctxt));
                    templPop(ctxt);
                    ctxt->node = oldNode;
@@ -1377,7 +1377,7 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
                    ctxt->xpathCtxt->proximityPosition = childno;
                    templPush(ctxt, template);
                    varsPush(ctxt, NULL);
-                   xsltApplyOneTemplate(ctxt, cur, template->content);
+                   xsltApplyOneTemplate(ctxt, cur, template->content, 1);
                    xsltFreeStackElemList(varsPop(ctxt));
                    templPop(ctxt);
                    ctxt->node = oldNode;
@@ -1414,7 +1414,7 @@ xsltApplyImports(xsltTransformContextPtr ctxt, xmlNodePtr node,
     if (template != NULL) {
        templPush(ctxt, template);
        varsPush(ctxt, NULL);
-       xsltApplyOneTemplate(ctxt, node, template->content);
+       xsltApplyOneTemplate(ctxt, node, template->content, 1);
        xsltFreeStackElemList(varsPop(ctxt));
        templPop(ctxt);
     }
@@ -1488,7 +1488,7 @@ xsltCallTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
        }
        cur = cur->next;
     }
-    xsltApplyOneTemplate(ctxt, node, template->content);
+    xsltApplyOneTemplate(ctxt, node, template->content, 1);
 
     xsltFreeStackElemList(varsPop(ctxt));
     templPop(ctxt);
@@ -1719,14 +1719,16 @@ error:
  * @ctxt:  a XSLT process context
  * @node:  the node in the source tree.
  * @list:  the template replacement nodelist
+ * @real: is this a real template processing
  *
  * Process the apply-templates node on the source node
  */
 void
 xsltApplyOneTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
-                    xmlNodePtr list) {
+                    xmlNodePtr list, int real) {
     xmlNodePtr cur = NULL, insert, copy = NULL;
     xmlNodePtr oldInsert;
+    xmlNodePtr oldCurrent;
     xmlAttrPtr attrs;
 
     if (list == NULL)
@@ -1746,6 +1748,10 @@ xsltApplyOneTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
      * stack and saves
      */
     oldInsert = insert = ctxt->insert;
+    if (real) {
+       oldCurrent = ctxt->current;
+       ctxt->current = node;
+    }
 
     /*
      * Insert all non-XSLT nodes found in the template
@@ -1760,6 +1766,8 @@ xsltApplyOneTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
            xsltGenericDebug(xsltGenericDebugContext,
                 "xsltApplyOneTemplate: insert == NULL !\n");
 #endif
+           if (real)
+               ctxt->current = oldCurrent;
            return;
        }
 
@@ -1918,6 +1926,8 @@ skip_children:
            }
        } while (cur != NULL);
     }
+    if (real)
+       ctxt->current = oldCurrent;
 }
 
 /**
@@ -2001,7 +2011,7 @@ xsltChoose(xsltTransformContextPtr ctxt, xmlNodePtr node,
 #endif
        if (doit) {
            varsPush(ctxt, NULL);
-           xsltApplyOneTemplate(ctxt, ctxt->node, when->children);
+           xsltApplyOneTemplate(ctxt, ctxt->node, when->children, 0);
            xsltFreeStackElemList(varsPop(ctxt));
            goto done;
        }
@@ -2018,7 +2028,7 @@ xsltChoose(xsltTransformContextPtr ctxt, xmlNodePtr node,
     }
     if (IS_XSLT_ELEM(replacement) && (IS_XSLT_NAME(replacement, "otherwise"))) {
        varsPush(ctxt, NULL);
-       xsltApplyOneTemplate(ctxt, ctxt->node, replacement->children);
+       xsltApplyOneTemplate(ctxt, ctxt->node, replacement->children, 0);
        xsltFreeStackElemList(varsPop(ctxt));
        replacement = replacement->next;
     }
@@ -2104,7 +2114,7 @@ xsltIf(xsltTransformContextPtr ctxt, xmlNodePtr node,
 #endif
     if (doit) {
        varsPush(ctxt, NULL);
-       xsltApplyOneTemplate(ctxt, node, inst->children);
+       xsltApplyOneTemplate(ctxt, node, inst->children, 0);
        xsltFreeStackElemList(varsPop(ctxt));
     }
 
@@ -2198,7 +2208,7 @@ xsltForEach(xsltTransformContextPtr ctxt, xmlNodePtr node,
        ctxt->node = list->nodeTab[i];
        ctxt->xpathCtxt->proximityPosition = i + 1;
        varsPush(ctxt, NULL);
-       xsltApplyOneTemplate(ctxt, list->nodeTab[i], replacement);
+       xsltApplyOneTemplate(ctxt, list->nodeTab[i], replacement, 0);
        xsltFreeStackElemList(varsPop(ctxt));
     }
     ctxt->nodeList = oldlist;
@@ -2257,7 +2267,7 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
 #endif
        templPush(ctxt, template);
        varsPush(ctxt, NULL);
-       xsltApplyOneTemplate(ctxt, node, template->content);
+       xsltApplyOneTemplate(ctxt, node, template->content, 1);
        xsltFreeStackElemList(varsPop(ctxt));
        templPop(ctxt);
     } else {
@@ -2273,7 +2283,7 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
        ctxt->node = node;
        templPush(ctxt, template);
        varsPush(ctxt, NULL);
-       xsltApplyOneTemplate(ctxt, node, template->content);
+       xsltApplyOneTemplate(ctxt, node, template->content, 1);
        xsltFreeStackElemList(varsPop(ctxt));
        templPop(ctxt);
        ctxt->node = oldNode;
index de953fb..63afb31 100644 (file)
@@ -23,7 +23,8 @@ xmlDocPtr     xsltApplyStylesheet     (xsltStylesheetPtr style,
                                         xmlDocPtr doc);
 void           xsltApplyOneTemplate    (xsltTransformContextPtr ctxt,
                                         xmlNodePtr node,
-                                        xmlNodePtr list);
+                                        xmlNodePtr list,
+                                        int real);
 #ifdef __cplusplus
 }
 #endif
index 5d95c79..be53cd4 100644 (file)
@@ -288,7 +288,7 @@ xsltEvalVariables(xsltTransformContextPtr ctxt, xsltStackElemPtr elem) {
            oldNode = ctxt->node;
            ctxt->insert = container;
 
-           xsltApplyOneTemplate(ctxt, ctxt->node, elem->tree);
+           xsltApplyOneTemplate(ctxt, ctxt->node, elem->tree, 0);
 
            ctxt->insert = oldInsert;
            ctxt->node = oldNode;
index 908e6a9..47dfe94 100644 (file)
@@ -216,8 +216,9 @@ struct _xsltTransformContext {
     xsltDocumentPtr docList;           /* the document list */
 
     xsltDocumentPtr document;          /* the current document */
-    xmlNodePtr node;                   /* the current node */
+    xmlNodePtr node;                   /* the node being processed */
     xmlNodeSetPtr nodeList;            /* the current node list */
+    xmlNodePtr current;                        /* the current node */
 
     xmlDocPtr output;                  /* the resulting document */
     xmlNodePtr insert;                 /* the insertion node */