No sleep :-(, still stuck in (test/debug/patch) loop:
authorDaniel Veillard <veillard@src.gnome.org>
Thu, 1 Feb 2001 04:38:30 +0000 (04:38 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Thu, 1 Feb 2001 04:38:30 +0000 (04:38 +0000)
- tests/REC/test-11*: added more tests
- libxslt/transform.c libxslt/variables.c: fixing bugs raised by
  said tests
Daniel

21 files changed:
ChangeLog
libxslt/transform.c
libxslt/variables.c
tests/REC/test-11.2-1.out [new file with mode: 0644]
tests/REC/test-11.2-1.xml [new file with mode: 0644]
tests/REC/test-11.2-1.xsl [new file with mode: 0644]
tests/REC/test-11.2-2.out [new file with mode: 0644]
tests/REC/test-11.2-2.xml [new file with mode: 0644]
tests/REC/test-11.2-2.xsl [new file with mode: 0644]
tests/REC/test-11.2-3.out [new file with mode: 0644]
tests/REC/test-11.2-3.xml [new file with mode: 0644]
tests/REC/test-11.2-3.xsl [new file with mode: 0644]
tests/REC/test-11.2-4.out [new file with mode: 0644]
tests/REC/test-11.2-4.xml [new file with mode: 0644]
tests/REC/test-11.2-4.xsl [new file with mode: 0644]
tests/REC/test-11.2-5.out [new file with mode: 0644]
tests/REC/test-11.2-5.xml [new file with mode: 0644]
tests/REC/test-11.2-5.xsl [new file with mode: 0644]
tests/REC/test-11.2-6.out [new file with mode: 0644]
tests/REC/test-11.2-6.xml [new file with mode: 0644]
tests/REC/test-11.2-6.xsl [new file with mode: 0644]

index b0c23ab..03c2c6b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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
index 12cde9a..0892957 100644 (file)
@@ -1312,6 +1312,125 @@ skip_children:
 }
 
 /**
+ * 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.
index d463ba9..c3aab76 100644 (file)
@@ -605,6 +605,7 @@ xsltFreeVariableHashes(xsltTransformContextPtr ctxt) {
        xsltFreeStackElemList(stack->elems[i]);
     }
     xmlFree(stack);
+
 }
 
 /**
diff --git a/tests/REC/test-11.2-1.out b/tests/REC/test-11.2-1.out
new file mode 100644 (file)
index 0000000..661cc07
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<doc x=""/>
diff --git a/tests/REC/test-11.2-1.xml b/tests/REC/test-11.2-1.xml
new file mode 100644 (file)
index 0000000..69d62f2
--- /dev/null
@@ -0,0 +1 @@
+<doc/>
diff --git a/tests/REC/test-11.2-1.xsl b/tests/REC/test-11.2-1.xsl
new file mode 100644 (file)
index 0000000..b2a0c99
--- /dev/null
@@ -0,0 +1,11 @@
+<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>
diff --git a/tests/REC/test-11.2-2.out b/tests/REC/test-11.2-2.out
new file mode 100644 (file)
index 0000000..661cc07
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<doc x=""/>
diff --git a/tests/REC/test-11.2-2.xml b/tests/REC/test-11.2-2.xml
new file mode 100644 (file)
index 0000000..69d62f2
--- /dev/null
@@ -0,0 +1 @@
+<doc/>
diff --git a/tests/REC/test-11.2-2.xsl b/tests/REC/test-11.2-2.xsl
new file mode 100644 (file)
index 0000000..b631a96
--- /dev/null
@@ -0,0 +1,11 @@
+<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>
diff --git a/tests/REC/test-11.2-3.out b/tests/REC/test-11.2-3.out
new file mode 100644 (file)
index 0000000..ba5c563
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+item1
diff --git a/tests/REC/test-11.2-3.xml b/tests/REC/test-11.2-3.xml
new file mode 100644 (file)
index 0000000..380664c
--- /dev/null
@@ -0,0 +1,5 @@
+<doc>
+<item>item1</item>
+<item>item2</item>
+<item>item3</item>
+</doc>
diff --git a/tests/REC/test-11.2-3.xsl b/tests/REC/test-11.2-3.xsl
new file mode 100644 (file)
index 0000000..c41aac6
--- /dev/null
@@ -0,0 +1,11 @@
+<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>
diff --git a/tests/REC/test-11.2-4.out b/tests/REC/test-11.2-4.out
new file mode 100644 (file)
index 0000000..23d6d82
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+item2
diff --git a/tests/REC/test-11.2-4.xml b/tests/REC/test-11.2-4.xml
new file mode 100644 (file)
index 0000000..380664c
--- /dev/null
@@ -0,0 +1,5 @@
+<doc>
+<item>item1</item>
+<item>item2</item>
+<item>item3</item>
+</doc>
diff --git a/tests/REC/test-11.2-4.xsl b/tests/REC/test-11.2-4.xsl
new file mode 100644 (file)
index 0000000..27c37d2
--- /dev/null
@@ -0,0 +1,11 @@
+<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>
diff --git a/tests/REC/test-11.2-5.out b/tests/REC/test-11.2-5.out
new file mode 100644 (file)
index 0000000..23d6d82
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+item2
diff --git a/tests/REC/test-11.2-5.xml b/tests/REC/test-11.2-5.xml
new file mode 100644 (file)
index 0000000..380664c
--- /dev/null
@@ -0,0 +1,5 @@
+<doc>
+<item>item1</item>
+<item>item2</item>
+<item>item3</item>
+</doc>
diff --git a/tests/REC/test-11.2-5.xsl b/tests/REC/test-11.2-5.xsl
new file mode 100644 (file)
index 0000000..876c0ef
--- /dev/null
@@ -0,0 +1,11 @@
+<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>
diff --git a/tests/REC/test-11.2-6.out b/tests/REC/test-11.2-6.out
new file mode 100644 (file)
index 0000000..e62488f
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<doc value="0"/>
diff --git a/tests/REC/test-11.2-6.xml b/tests/REC/test-11.2-6.xml
new file mode 100644 (file)
index 0000000..69d62f2
--- /dev/null
@@ -0,0 +1 @@
+<doc/>
diff --git a/tests/REC/test-11.2-6.xsl b/tests/REC/test-11.2-6.xsl
new file mode 100644 (file)
index 0000000..db59e1d
--- /dev/null
@@ -0,0 +1,11 @@
+<xsl:stylesheet version="1.0"
+      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+      xmlns:fo="http://www.w3.org/1999/XSL/Format">
+
+<xsl:param name="x" select="/.."/>
+
+<xsl:template match="doc">
+<doc value="{count($x)}"/>
+</xsl:template>
+
+</xsl:stylesheet>