The add test/debug loop ges on:
authorDaniel Veillard <veillard@src.gnome.org>
Wed, 31 Jan 2001 13:27:40 +0000 (13:27 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Wed, 31 Jan 2001 13:27:40 +0000 (13:27 +0000)
- tests/REC/test-7.*: added more tests
- libxslt/pattern.c libxslt/templates.c libxslt/transform.c:
  fixing bugs raised by said tests
Daniel

13 files changed:
ChangeLog
libxslt/pattern.c
libxslt/templates.c
libxslt/transform.c
tests/REC/test-7.3.out [new file with mode: 0644]
tests/REC/test-7.3.xml [new file with mode: 0644]
tests/REC/test-7.3.xsl [new file with mode: 0644]
tests/REC/test-7.4.out [new file with mode: 0644]
tests/REC/test-7.4.xml [new file with mode: 0644]
tests/REC/test-7.4.xsl [new file with mode: 0644]
tests/REC/test-7.5-1.out [new file with mode: 0644]
tests/REC/test-7.5-1.xml [new file with mode: 0644]
tests/REC/test-7.5-1.xsl [new file with mode: 0644]

index b78c487..4853fb6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jan 31 14:25:25 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+       * tests/REC/test-7.*: added more tests
+       * libxslt/pattern.c libxslt/templates.c libxslt/transform.c:
+         fixing bugs raised by said tests
+
 Tue Jan 30 18:55:49 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
        * tests/REC/test-7.*: added more tests
index 50275d1..8d5556a 100644 (file)
@@ -696,6 +696,8 @@ xsltCompileIdKeyPattern(xsltParserContextPtr ctxt, xmlChar *name, int aid) {
        return;
     }
 error:
+    if (name != NULL)
+       xmlFree(name);
     if (lit != NULL)
        xmlFree(lit);
     if (lit2 != NULL)
@@ -729,6 +731,12 @@ xsltCompileStepPattern(xsltParserContextPtr ctxt, xmlChar *token) {
 
     SKIP_BLANKS;
     if ((token == NULL) && (CUR == '@')) {
+       NEXT;
+       if (CUR == '*') {
+           NEXT;
+           PUSH(XSLT_OP_ATTR, NULL, NULL);
+           return;
+       }
        token = xsltScanName(ctxt);
        if (token == NULL) {
            xsltGenericError(xsltGenericErrorContext,
@@ -908,12 +916,14 @@ xsltCompileLocationPathPattern(xsltParserContextPtr ctxt) {
        }
     } else if (CUR == '*') {
        xsltCompileRelativePathPattern(ctxt, NULL);
+    } else if (CUR == '@') {
+       xsltCompileRelativePathPattern(ctxt, NULL);
     } else {
        xmlChar *name;
        name = xsltScanName(ctxt);
        if (name == NULL) {
            xsltGenericError(xsltGenericErrorContext,
-                   "xsltCompilePattern : Name expected\n");
+                   "xsltCompileLocationPathPattern : Name expected\n");
            ctxt->error = 1;
            return;
        }
index 61d9f4b..8de3a95 100644 (file)
@@ -266,17 +266,17 @@ xsltAttrTemplateProcess(xsltTransformContextPtr ctxt, xmlNodePtr target,
                xsltApplyAttributeSet(ctxt, ctxt->node, NULL, in);
                xmlFree(in);
            }
-           return(NULL);
-
        }
+       return(NULL);
     }
-    /* TODO: check for replacement namespaces */
-
     ret = xmlNewDocProp(ctxt->output, cur->name, NULL);
     if (ret == NULL) return(NULL);
     ret->parent = target;
     
-    ret->ns = xsltGetNamespace(ctxt, cur->parent, cur->ns, target);
+    if (cur->ns != NULL)
+       ret->ns = xsltGetNamespace(ctxt, cur->parent, cur->ns, target);
+    else
+       ret->ns = NULL;
 
     if (cur->children != NULL) {
        xmlChar *in = xmlNodeListGetString(ctxt->doc, cur->children, 1);
index 33c3758..23f30b4 100644 (file)
@@ -125,11 +125,13 @@ xsltCopyNode(xsltTransformContextPtr ctxt, xmlNodePtr node,
     copy->doc = ctxt->output;
     if (copy != NULL) {
        xmlAddChild(insert, copy);
-       /*
-        * Add namespaces as they are needed
-        */
-       if (node->nsDef != NULL)
-           xsltCopyNamespaceList(ctxt, copy, node->nsDef);
+       if (node->type == XML_ELEMENT_NODE) {
+           /*
+            * Add namespaces as they are needed
+            */
+           if (node->nsDef != NULL)
+               xsltCopyNamespaceList(ctxt, copy, node->nsDef);
+       }
        if (node->ns != NULL) {
            copy->ns = xsltGetNamespace(ctxt, node, node->ns, copy);
        }
@@ -362,21 +364,65 @@ void
 xsltCopy(xsltTransformContextPtr ctxt, xmlNodePtr node,
                   xmlNodePtr inst) {
     xmlChar *prop;
-    xmlNodePtr copy;
+    xmlNodePtr copy, oldInsert;
 
-    if ((node->type != XML_DOCUMENT_NODE) &&
-       (node->type != XML_HTML_DOCUMENT_NODE)) {
-       copy = xsltCopyNode(ctxt, node, ctxt->insert);
-       if (node->type == XML_ELEMENT_NODE) {
-           prop = xmlGetNsProp(inst, (const xmlChar *)"use-attribute-sets",
-                               XSLT_NAMESPACE);
-           if (prop != NULL) {
-               TODO /* xsl:copy use-attribute-sets */
+    oldInsert = ctxt->insert;
+    if (ctxt->insert != NULL) {
+       switch (node->type) {
+           case XML_DOCUMENT_NODE:
+           case XML_HTML_DOCUMENT_NODE:
+               break;
+           case XML_ELEMENT_NODE:
+#ifdef DEBUG_PROCESS
+               xsltGenericDebug(xsltGenericDebugContext,
+                                "xsl:copy: node %s\n", node->name);
+#endif
+               copy = xsltCopyNode(ctxt, node, ctxt->insert);
+               ctxt->insert = copy;
+               prop = xmlGetNsProp(inst, (const xmlChar *)"use-attribute-sets",
+                                   XSLT_NAMESPACE);
+               if (prop != NULL) {
+                   xsltApplyAttributeSet(ctxt, node, inst, prop);
+                   xmlFree(prop);
+               }
+               break;
+           case XML_ATTRIBUTE_NODE: {
+#ifdef DEBUG_PROCESS
+               xsltGenericDebug(xsltGenericDebugContext,
+                                "xsl:copy: attribute %s\n", node->name);
+#endif
+               if (ctxt->insert->type == XML_ELEMENT_NODE) {
+                   xmlAttrPtr attr = (xmlAttrPtr) node, ret, cur;
+                   if (attr->ns != NULL) {
+                       if ((!xmlStrEqual(attr->ns->href, XSLT_NAMESPACE)) &&
+                           (xmlStrncasecmp(attr->ns->prefix,
+                                           (xmlChar *)"xml", 3))) {
+                           ret = xmlCopyProp(ctxt->insert, attr);
+                           ret->ns = xsltGetNamespace(ctxt, node, attr->ns,
+                                                      ctxt->insert);
+                       } 
+                   } else
+                       ret = xmlCopyProp(ctxt->insert, attr);
+
+                   cur = ctxt->insert->properties;
+                   if (cur != NULL) {
+                       while (cur->next != NULL)
+                           cur = cur->next;
+                       cur->next = ret;
+                       ret->prev = cur;
+                   }else
+                       ctxt->insert->properties = ret;
+               }
+               break;
            }
+           default:
+               break;
+
        }
     }
 
     xsltApplyOneTemplate(ctxt, ctxt->node, inst->children);
+    ctxt->insert = oldInsert;
 }
 
 /**
@@ -706,6 +752,30 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
                    "xsltDefaultProcessOneNode: text copy failed\n");
            }
            return;
+       case XML_ATTRIBUTE_NODE:
+           if (ctxt->insert->type == XML_ELEMENT_NODE) {
+                   xmlAttrPtr attr = (xmlAttrPtr) node, ret, cur;
+               if (attr->ns != NULL) {
+                   if ((!xmlStrEqual(attr->ns->href, XSLT_NAMESPACE)) &&
+                       (xmlStrncasecmp(attr->ns->prefix,
+                                       (xmlChar *)"xml", 3))) {
+                       ret = xmlCopyProp(ctxt->insert, attr);
+                       ret->ns = xsltGetNamespace(ctxt, node, attr->ns,
+                                                  ctxt->insert);
+                   } 
+               } else
+                   ret = xmlCopyProp(ctxt->insert, attr);
+
+               cur = ctxt->insert->properties;
+               if (cur != NULL) {
+                   while (cur->next != NULL)
+                       cur = cur->next;
+                   cur->next = ret;
+                   ret->prev = cur;
+               }else
+                   ctxt->insert->properties = ret;
+           }
+           return;
        default:
            return;
     }
@@ -1024,6 +1094,7 @@ error:
        xmlXPathFreeNodeSet(list);
 }
 
+
 /**
  * xsltApplyOneTemplate:
  * @ctxt:  a XSLT process context
@@ -1415,14 +1486,34 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
            xsltGenericDebug(xsltGenericDebugContext,
             "xsltProcessOneNode: no template found for %s\n", node->name);
 #endif
+       oldNode = ctxt->node;
+       ctxt->node = node;
        xsltDefaultProcessOneNode(ctxt, node);
+       ctxt->node = oldNode;
        return;
     }
 
-    oldNode = ctxt->node;
-    ctxt->node = node;
-    xsltApplyOneTemplate(ctxt, node, template->content);
-    ctxt->node = oldNode;
+    if (node->type == XML_ATTRIBUTE_NODE) {
+#ifdef DEBUG_PROCESS
+       xsltGenericDebug(xsltGenericDebugContext,
+            "xsltProcessOneNode: applying template for attribute %s\n",
+                        node->name);
+#endif
+       xsltApplyOneTemplate(ctxt, node, template->content);
+    } else {
+#ifdef DEBUG_PROCESS
+       if (node->type == XML_DOCUMENT_NODE)
+           xsltGenericDebug(xsltGenericDebugContext,
+            "xsltProcessOneNode: applying template for /\n");
+       else 
+           xsltGenericDebug(xsltGenericDebugContext,
+            "xsltProcessOneNode: applying template for %s\n", node->name);
+#endif
+       oldNode = ctxt->node;
+       ctxt->node = node;
+       xsltApplyOneTemplate(ctxt, node, template->content);
+       ctxt->node = oldNode;
+    }
 }
 
 /**
diff --git a/tests/REC/test-7.3.out b/tests/REC/test-7.3.out
new file mode 100644 (file)
index 0000000..923fbfa
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<doc><?xml-stylesheet href="book.css" type="text/css"?></doc>
diff --git a/tests/REC/test-7.3.xml b/tests/REC/test-7.3.xml
new file mode 100644 (file)
index 0000000..636923c
--- /dev/null
@@ -0,0 +1,2 @@
+<doc>
+</doc>
diff --git a/tests/REC/test-7.3.xsl b/tests/REC/test-7.3.xsl
new file mode 100644 (file)
index 0000000..3f699f1
--- /dev/null
@@ -0,0 +1,15 @@
+<xsl:stylesheet
+  version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:fo="http://www.w3.org/1999/XSL/Format"
+  xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias">
+
+<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
+
+<xsl:template match="doc">
+<doc>
+<xsl:processing-instruction name="xml-stylesheet">href="book.css" type="text/css"</xsl:processing-instruction>
+</doc>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/REC/test-7.4.out b/tests/REC/test-7.4.out
new file mode 100644 (file)
index 0000000..cf037f2
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<doc><!--This file is automatically generated. Do not edit!--></doc>
diff --git a/tests/REC/test-7.4.xml b/tests/REC/test-7.4.xml
new file mode 100644 (file)
index 0000000..636923c
--- /dev/null
@@ -0,0 +1,2 @@
+<doc>
+</doc>
diff --git a/tests/REC/test-7.4.xsl b/tests/REC/test-7.4.xsl
new file mode 100644 (file)
index 0000000..8059473
--- /dev/null
@@ -0,0 +1,15 @@
+<xsl:stylesheet
+  version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:fo="http://www.w3.org/1999/XSL/Format"
+  xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias">
+
+<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
+
+<xsl:template match="doc">
+<doc>
+<xsl:comment>This file is automatically generated. Do not edit!</xsl:comment>
+</doc>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/REC/test-7.5-1.out b/tests/REC/test-7.5-1.out
new file mode 100644 (file)
index 0000000..450c3f1
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<doc attr="value">
+    <child attr1="val" attr2="val2">content</child>
+</doc>
diff --git a/tests/REC/test-7.5-1.xml b/tests/REC/test-7.5-1.xml
new file mode 100644 (file)
index 0000000..f3a0c0a
--- /dev/null
@@ -0,0 +1,3 @@
+<doc attr="value">
+    <child attr1="val" attr2="val2">content</child>
+</doc>
diff --git a/tests/REC/test-7.5-1.xsl b/tests/REC/test-7.5-1.xsl
new file mode 100644 (file)
index 0000000..b832f5f
--- /dev/null
@@ -0,0 +1,12 @@
+<xsl:stylesheet
+  version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:fo="http://www.w3.org/1999/XSL/Format"
+  xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias">
+
+<xsl:template match="@*|node()">
+  <xsl:copy>
+    <xsl:apply-templates select="@*|node()"/>
+  </xsl:copy>
+</xsl:template>
+</xsl:stylesheet>