Mor bug chasing/fixing on DocBook XSL:
authorDaniel Veillard <veillard@src.gnome.org>
Sat, 17 Feb 2001 13:33:31 +0000 (13:33 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Sat, 17 Feb 2001 13:33:31 +0000 (13:33 +0000)
- FEATURES libxslt/attributes.c: fixed use-attribute-sets
- libxslt/xsltutils.c: add carriage return to xsl:message when
  needed
Daniel

ChangeLog
FEATURES
libxslt/attributes.c
libxslt/xsltutils.c

index f6f8240..5163c3e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sat Feb 17 14:27:47 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+       * FEATURES libxslt/attributes.c: fixed use-attribute-sets
+       * libxslt/xsltutils.c: add carriage return to xsl:message when
+         needed
+
 Sat Feb 17 02:25:45 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
        * libxslt/functions.c: fixed a bug with generate-id()
index 48efff4..475e4d5 100644 (file)
--- a/FEATURES
+++ b/FEATURES
@@ -51,7 +51,7 @@ YES                           result-prefix = prefix | "#default"
 
 YES                        xsl:attribute-set
 YES                            name = qname 
-NO                             use-attribute-sets = qnames
+YES                            use-attribute-sets = qnames
 
 YES                        xsl:variable
 YES                            name = qname 
index 6863992..df94b42 100644 (file)
@@ -45,6 +45,8 @@
 #include "templates.h"
 #include "imports.h"
 
+#define DEBUG_ATTRIBUTES
+
 /*
  * TODO: merge attribute sets from different import precedence.
  *       all this should be precomputed just before the transformation
@@ -161,6 +163,62 @@ xsltAddAttrElemList(xsltAttrElemPtr list, xmlNodePtr attr) {
     }
     return(xsltNewAttrElem(attr));
 }
+
+/**
+ * xsltMergeAttrElemList:
+ * @list:  an XSLT AttrElem list
+ * @old:  another XSLT AttrElem list
+ *
+ * Add all the attributes from list @old to list @list,
+ * but drop redefinition of existing values.
+ *
+ * Returns the new list pointer
+ */
+xsltAttrElemPtr
+xsltMergeAttrElemList(xsltAttrElemPtr list, xsltAttrElemPtr old) {
+    xsltAttrElemPtr cur;
+    int add;
+
+    while (old != NULL) {
+
+       /*
+        * Check taht the attribute is not yet in the list
+        */
+       cur = list;
+       add = 1;
+       while (cur != NULL) {
+           if (cur->attr == old->attr) {
+               xsltGenericError(xsltGenericErrorContext,
+            "xslt:attribute-set : use-attribute-sets recursion detected\n");
+               return(list);
+           }
+           if (xmlStrEqual(cur->attr->name, old->attr->name)) {
+               if (cur->attr->ns == old->attr->ns) {
+                   add = 0;
+                   break;
+               }
+               if ((cur->attr->ns != NULL) && (old->attr->ns != NULL) &&
+                   (xmlStrEqual(cur->attr->ns->href, old->attr->ns->href))) {
+                   add = 0;
+                   break;
+               }
+           }
+           if (cur->next == NULL)
+               break;
+            cur = cur->next;
+       }
+
+       if (cur == NULL) {
+           list = xsltNewAttrElem(old->attr);
+       } else if (add) {
+           cur->next = xsltNewAttrElem(old->attr);
+       }
+
+       old = old->next;
+    }
+    return(list);
+}
+
 /************************************************************************
  *                                                                     *
  *                     Module interfaces                               *
@@ -203,8 +261,13 @@ xsltParseStylesheetAttributeSet(xsltStylesheetPtr style, xmlNodePtr cur) {
        prefix = NULL;
     }
 
-    if (style->attributeSets == NULL)
+    if (style->attributeSets == NULL) {
+#ifdef DEBUG_ATTRIBUTES
+       xsltGenericDebug(xsltGenericDebugContext,
+           "creating attribute set table\n");
+#endif
        style->attributeSets = xmlHashCreate(10);
+    }
     if (style->attributeSets == NULL)
        goto error;
 
@@ -223,7 +286,7 @@ xsltParseStylesheetAttributeSet(xsltStylesheetPtr style, xmlNodePtr cur) {
                                 list->name);
                delete = list;
            } else {
-#ifdef DEBUG_PARSING
+#ifdef DEBUG_ATTRIBUTES
                xsltGenericDebug(xsltGenericDebugContext,
                    "add attribute to list %s\n", ncname);
 #endif
@@ -257,11 +320,28 @@ xsltParseStylesheetAttributeSet(xsltStylesheetPtr style, xmlNodePtr cur) {
        while ((*end != 0) && (!IS_BLANK(*end))) end++;
        attribute = xmlStrndup(attribute, end - attribute);
        if (attribute) {
-#ifdef DEBUG_PARSING
+           xmlChar *ncname2 = NULL;
+           xmlChar *prefix2 = NULL;
+           xsltAttrElemPtr values2;
+#ifdef DEBUG_ATTRIBUTES
            xsltGenericDebug(xsltGenericDebugContext,
-               "xslt:attribute-set : %s adds use %s\n", ncname);
+               "xslt:attribute-set : %s adds use %s\n", ncname, attribute);
 #endif
-           TODO /* add use-attribute-sets support to atribute-set */
+           ncname2 = xmlSplitQName2(attribute, &prefix2);
+           if (ncname2 == NULL) {
+               ncname2 = attribute;
+               attribute = NULL;
+               prefix = NULL;
+           }
+           values2 = xmlHashLookup2(style->attributeSets, ncname2, prefix2);
+           values = xsltMergeAttrElemList(values, values2);
+
+           if (attribute != NULL)
+               xmlFree(attribute);
+           if (ncname2 != NULL)
+               xmlFree(ncname2);
+           if (prefix2 != NULL)
+               xmlFree(prefix2);
        }
        attribute = end;
     }
