From e0dfbada8a4a06f85b0d788e1ab3f954878b7e2c Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 19 Feb 2001 18:46:01 +0000 Subject: [PATCH] - libxslt/Makefile.am: small cleanup - libxslt/functions.c libxslt/transform.c libxslt/xsltInternals.h: fixed current() I hope Daniel --- ChangeLog | 6 ++++++ libxslt/Makefile.am | 2 +- libxslt/functions.c | 11 +++++++++- libxslt/templates.c | 2 +- libxslt/transform.c | 46 +++++++++++++++++++++++++---------------- libxslt/transform.h | 3 ++- libxslt/variables.c | 2 +- libxslt/xsltInternals.h | 3 ++- 8 files changed, 51 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f425642..a3d1c929 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Feb 19 19:34:59 CET 2001 Daniel Veillard + + * 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 * libxslt/numbers.c libxslt/numbersInternals.h libxslt/xslt.c diff --git a/libxslt/Makefile.am b/libxslt/Makefile.am index 5365bf7d..27d3b3b2 100644 --- a/libxslt/Makefile.am +++ b/libxslt/Makefile.am @@ -1,5 +1,5 @@ INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/libxslt \ - $(LIBXML_CFLAGS) -Wall -ansi + $(LIBXML_CFLAGS) $(CFLAGS) lib_LTLIBRARIES = libxslt.la diff --git a/libxslt/functions.c b/libxslt/functions.c index eec69349..d5ede7ad 100644 --- a/libxslt/functions.c +++ b/libxslt/functions.c @@ -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)); + } } /** diff --git a/libxslt/templates.c b/libxslt/templates.c index 445862fe..694357f2 100644 --- a/libxslt/templates.c +++ b/libxslt/templates.c @@ -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; diff --git a/libxslt/transform.c b/libxslt/transform.c index fc31b951..085f2363 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -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; diff --git a/libxslt/transform.h b/libxslt/transform.h index de953fba..63afb31a 100644 --- a/libxslt/transform.h +++ b/libxslt/transform.h @@ -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 diff --git a/libxslt/variables.c b/libxslt/variables.c index 5d95c792..be53cd47 100644 --- a/libxslt/variables.c +++ b/libxslt/variables.c @@ -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; diff --git a/libxslt/xsltInternals.h b/libxslt/xsltInternals.h index 908e6a93..47dfe940 100644 --- a/libxslt/xsltInternals.h +++ b/libxslt/xsltInternals.h @@ -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 */