# HG changeset patch
# User Daniel Veillard <veillard@src.gnome.org>
# Date 980075222 0
#      Sun Jan 21 11:07:02 2001 +0000
# Node ID a9147c4f0c91ec1ca8c61fc956df382e6cafb330
# Parent  96ed246c7e7da2540cd70b1205c31e900fe7ce42
More work, cleanups, HTML output:
- Makefile.am tests/Makefile.am tests/REC1/Makefile.am
  tests/REC2/Makefile.am tests/REC2/html.xml: added tests target
  too, added the HTML output test
- libxmls/xsltutils.c: added HTML output
- libxslt/xslt.c: check version on literal result used as templates
- libxslt/transform.c: fixed an error in VERSION number
- libxslt/templates.c: make sure generated nodes have doc and
  parent properly set
Daniel

diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Sun Jan 21 12:03:16 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+	* Makefile.am tests/Makefile.am tests/REC1/Makefile.am
+	  tests/REC2/Makefile.am tests/REC2/html.xml: added tests target
+	  too, added the HTML output test
+	* libxmls/xsltutils.c: added HTML output
+	* libxslt/xslt.c: check version on literal result used as templates
+	* libxslt/transform.c: fixed an error in VERSION number
+	* libxslt/templates.c: make sure generated nodes have doc and
+	  parent properly set
+
 Sat Jan 20 23:35:07 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
 	* libxslt/Makefile.am libxslt/template.[ch]: added a template
diff --git a/Makefile.am b/Makefile.am
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,7 +24,7 @@
 	       < $(srcdir)/xsltConf.sh.in > xsltConf.tmp \
 	&& mv xsltConf.tmp xsltConf.sh
 
-test:
+test tests:
 	@(cd tests ; make test)
 
 
diff --git a/libxslt/templates.c b/libxslt/templates.c
--- a/libxslt/templates.c
+++ b/libxslt/templates.c
@@ -202,8 +202,11 @@
 	xmlChar *out;
 
 	if (in != NULL) {
+	    xmlNodePtr child;
+
             out = xsltAttrTemplateValueProcess(ctxt, in);
-	    ret->children = xmlNewDocText(ctxt->output, out);
+	    child = xmlNewDocText(ctxt->output, out);
+	    xmlAddChild((xmlNodePtr) ret, child);
 	    xmlFree(out);
 	    xmlFree(in);
 	} else
@@ -233,12 +236,16 @@
 
     while (cur != NULL) {
         q = xsltAttrTemplateProcess(ctxt, target, cur);
-	if (p == NULL) {
-	    ret = p = q;
-	} else {
-	    p->next = q;
-	    q->prev = p;
-	    p = q;
+	if (q != NULL) {
+	    q->parent = target;
+	    q->doc = ctxt->output;
+	    if (p == NULL) {
+		ret = p = q;
+	    } else {
+		p->next = q;
+		q->prev = p;
+		p = q;
+	    }
 	}
 	cur = cur->next;
     }
diff --git a/libxslt/transform.c b/libxslt/transform.c
--- a/libxslt/transform.c
+++ b/libxslt/transform.c
@@ -294,7 +294,7 @@
     value = xmlNodeListGetString(inst->doc, inst->children, 1);
     if (value == NULL) {
 	if (ns) {
-#if LIBXML_VERSION > 202111
+#if LIBXML_VERSION > 20211
 	    attr = xmlSetNsProp(ctxt->insert, ncname, ns->href,
 		                (const xmlChar *)"");
 #else
@@ -316,6 +316,7 @@
 #endif
 	} else
 	    attr = xmlSetProp(ctxt->insert, ncname, value);
+	
     }
 
 error:
diff --git a/libxslt/xslt.c b/libxslt/xslt.c
--- a/libxslt/xslt.c
+++ b/libxslt/xslt.c
@@ -866,7 +866,11 @@
 		"xsltParseStylesheetDoc : document is stylesheet\n");
 #endif
 	
-	/* TODO: check the version */
+	if (!xmlStrEqual(prop, (const xmlChar *)"1.0")) {
+	    xsltGenericError(xsltGenericErrorContext,
+		"xsl:version: only 1.0 features are supported\n");
+	    TODO /* set up compatibility when not XSLT 1.0 */
+	}
 	xmlFree(prop);
 
 	/*
diff --git a/libxslt/xsltutils.c b/libxslt/xsltutils.c
--- a/libxslt/xsltutils.c
+++ b/libxslt/xsltutils.c
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 
+#include <libxml/xmlversion.h>
 #include <libxml/xmlmemory.h>
 #include <libxml/tree.h>
 #include <libxml/xmlerror.h>
@@ -198,6 +199,7 @@
 xsltSaveResultTo(xmlOutputBufferPtr buf, xmlDocPtr result,
 	       xsltStylesheetPtr style) {
     const xmlChar *encoding;
+    xmlNodePtr root;
     int base;
 
     if ((buf == NULL) || (result == NULL) || (style == NULL))
@@ -212,9 +214,22 @@
     /* TODO: when outputing and having imported stylesheets, apply cascade */
     base = buf->written;
     encoding = style->encoding;
