Skip to content
Snippets Groups Projects
Commit d482e049d591 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

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
parent 48a07afb6c1b
No related branches found
No related tags found
Loading
Fri Jan 12 22:33:07 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* 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 <Daniel.Veillard@imag.fr>
* transform.c, xsltproc.c: small fight with spaces and formatting
......
......@@ -22,7 +22,7 @@
#include "xslt.h"
#include "xsltInternals.h"
#define DEBUG_PARSING
/* #define DEBUG_PARSING */
#define TODO \
xsltGenericError(xsltGenericErrorContext, \
......
......@@ -22,9 +22,10 @@
#include <libxml/encoding.h>
#include <libxml/xmlerror.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxml/HTMLtree.h>
#include "xslt.h"
#include "xsltInternals.h"
#include "pattern.h"
#include "transform.h"
......@@ -25,10 +26,10 @@
#include <libxml/HTMLtree.h>
#include "xslt.h"
#include "xsltInternals.h"
#include "pattern.h"
#include "transform.h"
#define DEBUG_PROCESS
/* #define DEBUG_PROCESS */
/*
* To cleanup
......@@ -80,6 +81,7 @@
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 @@
xmlNodePtr insert; /* the insertion node */
xmlXPathContextPtr xpathCtxt; /* the XPath context */
xmlXPathParserContextPtr xpathParserCtxt;/* the XPath parser context */
};
/************************************************************************
......@@ -126,6 +129,8 @@
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 @@
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 @@
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 @@
ctxt = xsltNewTransformContext();
if (ctxt == NULL)
return(NULL);
ctxt->doc = doc;
ctxt->style = style;
if ((style->method != NULL) &&
(!xmlStrEqual(style->method, (const xmlChar *) "xml"))) {
......
......@@ -23,7 +23,7 @@
#include "xsltInternals.h"
#include "pattern.h"
#define DEBUG_PARSING
/* #define DEBUG_PARSING */
/*
* To cleanup
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment