* @ctxt: an XSLT transformation context
*
* Creates a Result Value Tree
- * (the XSLT 1.0 term for this is "Result Tree Fragment")
+ * (the XSLT 1.0 term for this is "Result Tree Fragment")
*
* Returns the result value tree or NULL in case of API or internal errors.
*/
/*
* Question: Why is this function public?
* Answer: It is called by the EXSLT module.
- */
+ */
if (ctxt == NULL)
return(NULL);
{
if ((ctxt == NULL) || (RVT == NULL))
return(-1);
-
+
/*
* When evaluating "select" expressions of xsl:variable
* and xsl:param, we need to bind newly created tree fragments
(((xmlNsPtr) cur)->next->type == XML_ELEMENT_NODE))
{
cur = (xmlNodePtr) ((xmlNsPtr) cur)->next;
- doc = cur->doc;
+ doc = cur->doc;
} else {
xsltTransformError(ctxt, NULL, ctxt->inst,
"Internal error in "
}
/*
* Clear the document tree.
- * REVISIT TODO: Do we expect ID/IDREF tables to be existent?
+ * REVISIT TODO: Do we expect ID/IDREF tables to be existent?
*/
if (RVT->children != NULL) {
xmlFreeNodeList(RVT->children);
cur->nameURI = elem->nameURI;
cur->select = elem->select;
cur->tree = elem->tree;
- cur->comp = elem->comp;
+ cur->comp = elem->comp;
return(cur);
}
* </xsl:variable>
* <f:result select="$bar"/>
* </f:function>
- *
+ *
*/
xsltRegisterLocalRVT(elem->context, cur);
} else {
xsltReleaseRVT((xsltTransformContextPtr) elem->context,
cur);
- }
+ }
}
}
/*
memset(elem, 0, sizeof(xsltStackElem));
elem->context = ctxt;
elem->next = ctxt->cache->stackItems;
- ctxt->cache->stackItems = elem;
+ ctxt->cache->stackItems = elem;
ctxt->cache->nbStackItems++;
#ifdef XSLT_DEBUG_PROFILE_CACHE
ctxt->cache->dbgCachedVars++;
void
xsltFreeStackElemList(xsltStackElemPtr elem) {
xsltStackElemPtr next;
-
+
while (elem != NULL) {
next = elem->next;
xsltFreeStackElem(elem);
return(NULL);
}
+#ifdef XSLT_REFACTORED
+#else
+
/**
* xsltCheckStackElem:
* @ctxt: xn XSLT transformation context
else if (cur->comp->type == XSLT_FUNC_PARAM)
return(2);
}
-
+
return(1);
}
+#endif /* XSLT_REFACTORED */
+
/**
* xsltAddStackElem:
* @ctxt: xn XSLT transformation context
}
ctxt->varsTab[ctxt->varsNr++] = elem;
ctxt->vars = elem;
-
+
elem = elem->next;
} while (elem != NULL);
-
+
return(0);
}
(xsltStyleItemVariablePtr) castedComp;
#else
xsltStylePreCompPtr comp = castedComp;
-#endif
+#endif
xmlXPathObjectPtr result = NULL;
xmlNodePtr oldInst;
oldXPContextSize = xpctxt->contextSize;
oldXPNamespaces = xpctxt->namespaces;
oldXPNsNr = xpctxt->nsNr;
-
+
xpctxt->node = ctxt->node;
/*
* OPTIMIZE TODO: Lame try to set the context doc.
/*
* BUG TODO: The proximity position and the context size will
* potentially be wrong.
- * Example:
+ * Example:
* <xsl:template select="foo">
* <xsl:variable name="pos" select="position()"/>
* <xsl:for-each select="bar">
* to the context of <xsl:for-each select="bar">, but
* the variable needs to be evaluated in the context of
* <xsl:template select="foo">.
- */
+ */
if (comp != NULL) {
-
+
#ifdef XSLT_REFACTORED
if (comp->inScopeNs != NULL) {
xpctxt->namespaces = comp->inScopeNs->list;
* we'll eventually free still referenced fragments, before
* we leave the scope of the variable.
*/
- ctxt->contextVariable = variable;
- variable->flags |= XSLT_VAR_IN_SELECT;
-
+ ctxt->contextVariable = variable;
+ variable->flags |= XSLT_VAR_IN_SELECT;
+
result = xmlXPathCompiledEval(xpExpr, xpctxt);
variable->flags ^= XSLT_VAR_IN_SELECT;
} else {
if (variable->tree == NULL) {
result = xmlXPathNewCString("");
- } else {
+ } else {
if (variable->tree) {
xmlDocPtr container;
xmlNodePtr oldInsert;
*/
/*
* Attach the Result Tree Fragment to the variable;
- * when the variable is freed, it will also free
+ * when the variable is freed, it will also free
* the Result Tree Fragment.
*/
variable->fragment = container;
-
+
oldOutput = ctxt->output;
- oldInsert = ctxt->insert;
-
+ oldInsert = ctxt->insert;
+
ctxt->output = container;
ctxt->insert = (xmlNodePtr) container;
ctxt->contextVariable = variable;
xsltApplyOneTemplate(ctxt, ctxt->node, variable->tree,
NULL, NULL);
- ctxt->contextVariable = oldVar;
+ ctxt->contextVariable = oldVar;
ctxt->insert = oldInsert;
ctxt->output = oldOutput;
-
+
result = xmlXPathNewValueTree((xmlNodePtr) container);
}
if (result == NULL) {
* Freeing is not handled there anymore.
* QUESTION TODO: What does the above comment mean?
*/
- result->boolval = 0;
+ result->boolval = 0;
}
#ifdef WITH_XSLT_DEBUG_VARIABLE
#ifdef LIBXML_DEBUG_ENABLED
#endif
oldInst = ctxt->inst;
+#ifdef XSLT_REFACTORED
+ comp = (xsltStyleBasicItemVariablePtr) elem->comp;
+#else
comp = elem->comp;
+#endif
oldVarName = elem->name;
elem->name = xsltComputingGlobalVarMarker;
/*
* called; and in the case of global params, if values for such params
* are provided by the user.
*/
- if (elem->select != NULL) {
+ if (elem->select != NULL) {
xmlXPathCompExprPtr xpExpr = NULL;
xmlDocPtr oldXPDoc;
xmlNodePtr oldXPContextNode;
}
if (xpExpr == NULL)
goto error;
-
-
+
+
if (comp != NULL)
ctxt->inst = comp->inst;
else
* to process the root node of the source document: the current
* node is the root node of the source document and the current
* node list is a list containing just the root node of the source
- * document."
+ * document."
*/
/*
* Save context states.
oldXPContextSize = xpctxt->contextSize;
oldXPNamespaces = xpctxt->namespaces;
oldXPNsNr = xpctxt->nsNr;
-
+
xpctxt->node = ctxt->initialContextNode;
xpctxt->doc = ctxt->initialContextDoc;
xpctxt->contextSize = 1;
xpctxt->proximityPosition = 1;
-
+
if (comp != NULL) {
-
+
#ifdef XSLT_REFACTORED
if (comp->inScopeNs != NULL) {
xpctxt->namespaces = comp->inScopeNs->list;
xpctxt->namespaces = NULL;
xpctxt->nsNr = 0;
}
-
+
result = xmlXPathCompiledEval(xpExpr, xpctxt);
/*
} else {
xmlDocPtr container;
xmlNodePtr oldInsert;
- xmlDocPtr oldOutput, oldXPDoc;
+ xmlDocPtr oldOutput, oldXPDoc;
/*
* Generate a result tree fragment.
*/
* Let the lifetime of the tree fragment be handled by
* the Libxslt's garbage collector.
*/
- xsltRegisterPersistRVT(ctxt, container);
+ xsltRegisterPersistRVT(ctxt, container);
oldOutput = ctxt->output;
oldInsert = ctxt->insert;
oldXPDoc = ctxt->xpathCtxt->doc;
-
- ctxt->output = container;
+
+ ctxt->output = container;
ctxt->insert = (xmlNodePtr) container;
ctxt->xpathCtxt->doc = ctxt->initialContextDoc;
ctxt->insert = oldInsert;
ctxt->output = oldOutput;
-
+
result = xmlXPathNewValueTree((xmlNodePtr) container);
if (result == NULL) {
result = xmlXPathNewCString("");
int
xsltEvalGlobalVariables(xsltTransformContextPtr ctxt) {
xsltStackElemPtr elem;
- xsltStylesheetPtr style;
+ xsltStylesheetPtr style;
if ((ctxt == NULL) || (ctxt->document == NULL))
return(-1);
-
+
#ifdef WITH_XSLT_DEBUG_VARIABLE
XSLT_TRACE(ctxt,XSLT_TRACE_VARIABLES,xsltGenericDebug(xsltGenericDebugContext,
"Registering global variables\n"));
style = ctxt->style;
while (style != NULL) {
elem = style->variables;
-
+
#ifdef WITH_XSLT_DEBUG_VARIABLE
if ((style->doc != NULL) && (style->doc->URL != NULL)) {
XSLT_TRACE(ctxt,XSLT_TRACE_VARIABLES,xsltGenericDebug(xsltGenericDebugContext,
/*
* Global variables are stored in the variables pool.
*/
- def = (xsltStackElemPtr)
+ def = (xsltStackElemPtr)
xmlHashLookup2(ctxt->globalVars,
elem->name, elem->nameURI);
if (def == NULL) {
/*
* This part does the actual evaluation
- */
+ */
xmlHashScan(ctxt->globalVars,
(xmlHashScanner) xsltEvalGlobalVariable, ctxt);
const xmlChar *href;
xmlXPathCompExprPtr xpExpr;
xmlXPathObjectPtr result;
-
+
xsltStackElemPtr elem;
int res;
void *res_ptr;
int oldXPProximityPosition, oldXPContextSize, oldXPNsNr;
xmlNsPtr *oldXPNamespaces;
xmlXPathContextPtr xpctxt = ctxt->xpathCtxt;
-
+
/*
* Save context states.
*/
* node list is a list containing just the root node of the source
* document."
*/
- xpctxt->doc = ctxt->initialContextDoc;
- xpctxt->node = ctxt->initialContextNode;
+ xpctxt->doc = ctxt->initialContextDoc;
+ xpctxt->node = ctxt->initialContextNode;
xpctxt->contextSize = 1;
xpctxt->proximityPosition = 1;
- /*
+ /*
* There is really no in scope namespace for parameters on the
* command line.
*/
xpctxt->namespaces = NULL;
- xpctxt->nsNr = 0;
-
+ xpctxt->nsNr = 0;
+
result = xmlXPathCompiledEval(xpExpr, xpctxt);
-
+
/*
* Restore Context states.
*/
xpctxt->proximityPosition = oldXPProximityPosition;
xpctxt->namespaces = oldXPNamespaces;
xpctxt->nsNr = oldXPNsNr;
-
+
xmlXPathFreeCompExpr(xpExpr);
}
if (result == NULL) {
}
}
- /*
+ /*
* If @eval is 0 then @value is to be taken literally and result is NULL
- *
+ *
* If @eval is not 0, then @value is an XPath expression and has been
* successfully evaluated and result contains the resulting value and
* is not NULL.
elem->computed = 1;
if (eval == 0) {
elem->value = xmlXPathNewString(value);
- }
+ }
else {
elem->value = result;
}
*
* Returns 0 in case of success, -1 in case of error
*/
-
+
int
xsltEvalUserParams(xsltTransformContextPtr ctxt, const char **params) {
int indx = 0;
while (params[indx] != NULL) {
name = (const xmlChar *) params[indx++];
value = (const xmlChar *) params[indx++];
- if (xsltEvalOneUserParam(ctxt, name, value) != 0)
+ if (xsltEvalOneUserParam(ctxt, name, value) != 0)
return(-1);
}
return 0;
*
* Returns 0 in case of success, -1 in case of error.
*/
-
+
int
xsltQuoteUserParams(xsltTransformContextPtr ctxt, const char **params) {
int indx = 0;
while (params[indx] != NULL) {
name = (const xmlChar *) params[indx++];
value = (const xmlChar *) params[indx++];
- if (xsltQuoteOneUserParam(ctxt, name, value) != 0)
+ if (xsltQuoteOneUserParam(ctxt, name, value) != 0)
return(-1);
}
return 0;
int
xsltEvalOneUserParam(xsltTransformContextPtr ctxt,
- const xmlChar * name,
+ const xmlChar * name,
const xmlChar * value) {
return xsltProcessUserParamInternal(ctxt, name, value,
1 /* xpath eval ? */);
(xsltStyleBasicItemVariablePtr) castedComp;
#else
xsltStylePreCompPtr comp = castedComp;
-#endif
+#endif
xsltStackElemPtr elem;
#ifdef WITH_XSLT_DEBUG_VARIABLE
xsltStylePreCompPtr comp = castedComp;
int present;
#endif
- xsltStackElemPtr variable;
-
+ xsltStackElemPtr variable;
+
#ifdef XSLT_REFACTORED
/*
* REFACTORED NOTE: Redefinitions of vars/params are checked
*/
#else
present = xsltCheckStackElem(ctxt, comp->name, comp->ns);
- if (isParam == 0) {
+ if (isParam == 0) {
if ((present != 0) && (present != 3)) {
/* TODO: report QName. */
xsltTransformError(ctxt, NULL, comp->inst,
/**
* xsltParseStylesheetCallerParam:
- * @ctxt: the XSLT transformation context
+ * @ctxt: the XSLT transformation context
* @inst: the xsl:with-param instruction element
*
* Processes an xsl:with-param instruction at transformation time.
* The value is compute, but not recorded.
* NOTE that this is also called with an *xsl:param* element
- * from exsltFuncFunctionFunction().
+ * from exsltFuncFunctionFunction().
*
* Returns the new xsltStackElemPtr or NULL
*/
xmlNodePtr tree = NULL; /* The first child node of the instruction or
the instruction itself. */
xsltStackElemPtr param = NULL;
-
- if ((ctxt == NULL) || (inst == NULL))
+
+ if ((ctxt == NULL) || (inst == NULL) || (inst->type != XML_ELEMENT_NODE))
return(NULL);
#ifdef XSLT_REFACTORED
#else
comp = (xsltStylePreCompPtr) inst->psvi;
#endif
-
+
if (comp == NULL) {
xsltTransformError(ctxt, NULL, inst,
"Internal error in xsltParseStylesheetCallerParam(): "
xsltStylePreCompPtr comp;
#endif
- if ((cur == NULL) || (style == NULL))
+ if ((cur == NULL) || (style == NULL) || (cur->type != XML_ELEMENT_NODE))
return;
-
+
#ifdef XSLT_REFACTORED
/*
* Note that xsltStylePreCompute() will be called from
* Parse the content (a sequence constructor) of xsl:variable.
*/
if (cur->children != NULL) {
-#ifdef XSLT_REFACTORED
+#ifdef XSLT_REFACTORED
xsltParseSequenceConstructor(XSLT_CCTXT(style), cur->children);
#else
xsltParseTemplateContent(style, cur);
xsltStylePreCompPtr comp;
#endif
- if ((cur == NULL) || (style == NULL))
+ if ((cur == NULL) || (style == NULL) || (cur->type != XML_ELEMENT_NODE))
return;
-
+
#ifdef XSLT_REFACTORED
/*
* Note that xsltStylePreCompute() will be called from
#else
xsltStylePreCompute(style, cur);
comp = (xsltStylePreCompPtr) cur->psvi;
-#endif
+#endif
if (comp == NULL) {
xsltTransformError(NULL, style, cur,
"xsl:param : compilation failed\n");
* Parse the content (a sequence constructor) of xsl:param.
*/
if (cur->children != NULL) {
-#ifdef XSLT_REFACTORED
+#ifdef XSLT_REFACTORED
xsltParseSequenceConstructor(XSLT_CCTXT(style), cur->children);
#else
xsltParseTemplateContent(style, cur);
xsltStylePreCompPtr comp;
#endif
- if ((inst == NULL) || (ctxt == NULL))
+ if ((inst == NULL) || (ctxt == NULL) || (inst->type != XML_ELEMENT_NODE))
return;
comp = inst->psvi;
xsltStylePreCompPtr comp;
#endif
- if ((cur == NULL) || (ctxt == NULL))
+ if ((cur == NULL) || (ctxt == NULL) || (cur->type != XML_ELEMENT_NODE))
return;
comp = cur->psvi;
XSLT_TRACE(((xsltTransformContextPtr)ctxt),XSLT_TRACE_VARIABLES,xsltGenericDebug(xsltGenericDebugContext,
"Lookup variable '%s'\n", name));
#endif
-
+
tctxt = (xsltTransformContextPtr) ctxt;
/*
* Local variables/params ---------------------------------------------
goto local_variable_found;
}
cur = cur->next;
- }
+ }
/*
* Redo the lookup with interned strings to avoid string comparison.
*
name = xmlDictLookup(tctxt->dict, name, -1);
if (ns_uri)
ns_uri = xmlDictLookup(tctxt->dict, ns_uri, -1);
- if ((tmpName != name) || (tmpNsName != ns_uri)) {
+ if ((tmpName != name) || (tmpNsName != ns_uri)) {
for (i = tctxt->varsNr; i > tctxt->varsBase; i--) {
cur = tctxt->varsTab[i-1];
if ((cur->name == name) && (cur->nameURI == ns_uri)) {
if (variable) {
if (variable->computed == 0) {
-
+
#ifdef WITH_XSLT_DEBUG_VARIABLE
XSLT_TRACE(tctxt,XSLT_TRACE_VARIABLES,xsltGenericDebug(xsltGenericDebugContext,
"uncomputed variable '%s'\n", name));
variable->computed = 1;
}
if (variable->value != NULL) {
- valueObj = xmlXPathObjectCopy(variable->value);
+ valueObj = xmlXPathObjectCopy(variable->value);
}
return(valueObj);
}
}
/*
* Global variables/params --------------------------------------------
- */
+ */
if (tctxt->globalVars) {
valueObj = xsltGlobalVariableLookup(tctxt, name, ns_uri);
}