-    if (xmlStrEqual(style->method, (const xmlChar *) "html")) {
-	TODO /* HTML dump ... */
-    } else if (xmlStrEqual(style->method, (const xmlChar *) "text")) {
+    if (style->method == NULL)
+	root = xmlDocGetRootElement(result);
+    else
+	root = NULL;
+    if (((style->method != NULL) &&
+	 (xmlStrEqual(style->method, (const xmlChar *) "html"))) ||
+	((root != NULL) &&
+	 (xmlStrEqual(root->name, (const xmlChar *) "html")))){
+#if LIBXML_VERSION > 20211
+	htmlDocContentDumpOutput(buf, result, (const char *) encoding);
+#else
+	xsltGenericError(xsltGenericErrorContext,
+		"HTML output requires libxml version > 2.2.11\n");
+#endif
+    } else if ((style->method != NULL) &&
+	       (xmlStrEqual(style->method, (const xmlChar *) "text"))) {
 	xmlNodePtr cur;
 
 	cur = result->children;
@@ -258,7 +273,7 @@
 	    xmlNodePtr child = result->children;
 
 	    while (child != NULL) {
-		xmlNodeDumpOutput(buf, result, child, 0, style->indent,
+		xmlNodeDumpOutput(buf, result, child, 0, (style->indent == 1),
 			          (const char *) encoding);
 		xmlOutputBufferWriteString(buf, "\n");
 		child = child->next;
diff --git a/tests/Makefile.am b/tests/Makefile.am
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,6 +18,6 @@
 #testevents_DEPENDENCIES = $(DEPS)
 #testevents_LDADD = $(LDADDS)
 
-test: $(top_builddir)/libxslt/xsltproc
+test tests: $(top_builddir)/libxslt/xsltproc
 	@(cd REC1 ; make test)
 	@(cd REC2 ; make test)
diff --git a/tests/REC1/Makefile.am b/tests/REC1/Makefile.am
--- a/tests/REC1/Makefile.am
+++ b/tests/REC1/Makefile.am
@@ -3,7 +3,7 @@
 $(top_builddir)/libxslt/xsltproc:
 	@(cd ../../libxslt ; make xsltproc)
 
-test: $(top_builddir)/libxslt/xsltproc
+test tests: $(top_builddir)/libxslt/xsltproc
 	@(rm -f .memdump ; touch .memdump)
 	@($(top_builddir)/libxslt/xsltproc doc.xsl doc.xml > doc.res ; \
 	diff result.xml doc.res ; \
diff --git a/tests/REC2/Makefile.am b/tests/REC2/Makefile.am
--- a/tests/REC2/Makefile.am
+++ b/tests/REC2/Makefile.am
@@ -3,7 +3,7 @@
 $(top_builddir)/libxslt/xsltproc:
 	@(cd ../../libxslt ; make xsltproc)
 
-test: $(top_builddir)/libxslt/xsltproc
+test tests: $(top_builddir)/libxslt/xsltproc
 	@(rm -f .memdump ; touch .memdump)
 	@($(top_builddir)/libxslt/xsltproc vrml.xsl data.xml > vrml.res ; \
 	diff vrml.xml vrml.res ; \
@@ -13,5 +13,9 @@
 	diff svg.xml svg.res ; \
 	grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0";\
 	rm -f svg.res)
+	@($(top_builddir)/libxslt/xsltproc html.xsl data.xml > html.res ; \
+	diff html.xml html.res ; \
+	grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0";\
+	rm -f html.res)
 
 
diff --git a/tests/REC2/html.xml b/tests/REC2/html.xml
--- a/tests/REC2/html.xml
+++ b/tests/REC2/html.xml
@@ -1,22 +1,29 @@
-<html lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-<title>Sales Results By Division</title>
-</head>
-<body>
-<table border="1">
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html lang="en">
+<head><title>Sales Results By Division</title></head>
+<body><table border="1">
 <tr>
-<th>Division</th><th>Revenue</th><th>Growth</th><th>Bonus</th>
+<th>Division</th>
+<th>Revenue</th>
+<th>Growth</th>
+<th>Bonus</th>
 </tr>
 <tr>
-<td><em>North</em></td><td>10</td><td>9</td><td>7</td>
-</tr>
-<tr>
-<td><em>West</em></td><td>6</td><td style="color:red">-1.5</td><td>2</td>
+<td><em>West</em></td>
+<td>6</td>
+<td style="color:red">-1.5</td>
+<td>2</td>
 </tr>
 <tr>
-<td><em>South</em></td><td>4</td><td>3</td><td>4</td>
+<td><em>South</em></td>
+<td>4</td>
+<td>3</td>
+<td>4</td>
 </tr>
-</table>
-</body>
+<tr>
+<td><em>North</em></td>
+<td>10</td>
+<td>9</td>
+<td>7</td>
+</tr>
+</table></body>
 </html>