/*
* transform.c: Implemetation of the XSL Transformation 1.0 engine
- * transform part, i.e. applying a Stylesheet to a document
+ * transform part, i.e. applying a Stylesheet to a document
*
* References:
* http://www.w3.org/TR/1999/REC-xslt-19991116
/************************************************************************
* *
- * handling of transformation contexts *
+ * Handling of Transformation Contexts *
* *
************************************************************************/
cur->varsNr = 0;
cur->varsMax = 5;
cur->vars = NULL;
+ cur->varsBase = 0;
cur->style = style;
xmlXPathInit();
/**
* xsltCopyPropList:
* @ctxt: a XSLT process context
- * @target: the element where the attributes will be grafted
- * @cur: the first attribute
+ * @target: the element where the properties will be grafted
+ * @cur: the first property
*
- * Do a copy of an attribute list.
+ * Do a copy of a properties list.
*
* Returns: a new xmlAttrPtr, or NULL in case of error.
*/
/**
* xsltCopyTreeList:
* @ctxt: a XSLT process context
- * @list: the list of element node in the source tree.
+ * @list: the list of element nodes in the source tree.
* @insert: the parent in the result tree.
*
* Make a copy of the full list of tree @list
- * and insert them as last children of @insert
+ * and insert it as last children of @insert
*
* Returns a pointer to the new list, or NULL in case of error
*/
* <xsl:value-of select="."/>
* </xsl:template>
*
- * Note also that namespaces declarations are copied directly:
+ * Note also that namespace declarations are copied directly:
*
* the built-in template rule is the only template rule that is applied
* for namespace nodes.
int strip_spaces = -1;
int nbchild = 0, oldSize;
int childno = 0, oldPos;
+ int oldBase;
xsltTemplatePtr template;
CHECK_STOPPED;
oldNode = ctxt->node;
ctxt->node = node;
templPush(ctxt, template);
+ oldBase = ctxt->varsBase;
+ ctxt->varsBase = ctxt->varsNr - 1;
xsltApplyOneTemplate(ctxt, node, template->content, 1);
templPop(ctxt);
+ ctxt->varsBase = oldBase;
ctxt->node = oldNode;
}
attrs = attrs->next;
oldNode = ctxt->node;
ctxt->node = node;
templPush(ctxt, template);
+ oldBase = ctxt->varsBase;
+ ctxt->varsBase = ctxt->varsNr - 1;
xsltApplyOneTemplate(ctxt, node, template->content, 1);
templPop(ctxt);
+ ctxt->varsBase = oldBase;
ctxt->node = oldNode;
} else /* if (ctxt->mode == NULL) */ {
#ifdef WITH_XSLT_DEBUG_PROCESS
ctxt->xpathCtxt->contextSize = nbchild;
ctxt->xpathCtxt->proximityPosition = childno;
templPush(ctxt, template);
+ oldBase = ctxt->varsBase;
+ ctxt->varsBase = ctxt->varsNr - 1;
xsltApplyOneTemplate(ctxt, cur, template->content, 1);
templPop(ctxt);
+ ctxt->varsBase = oldBase;
ctxt->node = oldNode;
} else /* if (ctxt->mode == NULL) */ {
#ifdef WITH_XSLT_DEBUG_PROCESS
ctxt->xpathCtxt->contextSize = nbchild;
ctxt->xpathCtxt->proximityPosition = childno;
templPush(ctxt, template);
+ oldBase = ctxt->varsBase;
+ ctxt->varsBase = ctxt->varsNr - 1;
xsltApplyOneTemplate(ctxt, cur, template->content, 1);
templPop(ctxt);
+ ctxt->varsBase = oldBase;
ctxt->node = oldNode;
}
break;
xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
xsltTemplatePtr template;
xmlNodePtr oldNode;
+ int oldBase;
/*
* Cleanup children empty nodes if asked for
template->match, node->name);
#endif
templPush(ctxt, template);
+ oldBase = ctxt->varsBase;
+ ctxt->varsBase = ctxt->varsNr - 1;
xsltApplyOneTemplate(ctxt, node, template->content, 1);
templPop(ctxt);
+ ctxt->varsBase = oldBase;
} else {
#ifdef WITH_XSLT_DEBUG_PROCESS
if (node->type == XML_DOCUMENT_NODE)
oldNode = ctxt->node;
ctxt->node = node;
templPush(ctxt, template);
+ oldBase = ctxt->varsBase;
+ ctxt->varsBase = ctxt->varsNr - 1;
xsltApplyOneTemplate(ctxt, node, template->content, 1);
templPop(ctxt);
+ ctxt->varsBase = oldBase;
ctxt->node = oldNode;
}
}
cur->name);
#endif
/*
- * Search if there is fallbacks
+ * Search if there are fallbacks
*/
child = cur->children;
while (child != NULL) {
* @ctxt: an XSLT processing context
* @node: The current node
* @inst: the instruction in the stylesheet
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process an XSLT-1.1 document element
*/
xsltFreeStackElemList(varsPop(ctxt));
/*
- * Save the res
+ * Save the result
*/
ret = xsltSaveResultToFilename((const char *) filename,
res, style, 0);
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt sort node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* function attached to xsl:sort nodes, but this should not be
* called directly
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt copy node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt copy node on the source node
*/
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt text node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt text node on the source node
*/
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt element node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt element node on the source node
*/
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt attribute node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt attribute node on the source node
*/
}
if (ctxt->insert->children != NULL) {
xsltGenericError(xsltGenericErrorContext,
- "xsl:attribute : node has already children\n");
+ "xsl:attribute : node already has children\n");
return;
}
if (comp->name == NULL) {
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt comment node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt comment node on the source node
*/
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt processing-instruction node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt processing-instruction node on the source node
*/
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt copy-of node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt copy-of node on the source node
*/
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt value-of node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt value-of node on the source node
*/
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt number node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt number node on the source node
*/
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt apply-imports node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt apply-imports node on the source node
*/
xsltApplyImports(xsltTransformContextPtr ctxt, xmlNodePtr node,
xmlNodePtr inst ATTRIBUTE_UNUSED, xsltStylePreCompPtr comp ATTRIBUTE_UNUSED) {
xsltTemplatePtr template;
+ int oldBase;
if ((ctxt->templ == NULL) || (ctxt->templ->style == NULL)) {
xsltGenericError(xsltGenericErrorContext,
template = xsltGetTemplate(ctxt, node, ctxt->templ->style);
if (template != NULL) {
templPush(ctxt, template);
+ oldBase = ctxt->varsBase;
+ ctxt->varsBase = ctxt->varsNr - 1;
varsPush(ctxt, NULL);
xsltApplyOneTemplate(ctxt, node, template->content, 1);
xsltFreeStackElemList(varsPop(ctxt));
templPop(ctxt);
+ ctxt->varsBase = oldBase;
}
}
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt call-template node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt call-template node on the source node
*/
xmlNodePtr inst, xsltStylePreCompPtr comp) {
xmlNodePtr cur = NULL;
xsltStackElemPtr params = NULL, param;
-
+ int oldBase;
if (ctxt->insert == NULL)
return;
}
}
- /*
- * Create a new frame but block access to variables
- */
- templPush(ctxt, comp->templ);
cur = inst->children;
while (cur != NULL) {
if (ctxt->state == XSLT_STATE_STOPPED) break;
}
cur = cur->next;
}
+ /*
+ * Create a new frame but block access to variables
+ */
+ templPush(ctxt, comp->templ);
+ oldBase = ctxt->varsBase; /* Save the original variable base */
varsPush(ctxt, params);
+ ctxt->varsBase = ctxt->varsNr - 1; /* Reset base to be new templ params */
xsltApplyOneTemplate(ctxt, node, comp->templ->content, 1);
xsltFreeStackElemList(varsPop(ctxt));
templPop(ctxt);
+ ctxt->varsBase = oldBase; /* Restore the original variable base */
}
/**
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the apply-templates node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the apply-templates node on the source node
*/
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt choose node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt choose node on the source node
*/
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt if node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt if node on the source node
*/
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt for-each node
- * @comp: precomputed informations
+ * @comp: precomputed information
*
* Process the xslt for-each node on the source node
*/
ctxt->node = (xmlNodePtr) doc;
xsltInitCtxtExts(ctxt);
varsPush(ctxt, NULL);
+ ctxt->varsBase = ctxt->varsNr - 1;
xsltProcessOneNode(ctxt, ctxt->node);
xsltFreeStackElemList(varsPop(ctxt));
xsltShutdownCtxtExts(ctxt);