Testing/debugging: - tests/REC/test-7.*: added more tests -
authorDaniel Veillard <veillard@src.gnome.org>
Tue, 30 Jan 2001 18:00:24 +0000 (18:00 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Tue, 30 Jan 2001 18:00:24 +0000 (18:00 +0000)
Testing/debugging:
- tests/REC/test-7.*: added more tests
- libxslt/namespaces.[ch] libxslt/pattern.c libxslt/attributes.c
  libxslt/templates.c libxslt/transform.c libxslt/xslt.c: fixing bugs
  raised by said tests
Daniel

17 files changed:
ChangeLog
libxslt/attributes.c
libxslt/namespaces.c
libxslt/namespaces.h
libxslt/pattern.c
libxslt/templates.c
libxslt/transform.c
libxslt/xslt.c
tests/REC/test-7.1.1.out [new file with mode: 0644]
tests/REC/test-7.1.1.xml [new file with mode: 0644]
tests/REC/test-7.1.1.xsl [new file with mode: 0644]
tests/REC/test-7.1.3.out [new file with mode: 0644]
tests/REC/test-7.1.3.xml [new file with mode: 0644]
tests/REC/test-7.1.3.xsl [new file with mode: 0644]
tests/REC/test-7.1.4.out [new file with mode: 0644]
tests/REC/test-7.1.4.xml [new file with mode: 0644]
tests/REC/test-7.1.4.xsl [new file with mode: 0644]

index a66f0fd..b78c487 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Jan 30 18:55:49 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+       * tests/REC/test-7.*: added more tests
+       * libxslt/namespaces.[ch] libxslt/pattern.c libxslt/attributes.c
+         libxslt/templates.c libxslt/transform.c libxslt/xslt.c: fixing bugs
+         raised by said tests
+
 Tue Jan 30 15:16:56 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
        * TODO: updated
index 3bafd1c..ac54dcb 100644 (file)
@@ -207,23 +207,23 @@ xsltParseStylesheetAttributeSet(xsltStylesheetPtr style, xmlNodePtr cur) {
     list = cur->children;
     delete = NULL;
     while (list != NULL) {
-       if (IS_XSLT_ELEM(cur)) {
-           if (!IS_XSLT_NAME(cur, "attribute")) {
+       if (IS_XSLT_ELEM(list)) {
+           if (!IS_XSLT_NAME(list, "attribute")) {
                xsltGenericError(xsltGenericErrorContext,
                    "xslt:attribute-set : unexpected child xsl:%s\n",
-                                cur->name);
-               delete = cur;
+                                list->name);
+               delete = list;
            } else {
 #ifdef DEBUG_PARSING
                xsltGenericDebug(xsltGenericDebugContext,
                    "add attribute to list %s\n", ncname);
 #endif
-                values = xsltAddAttrElemList(values, cur);
+                values = xsltAddAttrElemList(values, list);
            }
        } else {
            xsltGenericError(xsltGenericErrorContext,
-               "xslt:attribute-set : unexpected child %s\n", cur->name);
-           delete = cur;
+               "xslt:attribute-set : unexpected child %s\n", list->name);
+           delete = list;
        }
        list = list->next;
     }
@@ -316,16 +316,16 @@ xsltAttribute(xsltTransformContextPtr ctxt, xmlNodePtr node,
        prop = NULL;
        prefix = NULL;
     }
-    if (xmlStrEqual(ncname, (const xmlChar *) "xmlns")) {
-       xsltGenericError(xsltGenericErrorContext,
-            "xslt:attribute : xmlns forbidden\n");
+    if ((prefix != NULL) && (xmlStrEqual(prefix, (const xmlChar *)"xmlns"))) {
+#ifdef DEBUG_PARSING
+           xsltGenericDebug(xsltGenericDebugContext,
+                "xslt:attribute : xmlns prefix forbidden\n");
+#endif
        goto error;
     }
     prop = xsltEvalAttrValueTemplate(ctxt, inst, (const xmlChar *)"namespace");
     if (prop != NULL) {
        TODO /* xsl:attribute namespace */
-       xmlFree(prop);
-       return;
     } else {
        if (prefix != NULL) {
            ns = xmlSearchNs(inst->doc, inst, prefix);
index 9842453..384836d 100644 (file)
@@ -139,11 +139,6 @@ xsltGetNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur, xmlNsPtr ns,
 
     if ((ctxt == NULL) || (cur == NULL) || (out == NULL) || (ns == NULL))
        return(NULL);
-    if ((out->type == XML_ELEMENT_NODE) && (out->ns != NULL) &&
-        ((out->ns->href != NULL) && (ns->href != NULL) &&
-         (xmlStrEqual(out->ns->href, ns->href)))) {
-       return(out->ns);
-    }
 
     /* TODO apply cascading */
     if (ctxt->style->nsAliases != NULL) {
@@ -153,10 +148,17 @@ xsltGetNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur, xmlNsPtr ns,
     } else
        URI = ns->href;
 
-    ret = xmlSearchNsByHref(out->doc, out, URI);
+    if ((out->parent != NULL) &&
+       (out->parent->type == XML_ELEMENT_NODE) &&
+       (out->parent->ns != NULL) &&
+       (xmlStrEqual(out->parent->ns->href, URI)))
+       ret = out->parent->ns;
+    else
+       ret = xmlSearchNsByHref(out->doc, out, URI);
+
     if (ret == NULL) {
        if (out->type == XML_ELEMENT_NODE)
-           ret = xmlNewNs(out, ns->href, ns->prefix);
+           ret = xmlNewNs(out, URI, ns->prefix);
     }
     return(ret);
 }
@@ -202,3 +204,16 @@ xsltCopyNamespaceList(xsltTransformContextPtr ctxt, xmlNodePtr node,
     return(ret);
 }
 
+
+/**
+ * xsltFreeNamespaceAliasHashes:
+ * @style: an XSLT stylesheet
+ *
+ * Free up the memory used by namespaces aliases
+ */
+void
+xsltFreeNamespaceAliasHashes(xsltStylesheetPtr style) {
+    if (style->nsAliases != NULL)
+       xmlHashFree((xmlHashTablePtr) style->nsAliases, NULL);
+    style->nsAliases = NULL;
+}
index 14c2f4d..a4158a8 100644 (file)
@@ -24,6 +24,7 @@ xmlNsPtr      xsltGetNamespace        (xsltTransformContextPtr ctxt,
 xmlNsPtr       xsltCopyNamespaceList   (xsltTransformContextPtr ctxt,
                                         xmlNodePtr node,
                                         xmlNsPtr cur);
+void           xsltFreeNamespaceAliasHashes(xsltStylesheetPtr style);
 #ifdef __cplusplus
 }
 #endif
index 2c4129c..50275d1 100644 (file)
@@ -1263,7 +1263,7 @@ xsltGetTemplate(xsltStylesheetPtr style, xmlNodePtr node) {
            case XML_NAMESPACE_DECL:
            case XML_XINCLUDE_START:
            case XML_XINCLUDE_END:
-               return(NULL);
+               break;
            default:
                return(NULL);
 
index 66d6e40..61d9f4b 100644 (file)
@@ -26,6 +26,7 @@
 #include "templates.h"
 #include "transform.h"
 #include "namespaces.h"
+#include "attributes.h"
 
 #define DEBUG_TEMPLATES
 
@@ -257,9 +258,19 @@ xsltAttrTemplateProcess(xsltTransformContextPtr ctxt, xmlNodePtr target,
 
     if ((cur->ns != NULL) &&
        (xmlStrEqual(cur->ns->href, XSLT_NAMESPACE))) {
-       /* TODO: check for replacement namespaces */
-       return(NULL);
+       if (xmlStrEqual(cur->name, (const xmlChar *)"use-attribute-sets")) {
+           xmlChar *in;
+
+           in = xmlNodeListGetString(ctxt->doc, cur->children, 1);
+           if (in != NULL) {
+               xsltApplyAttributeSet(ctxt, ctxt->node, NULL, in);
+               xmlFree(in);
+           }
+           return(NULL);
+
+       }
     }
+    /* TODO: check for replacement namespaces */
 
     ret = xmlNewDocProp(ctxt->output, cur->name, NULL);
     if (ret == NULL) return(NULL);
@@ -304,7 +315,10 @@ xsltAttrListTemplateProcess(xsltTransformContextPtr ctxt,
                            xmlNodePtr target, xmlAttrPtr cur) {
     xmlAttrPtr ret = NULL;
     xmlAttrPtr p = NULL,q;
+    xmlNodePtr oldInsert;
 
+    oldInsert = ctxt->insert;
+    ctxt->insert = target;
     while (cur != NULL) {
         q = xsltAttrTemplateProcess(ctxt, target, cur);
        if (q != NULL) {
@@ -320,6 +334,7 @@ xsltAttrListTemplateProcess(xsltTransformContextPtr ctxt,
        }
        cur = cur->next;
     }
+    ctxt->insert = oldInsert;
     return(ret);
 }
 
index 96e1884..33c3758 100644 (file)
@@ -31,6 +31,7 @@
 #include "transform.h"
 #include "variables.h"
 #include "namespaces.h"
+#include "attributes.h"
 #include "templates.h"
 
 #define DEBUG_PROCESS
@@ -1036,6 +1037,7 @@ xsltApplyOneTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
                     xmlNodePtr list) {
     xmlNodePtr cur = NULL, insert, copy = NULL;
     xmlNodePtr oldInsert;
+    xmlAttrPtr attrs;
     int has_variables = 0;
 
     CHECK_STOPPED;
@@ -1153,11 +1155,18 @@ xsltApplyOneTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
            copy = xsltCopyNode(ctxt, cur, insert);
            /*
             * all the attributes are directly inherited
-            * TODO: Do the substitution of {} XPath expressions !!!
             */
-           if (cur->properties != NULL)
-               copy->properties = xsltAttrListTemplateProcess(ctxt,
-                                              copy, cur->properties);
+           if (cur->properties != NULL) {
+               attrs = xsltAttrListTemplateProcess(ctxt, copy,
+                                                   cur->properties);
+               if (copy->properties != NULL) {
+                   xmlAttrPtr cur = copy->properties;
+                   while (cur->next != NULL)
+                       cur = cur->next;
+                   cur->next = attrs;
+               } else
+                   copy->properties = attrs;
+           }
        }
 
        /*
@@ -1391,6 +1400,7 @@ error:
 void
 xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
     xsltTemplatePtr template;
+    xmlNodePtr oldNode;
 
     template = xsltGetTemplate(ctxt->style, node);
     /*
@@ -1409,7 +1419,10 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
        return;
     }
 
+    oldNode = ctxt->node;
+    ctxt->node = node;
     xsltApplyOneTemplate(ctxt, node, template->content);
+    ctxt->node = oldNode;
 }
 
 /**
index c75ace4..3154d8d 100644 (file)
@@ -264,6 +264,7 @@ xsltFreeStylesheet(xsltStylesheetPtr sheet) {
     xsltFreeDecimalFormatList(sheet);
     xsltFreeTemplateList(sheet->templates);
     xsltFreeAttributeSetsHashes(sheet);
+    xsltFreeNamespaceAliasHashes(sheet);
     if (sheet->doc != NULL)
        xmlFreeDoc(sheet->doc);
     if (sheet->variables != NULL)
diff --git a/tests/REC/test-7.1.1.out b/tests/REC/test-7.1.1.out
new file mode 100644 (file)
index 0000000..f21cf90
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<axsl:stylesheet xmlns:axsl="http://www.w3.org/1999/XSL/Transform">
+<axsl:template match="p"><fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"><axsl:apply-templates/></fo:block></axsl:template>
+<axsl:template match="h1"><fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"><axsl:apply-templates/></fo:block></axsl:template>
+<axsl:template match="h2"><fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"><axsl:apply-templates/></fo:block></axsl:template>
+<axsl:template match="h3"><fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"><axsl:apply-templates/></fo:block></axsl:template>
+<axsl:template match="h4"><fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"><axsl:apply-templates/></fo:block></axsl:template>
+</axsl:stylesheet>
diff --git a/tests/REC/test-7.1.1.xml b/tests/REC/test-7.1.1.xml
new file mode 100644 (file)
index 0000000..d88b575
--- /dev/null
@@ -0,0 +1,7 @@
+<elements>
+<block>p</block>
+<block>h1</block>
+<block>h2</block>
+<block>h3</block>
+<block>h4</block>
+</elements>
diff --git a/tests/REC/test-7.1.1.xsl b/tests/REC/test-7.1.1.xsl
new file mode 100644 (file)
index 0000000..10cc935
--- /dev/null
@@ -0,0 +1,21 @@
+<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="/">
+  <axsl:stylesheet>
+    <xsl:apply-templates/>
+  </axsl:stylesheet>
+</xsl:template>
+
+<xsl:template match="block">
+  <axsl:template match="{.}">
+     <fo:block><axsl:apply-templates/></fo:block>
+  </axsl:template>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/REC/test-7.1.3.out b/tests/REC/test-7.1.3.out
new file mode 100644 (file)
index 0000000..dee0832
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<doc attr="value"/>
diff --git a/tests/REC/test-7.1.3.xml b/tests/REC/test-7.1.3.xml
new file mode 100644 (file)
index 0000000..69d62f2
--- /dev/null
@@ -0,0 +1 @@
+<doc/>
diff --git a/tests/REC/test-7.1.3.xsl b/tests/REC/test-7.1.3.xsl
new file mode 100644 (file)
index 0000000..e54f6f3
--- /dev/null
@@ -0,0 +1,20 @@
+<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:attribute name="xmlns:xsl" namespace="whatever">http://www.w3.org/1999/XSL/Transform</xsl:attribute>
+<xsl:attribute name="attr">value</xsl:attribute>
+<!--
+<xsl:attribute name="a">x
+y</xsl:attribute>
+-->
+</doc>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/REC/test-7.1.4.out b/tests/REC/test-7.1.4.out
new file mode 100644 (file)
index 0000000..e210ef3
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+
+
+
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format" font-size="12pt" font-weight="bold" quadding="start">this is the heading</fo:block>
+
+
+
diff --git a/tests/REC/test-7.1.4.xml b/tests/REC/test-7.1.4.xml
new file mode 100644 (file)
index 0000000..50ab16a
--- /dev/null
@@ -0,0 +1,5 @@
+<doc>
+<chapter>
+<heading>this is the heading</heading>
+</chapter>
+</doc>
diff --git a/tests/REC/test-7.1.4.xsl b/tests/REC/test-7.1.4.xsl
new file mode 100644 (file)
index 0000000..88c61b9
--- /dev/null
@@ -0,0 +1,19 @@
+<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="chapter/heading">
+  <fo:block quadding="start" xsl:use-attribute-sets="title-style">
+    <xsl:apply-templates/>
+  </fo:block>
+</xsl:template>
+
+<xsl:attribute-set name="title-style">
+  <xsl:attribute name="font-size">12pt</xsl:attribute>
+  <xsl:attribute name="font-weight">bold</xsl:attribute>
+</xsl:attribute-set>
+</xsl:stylesheet>