@@ -272,7 +352,7 @@ done:
      * Update the value
      */
     xmlHashUpdateEntry2(style->attributeSets, ncname, prefix, values, NULL);
-#ifdef DEBUG_PARSING
+#ifdef DEBUG_ATTRIBUTES
     xsltGenericDebug(xsltGenericDebugContext,
        "updated attribute list %s\n", ncname);
 #endif
@@ -327,7 +407,7 @@ xsltAttribute(xsltTransformContextPtr ctxt, xmlNodePtr node,
     }
 
     if ((prefix != NULL) && (xmlStrEqual(prefix, (const xmlChar *)"xmlns"))) {
-#ifdef DEBUG_PARSING
+#ifdef DEBUG_ATTRIBUTES
        xsltGenericDebug(xsltGenericDebugContext,
             "xslt:attribute : xmlns prefix forbidden\n");
 #endif
@@ -407,7 +487,7 @@ xsltApplyAttributeSet(xsltTransformContextPtr ctxt, xmlNodePtr node,
        while ((*end != 0) && (!IS_BLANK(*end))) end++;
        attribute = xmlStrndup(attribute, end - attribute);
        if (attribute) {
-#ifdef DEBUG_PARSING
+#ifdef DEBUG_ATTRIBUTES
            xsltGenericDebug(xsltGenericDebugContext,
                "apply attribute set %s\n", attribute);
 #endif
index 0ba29c1..f52de7b 100644 (file)
@@ -121,7 +121,11 @@ xsltMessage(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst) {
     }
     message = xsltEvalTemplateString(ctxt, node, inst);
     if (message != NULL) {
+       int len = xmlStrlen(message);
+
        xsltGenericError(xsltGenericErrorContext, (const char *)message);
+       if ((len > 0) && (message[len - 1] != '\n'))
+           xsltGenericError(xsltGenericErrorContext, "\n");
        xmlFree(message);
     }
     if (terminate)