fixed an ugly problem with namespaces in templates compilation added a
authorDaniel Veillard <veillard@src.gnome.org>
Wed, 25 Jul 2001 20:20:57 +0000 (20:20 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Wed, 25 Jul 2001 20:20:57 +0000 (20:20 +0000)
* libxslt/pattern.c: fixed an ugly problem with namespaces
  in templates compilation
* tests/namespaces/tst4.*: added a specific testcase
* libxslt/transform.c: reenabled debug
Daniel

ChangeLog
libxslt/pattern.c
libxslt/transform.c
tests/namespaces/tst4.out [new file with mode: 0644]
tests/namespaces/tst4.xml [new file with mode: 0644]
tests/namespaces/tst4.xsl [new file with mode: 0644]

index b27acb7..ffd311b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Jul 26 10:20:19 EDT 2001 Daniel Veillard <daniel@veillard.com>
+
+       * libxslt/pattern.c: fixed an ugly problem with namespaces
+         in templates compilation
+       * tests/namespaces/tst4.*: added a specific testcase
+       * libxslt/transform.c: reenabled debug
+
 Tue Jul 24 17:45:22 CEST 2001 Daniel Veillard <daniel@veillard.com>
 
        * configure.in libxslt.spec.in libxslt/xsltwin32config.h:
index 51346f7..fe7aa20 100644 (file)
@@ -860,7 +860,7 @@ xsltScanLiteral(xsltParserContextPtr ctxt) {
  * xsltScanName:
  * @ctxt:  the XPath Parser context
  *
- * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' |
+ * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | 
  *                  CombiningChar | Extender
  *
  * [5] Name ::= (Letter | '_' | ':') (NameChar)*
@@ -883,7 +883,7 @@ xsltScanName(xsltParserContextPtr ctxt) {
 
     while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
            (NXT(len) == '.') || (NXT(len) == '-') ||
-          (NXT(len) == '_') || (NXT(len) == ':') || 
+          (NXT(len) == '_') || 
           (IS_COMBINING(NXT(len))) ||
           (IS_EXTENDER(NXT(len)))) {
        buf[len] = NXT(len);
@@ -1209,59 +1209,88 @@ xsltCompileStepPattern(xsltParserContextPtr ctxt, xmlChar *token) {
     } else if (CUR == ':') {
        NEXT;
        if (NXT(1) != ':') {
-           xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
-           xsltGenericError(xsltGenericErrorContext,
-                   "xsltCompileStepPattern : sequence '::' expected\n");
-           ctxt->error = 1;
-           goto error;
-       }
-       NEXT;
-       if (xmlStrEqual(token, (const xmlChar *) "child")) {
-           name = xsltScanName(ctxt);
-           if (name == NULL) {
+           xmlChar *prefix = token;
+           xmlNsPtr ns;
+
+           /*
+            * This is a namespace match
+            */
+           token = xsltScanName(ctxt);
+           ns = xmlSearchNs(ctxt->doc, ctxt->elem, prefix);
+           if (ns == NULL) {
                xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
                xsltGenericError(xsltGenericErrorContext,
-                       "xsltCompileStepPattern : QName expected\n");
+           "xsltCompileStepPattern : no namespace bound to prefix %s\n",
+                                prefix);
                ctxt->error = 1;
                goto error;
+           } else {
+               URL = xmlStrdup(ns->href);
            }
-           URI = xsltGetQNameURI(ctxt->elem, &token);
+           xmlFree(prefix);
            if (token == NULL) {
-               ctxt->error = 1;
-               goto error;
+               if (CUR == '*') {
+                   NEXT;
+                   PUSH(XSLT_OP_NS, URL, NULL);
+               } else {
+                   xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
+                   xsltGenericError(xsltGenericErrorContext,
+                           "xsltCompileStepPattern : Name expected\n");
+                   ctxt->error = 1;
+                   goto error;
+               }
            } else {
-               name = xmlStrdup(token);
-               if (URI != NULL)
-                   URL = xmlStrdup(URI);
+               PUSH(XSLT_OP_ELEM, token, URL);
            }
-           PUSH(XSLT_OP_CHILD, name, URL);
-       } else if (xmlStrEqual(token, (const xmlChar *) "attribute")) {
-           name = xsltScanName(ctxt);
-           if (name == NULL) {
+       } else {
+           NEXT;
+           if (xmlStrEqual(token, (const xmlChar *) "child")) {
+               name = xsltScanName(ctxt);
+               if (name == NULL) {
+                   xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
+                   xsltGenericError(xsltGenericErrorContext,
+                           "xsltCompileStepPattern : QName expected\n");
+                   ctxt->error = 1;
+                   goto error;
+               }
+               URI = xsltGetQNameURI(ctxt->elem, &token);
+               if (token == NULL) {
+                   ctxt->error = 1;
+                   goto error;
+               } else {
+                   name = xmlStrdup(token);
+                   if (URI != NULL)
+                       URL = xmlStrdup(URI);
+               }
+               PUSH(XSLT_OP_CHILD, name, URL);
+           } else if (xmlStrEqual(token, (const xmlChar *) "attribute")) {
+               name = xsltScanName(ctxt);
+               if (name == NULL) {
+                   xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
+                   xsltGenericError(xsltGenericErrorContext,
+                           "xsltCompileStepPattern : QName expected\n");
+                   ctxt->error = 1;
+                   goto error;
+               }
+               URI = xsltGetQNameURI(ctxt->elem, &token);
+               if (token == NULL) {
+                   ctxt->error = 1;
+                   goto error;
+               } else {
+                   name = xmlStrdup(token);
+                   if (URI != NULL)
+                       URL = xmlStrdup(URI);
+               }
+               PUSH(XSLT_OP_ATTR, name, URL);
+           } else {
                xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
                xsltGenericError(xsltGenericErrorContext,
-                       "xsltCompileStepPattern : QName expected\n");
+                   "xsltCompileStepPattern : 'child' or 'attribute' expected\n");
                ctxt->error = 1;
                goto error;
            }
-           URI = xsltGetQNameURI(ctxt->elem, &token);
-           if (token == NULL) {
-               ctxt->error = 1;
-               goto error;
-           } else {
-               name = xmlStrdup(token);
-               if (URI != NULL)
-                   URL = xmlStrdup(URI);
-           }
-           PUSH(XSLT_OP_ATTR, name, URL);
-       } else {
-           xsltPrintErrorContext(NULL, NULL, NULL); /* TODO */
-           xsltGenericError(xsltGenericErrorContext,
-               "xsltCompileStepPattern : 'child' or 'attribute' expected\n");
-           ctxt->error = 1;
-           goto error;
+           xmlFree(token);
        }
-       xmlFree(token);
     } else if (CUR == '*') {
        NEXT;
        PUSH(XSLT_OP_ALL, token, NULL);
@@ -1631,7 +1660,6 @@ xsltAddTemplate(xsltStylesheetPtr style, xsltTemplatePtr cur,
         case XSLT_OP_CHILD:
         case XSLT_OP_PARENT:
         case XSLT_OP_ANCESTOR:
-        case XSLT_OP_NS:
            name = pat->steps[0].value;
            break;
         case XSLT_OP_ROOT:
@@ -1642,6 +1670,7 @@ xsltAddTemplate(xsltStylesheetPtr style, xsltTemplatePtr cur,
            break;
         case XSLT_OP_ID:
            /* TODO optimize ID !!! */
+        case XSLT_OP_NS:
         case XSLT_OP_ALL:
            top = (xsltCompMatchPtr *) &(style->elemMatch);
            break;
index 3deecce..7992b9f 100644 (file)
@@ -51,6 +51,7 @@
 
 #ifdef WITH_XSLT_DEBUG
 #define WITH_XSLT_DEBUG_EXTRA
+#define WITH_XSLT_DEBUG_PROCESS
 #endif
 
 int xsltMaxDepth = 500;
diff --git a/tests/namespaces/tst4.out b/tests/namespaces/tst4.out
new file mode 100644 (file)
index 0000000..37ef592
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+
+
+    matched html:* template
+  
+
diff --git a/tests/namespaces/tst4.xml b/tests/namespaces/tst4.xml
new file mode 100644 (file)
index 0000000..86962bf
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version='1.0' encoding="ISO-8859-1"?>
+<?xml-stylesheet href="style.xsl" type="text/xsl"?>
+<dummy xmlns:html="http://www.w3.org/1999/xhtml">
+<html:h1/>
+</dummy>
+
diff --git a/tests/namespaces/tst4.xsl b/tests/namespaces/tst4.xsl
new file mode 100644 (file)
index 0000000..a7b34f8
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:html="http://www.w3.org/1999/xhtml"
+  version="1.0">
+
+  <xsl:template match="/">
+    <xsl:apply-templates/>
+  </xsl:template>
+  
+  <xsl:template match="html:*">
+    matched html:* template
+  </xsl:template>
+
+</xsl:stylesheet>