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

No sleep :-(, still stuck in (test/debug/patch) loop:

- tests/REC/test-11*: added more tests
- libxslt/transform.c libxslt/variables.c: fixing bugs raised by
  said tests
Daniel
parent 366feca8ee22
No related branches found
No related tags found
No related merge requests found
Showing
with 211 additions and 0 deletions
Thu Feb 1 05:36:28 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* tests/REC/test-11*: added more tests
* libxslt/transform.c libxslt/variables.c: fixing bugs raised by
said tests
Wed Jan 31 21:42:43 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* tests/REC/test-[9-10]*: added more tests
......
......@@ -1312,6 +1312,125 @@
}
/**
* xsltChoose:
* @ctxt: a XSLT process context
* @node: the node in the source tree.
* @inst: the xslt choose node
*
* Process the xslt choose node on the source node
*/
void
xsltChoose(xsltTransformContextPtr ctxt, xmlNodePtr node,
xmlNodePtr inst) {
xmlChar *prop;
xmlXPathObjectPtr res = NULL, tmp;
xmlXPathParserContextPtr xpathParserCtxt = NULL;
xmlNodePtr replacement, when;
int doit = 1;
if ((ctxt == NULL) || (node == NULL) || (inst == NULL))
return;
/*
* Check the when's
*/
replacement = inst->children;
if (replacement == NULL) {
xsltGenericError(xsltGenericErrorContext,
"xslt:choose: empty content not allowed\n");
goto error;
}
if ((!IS_XSLT_ELEM(replacement)) ||
(!IS_XSLT_NAME(replacement, "when"))) {
xsltGenericError(xsltGenericErrorContext,
"xslt:choose: xsl:when expected first\n");
goto error;
}
while (IS_XSLT_ELEM(replacement) && (IS_XSLT_NAME(replacement, "when"))) {
when = replacement;
prop = xmlGetNsProp(when, (const xmlChar *)"test", XSLT_NAMESPACE);
if (prop == NULL) {
xsltGenericError(xsltGenericErrorContext,
"xsl:when: test is not defined\n");
return;
}
#ifdef DEBUG_PROCESS
xsltGenericDebug(xsltGenericDebugContext,
"xsl:when: test %s\n", prop);
#endif
xpathParserCtxt = xmlXPathNewParserContext(prop, ctxt->xpathCtxt);
if (xpathParserCtxt == NULL)
goto error;
ctxt->xpathCtxt->node = node;
valuePush(xpathParserCtxt, xmlXPathNewNodeSet(node));
xmlXPathEvalExpr(xpathParserCtxt);
xmlXPathBooleanFunction(xpathParserCtxt, 1);
res = valuePop(xpathParserCtxt);
do {
tmp = valuePop(xpathParserCtxt);
if (tmp != NULL) {
xmlXPathFreeObject(tmp);
}
} while (tmp != NULL);
if (res != NULL) {
if (res->type == XPATH_BOOLEAN)
doit = res->boolval;
else {
#ifdef DEBUG_PROCESS
xsltGenericDebug(xsltGenericDebugContext,
"xsl:when: test didn't evaluate to a boolean\n");
#endif
goto error;
}
}
#ifdef DEBUG_PROCESS
xsltGenericDebug(xsltGenericDebugContext,
"xsl:when: test evaluate to %d\n", doit);
#endif
if (doit) {
xsltApplyOneTemplate(ctxt, ctxt->node, when->children);
goto done;
}
if (xpathParserCtxt != NULL)
xmlXPathFreeParserContext(xpathParserCtxt);
xpathParserCtxt = NULL;
if (prop != NULL)
xmlFree(prop);
prop = NULL;
if (res != NULL)
xmlXPathFreeObject(res);
res = NULL;
replacement = replacement->next;
}
if (IS_XSLT_ELEM(replacement) && (IS_XSLT_NAME(replacement, "otherwise"))) {
xsltApplyOneTemplate(ctxt, ctxt->node, replacement->children);
replacement = replacement->next;
}
if (replacement != NULL) {
#ifdef DEBUG_PROCESS
xsltGenericDebug(xsltGenericDebugContext,
"xsl:otherwise: applying default fallback\n");
#endif
xsltGenericError(xsltGenericErrorContext,
"xslt:choose: unexpected content %s\n", replacement->name);
goto error;
}
done:
error:
if (xpathParserCtxt != NULL)
xmlXPathFreeParserContext(xpathParserCtxt);
if (prop != NULL)
xmlFree(prop);
if (res != NULL)
xmlXPathFreeObject(res);
}
/**
* xsltIf:
* @ctxt: a XSLT process context
* @node: the node in the source tree.
......
......@@ -605,6 +605,7 @@
xsltFreeStackElemList(stack->elems[i]);
}
xmlFree(stack);
}
/**
......
<?xml version="1.0"?>
<doc x=""/>
<doc/>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:variable name="x"/>
<xsl:template match="doc">
<doc x="{$x}"/>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<doc x=""/>
<doc/>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:variable name="x" select="''"/>
<xsl:template match="doc">
<doc x="{$x}"/>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
item1
<doc>
<item>item1</item>
<item>item2</item>
<item>item3</item>
</doc>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:variable name="n">2</xsl:variable>
<xsl:template match="doc">
<xsl:value-of select="item[$n]"/>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
item2
<doc>
<item>item1</item>
<item>item2</item>
<item>item3</item>
</doc>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:variable name="n" select="2"/>
<xsl:template match="doc">
<xsl:value-of select="item[$n]"/>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
item2
<doc>
<item>item1</item>
<item>item2</item>
<item>item3</item>
</doc>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:variable name="n">2</xsl:variable>
<xsl:template match="doc">
<xsl:value-of select="item[position()=$n]"/>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<doc value="0"/>
<doc/>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment