From 26897de4a7dd80c7e121af1308e2bbe799afbfb7 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Fri, 12 Jan 2001 21:35:20 +0000 Subject: [PATCH] Handle the first REC example correctly it seems: - pattern.c, xslt.c: removed debug - transform.c: added value-of, seems to handle the first REC example correctly Daniel --- ChangeLog | 6 +++ libxslt/pattern.c | 2 +- libxslt/transform.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++- libxslt/xslt.c | 2 +- 4 files changed, 112 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 24138e7..22037e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Jan 12 22:33:07 CET 2001 Daniel Veillard + + * pattern.c, xslt.c: removed debug + * transform.c: added value-of, seems to handle the first + REC example correctly + Fri Jan 12 18:34:01 CET 2001 Daniel Veillard * transform.c, xsltproc.c: small fight with spaces and formatting diff --git a/libxslt/pattern.c b/libxslt/pattern.c index b8b5ea3..9dddab1 100644 --- a/libxslt/pattern.c +++ b/libxslt/pattern.c @@ -22,7 +22,7 @@ #include "xslt.h" #include "xsltInternals.h" -#define DEBUG_PARSING +/* #define DEBUG_PARSING */ #define TODO \ xsltGenericError(xsltGenericErrorContext, \ diff --git a/libxslt/transform.c b/libxslt/transform.c index e29d837..7c2b228 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -22,13 +22,14 @@ #include #include #include +#include #include #include "xslt.h" #include "xsltInternals.h" #include "pattern.h" #include "transform.h" -#define DEBUG_PROCESS +/* #define DEBUG_PROCESS */ /* * To cleanup @@ -80,6 +81,7 @@ struct _xsltTransformContext { xsltStylesheetPtr style; /* the stylesheet used */ xsltOutputType type; /* the type of output */ + xmlDocPtr doc; /* the current doc */ xmlNodePtr node; /* the current node */ xmlNodeSetPtr nodeList; /* the current node list */ @@ -87,6 +89,7 @@ struct _xsltTransformContext { xmlNodePtr insert; /* the insertion node */ xmlXPathContextPtr xpathCtxt; /* the XPath context */ + xmlXPathParserContextPtr xpathParserCtxt;/* the XPath parser context */ }; /************************************************************************ @@ -126,6 +129,8 @@ void xsltFreeTransformContext(xsltTransformContextPtr ctxt) { if (ctxt == NULL) return; + if (ctxt->xpathCtxt != NULL) + xmlXPathFreeContext(ctxt->xpathCtxt); memset(ctxt, -1, sizeof(xsltTransformContext)); xmlFree(ctxt); } @@ -139,6 +144,99 @@ xsltFreeTransformContext(xsltTransformContextPtr ctxt) { void xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node); /** + * xsltValueOf: + * @ctxt: a XSLT process context + * @node: the node in the source tree. + * @inst: the xsltValueOf node + * + * Process the xsltValueOf node on the source node + */ +void +xsltValueOf(xsltTransformContextPtr ctxt, xmlNodePtr node, + xmlNodePtr inst) { + xmlChar *prop; + int disableEscaping = 0; + xmlXPathObjectPtr res, tmp; + xmlNodePtr copy = NULL; + + if ((ctxt == NULL) || (node == NULL) || (inst == NULL)) + return; + + prop = xmlGetNsProp(inst, (const xmlChar *)"disable-output-escaping", + XSLT_NAMESPACE); + if (prop != NULL) { + if (xmlStrEqual(prop, (const xmlChar *)"yes")) + disableEscaping = 1; + else if (xmlStrEqual(prop, (const xmlChar *)"no")) + disableEscaping = 0; + else + xsltGenericError(xsltGenericErrorContext, + "invalud value %s for disable-output-escaping\n", prop); + + xmlFree(prop); + if (disableEscaping) { + TODO /* disable-output-escaping */ + } + } + prop = xmlGetNsProp(inst, (const xmlChar *)"select", XSLT_NAMESPACE); + if (prop == NULL) { + xsltGenericError(xsltGenericErrorContext, + "xsltValueOf: select is not defined\n", prop); + return; + } +#ifdef DEBUG_PROCESS + xsltGenericError(xsltGenericErrorContext, + "xsltValueOf: select %s\n", prop); +#endif + + if (ctxt->xpathCtxt == NULL) { + xmlXPathInit(); + ctxt->xpathCtxt = xmlXPathNewContext(ctxt->doc); + if (ctxt->xpathCtxt == NULL) + goto error; + } + ctxt->xpathParserCtxt = + xmlXPathNewParserContext(prop, ctxt->xpathCtxt); + if (ctxt->xpathParserCtxt == NULL) + goto error; + ctxt->xpathCtxt->node = node; + valuePush(ctxt->xpathParserCtxt, xmlXPathNewNodeSet(node)); + xmlXPathEvalExpr(ctxt->xpathParserCtxt); + xmlXPathStringFunction(ctxt->xpathParserCtxt, 1); + res = valuePop(ctxt->xpathParserCtxt); + do { + tmp = valuePop(ctxt->xpathParserCtxt); + if (tmp != NULL) { + xmlXPathFreeObject(tmp); + } + } while (tmp != NULL); + if (res != NULL) { + if (res->type == XPATH_STRING) { + copy = xmlNewText(res->stringval); + if (copy != NULL) { + xmlAddChild(ctxt->insert, copy); + } + } + } + if (copy == NULL) { + xsltGenericError(xsltGenericErrorContext, + "xsltDefaultProcessOneNode: text copy failed\n"); + } +#ifdef DEBUG_PROCESS + else + xsltGenericError(xsltGenericErrorContext, + "xsltValueOf: result %s\n", res->stringval); +#endif +error: + if (ctxt->xpathParserCtxt != NULL) + xmlXPathFreeParserContext(ctxt->xpathParserCtxt); + if (prop != NULL) + xmlFree(prop); + if (res != NULL) + xmlXPathFreeObject(res); +} + +/** * xsltCopyNode: * @ctxt: a XSLT process context * @node: the element node in the source tree. @@ -335,6 +433,10 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { ctxt->insert = insert; xsltApplyTemplates(ctxt, node, cur); ctxt->insert = oldInsert; + } else if (IS_XSLT_NAME(cur, "value-of")) { + ctxt->insert = insert; + xsltValueOf(ctxt, node, cur); + ctxt->insert = oldInsert; } else { #ifdef DEBUG_PROCESS xsltGenericError(xsltGenericErrorContext, @@ -435,6 +537,7 @@ xsltApplyStylesheet(xsltStylesheetPtr style, xmlDocPtr doc) { ctxt = xsltNewTransformContext(); if (ctxt == NULL) return(NULL); + ctxt->doc = doc; ctxt->style = style; if ((style->method != NULL) && (!xmlStrEqual(style->method, (const xmlChar *) "xml"))) { diff --git a/libxslt/xslt.c b/libxslt/xslt.c index d855f36..8635976 100644 --- a/libxslt/xslt.c +++ b/libxslt/xslt.c @@ -23,7 +23,7 @@ #include "xsltInternals.h" #include "pattern.h" -#define DEBUG_PARSING +/* #define DEBUG_PARSING */ /* * To cleanup -- 2.7.4