- libxslt/pattern.c : trying to fix #55670
authorDaniel Veillard <veillard@src.gnome.org>
Tue, 5 Jun 2001 15:08:14 +0000 (15:08 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Tue, 5 Jun 2001 15:08:14 +0000 (15:08 +0000)
- tests/XSLTMark/reverser.out : result of test changed when
  William fixed XPath
Daniel

ChangeLog
libxslt/pattern.c
tests/XSLTMark/reverser.out

index b833822..dd5c49a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jun  6 11:07:50 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+       * libxslt/pattern.c : trying to fix #55670
+       * tests/XSLTMark/reverser.out : result of test changed when
+         William fixed XPath
+
 Sat Jun  2 06:52:12 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
        * doc/xslt.html: updated with 0.11.0
index 50a15be..50ff468 100644 (file)
@@ -853,9 +853,6 @@ xsltScanLiteral(xsltParserContextPtr ctxt) {
  * xsltScanName:
  * @ctxt:  the XPath Parser context
  *
- * Trickery: parse an XML name but without consuming the input flow
- * Needed to avoid insanity in the parser state.
- *
  * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' |
  *                  CombiningChar | Extender
  *
@@ -899,6 +896,73 @@ xsltScanName(xsltParserContextPtr ctxt) {
     SKIP(len);
     return(xmlStrndup(buf, len));
 }
+
+/**
+ * xsltScanNCName:
+ * @ctxt:  the XPath Parser context
+ *
+ * Parses a non qualified name
+ *
+ * Returns the Name parsed or NULL
+ */
+
+static xmlChar *
+xsltScanNCName(xsltParserContextPtr ctxt) {
+    xmlChar buf[XML_MAX_NAMELEN];
+    int len = 0;
+
+    SKIP_BLANKS;
+    if (!IS_LETTER(CUR) && (CUR != '_')) {
+       return(NULL);
+    }
+
+    while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
+           (NXT(len) == '.') || (NXT(len) == '-') ||
+          (NXT(len) == '_') ||
+          (IS_COMBINING(NXT(len))) ||
+          (IS_EXTENDER(NXT(len)))) {
+       buf[len] = NXT(len);
+       len++;
+       if (len >= XML_MAX_NAMELEN) {
+           xmlGenericError(xmlGenericErrorContext, 
+              "xmlScanNCName: reached XML_MAX_NAMELEN limit\n");
+           while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) ||
+                  (NXT(len) == '.') || (NXT(len) == '-') ||
+                  (NXT(len) == '_') ||
+                  (IS_COMBINING(NXT(len))) ||
+                  (IS_EXTENDER(NXT(len))))
+                len++;
+           break;
+       }
+    }
+    SKIP(len);
+    return(xmlStrndup(buf, len));
+}
+
+/**
+ * xsltScanQName:
+ * @ctxt:  the XPath Parser context
+ * @prefix:  the place to store the prefix
+ *
+ * Parse a qualified name
+ *
+ * Returns the Name parsed or NULL
+ */
+
+static xmlChar *
+xsltScanQName(xsltParserContextPtr ctxt, xmlChar **prefix) {
+    xmlChar *ret = NULL;
+
+    *prefix = NULL;
+    ret = xsltScanNCName(ctxt);
+    if (CUR == ':') {
+        *prefix = ret;
+       NEXT;
+       ret = xsltScanNCName(ctxt);
+    }
+    return(ret);
+}
+
 /*
  * xsltCompileIdKeyPattern:
  * @comp:  the compilation context
@@ -1072,14 +1136,32 @@ xsltCompileStepPattern(xsltParserContextPtr ctxt, xmlChar *token) {
            PUSH(XSLT_OP_ATTR, NULL, NULL);
            return;
        }
-       token = xsltScanName(ctxt);
+       token = xsltScanQName(ctxt, &prefix);
+       if (prefix != NULL) {
+           xmlNsPtr ns;
+
+           ns = xmlSearchNs(ctxt->doc, ctxt->elem, prefix);
+           if (ns == NULL) {
+               xsltGenericError(xsltGenericErrorContext,
+                   "xsl: pattern, no namespace bound to prefix %s\n",
+                                prefix);
+           } else {
+               URL = xmlStrdup(ns->href);
+           }
+           xmlFree(prefix);
+       }
        if (token == NULL) {
+           if (CUR == '*') {
+               NEXT;
+               PUSH(XSLT_OP_ATTR, NULL, URL);
+               return;
+           }
            xsltGenericError(xsltGenericErrorContext,
                    "xsltCompileStepPattern : Name expected\n");
            ctxt->error = 1;
            goto error;
        }
-       PUSH(XSLT_OP_ATTR, token, NULL);
+       PUSH(XSLT_OP_ATTR, token, URL);
        return;
     }
     if (token == NULL)
@@ -1439,10 +1521,19 @@ xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) {
                   (element->steps[0].value != NULL) &&
                   (element->steps[1].op == XSLT_OP_END)) {
            element->priority = 0;
+       } else if ((element->steps[0].op == XSLT_OP_ATTR) &&
+                  (element->steps[0].value2 != NULL) &&
+                  (element->steps[1].op == XSLT_OP_END)) {
+           element->priority = -0.25;
        } else if ((element->steps[0].op == XSLT_OP_NS) &&
                   (element->steps[0].value != NULL) &&
                   (element->steps[1].op == XSLT_OP_END)) {
            element->priority = -0.25;
+       } else if ((element->steps[0].op == XSLT_OP_ATTR) &&
+                  (element->steps[0].value == NULL) &&
+                  (element->steps[0].value2 == NULL) &&
+                  (element->steps[1].op == XSLT_OP_END)) {
+           element->priority = -0.5;
        } else if (((element->steps[0].op == XSLT_OP_PI) ||
                    (element->steps[0].op == XSLT_OP_TEXT) ||
                    (element->steps[0].op == XSLT_OP_ALL) ||
index 117e035..87f3ef3 100644 (file)
@@ -1,21 +1,2 @@
 <?xml version="1.0" encoding="utf-8"?>
-earth. the from perish not shall the
-people, for people the by people the of government that and freedom, birth
-of new a have shall nation, the that vain; in died have not dead
-shall these resolve highly here we that -- devotion of measure last
-full the gave here, they which for cause that to devotion take
-increased we dead honored these from that, -- us before remaining great
-task the to dedicated be here we living, the us, for rather is here.
-It did they what forget never can it while say
-here; we what remember long nor note, little will world The or
-detract. add to power poor our above far it, hallowed have struggled
-here, who dead, and living men, brave The -- ground this not
-hallow, can we -- consecrate not can we -- dedicate not can we larger
-sense, a in But, do. propriety all in may, we This live. might the
-nation that here, died who those for place resting final a as it, portion
-of a dedicate to come We war. that of field battle great a on are
-met We endure. long can dedicated, so and conceived, so nation any nation,
-or that whether testing war, civil great a in engaged are we equal&quot;
-Now created are men &quot;all that the
-proposition to dedicated and liberty, in conceived nation, new a this
-continent, upon forth, brought fathers our ago years seven and score Four
+earth. the from perish not shall people, the for people the by people the of government that and freedom, of birth new a have shall nation, the that vain; in died have not shall dead these resolve highly here we that -- devotion of measure full last the gave here, they which for cause that to devotion increased take we dead honored these from that, -- us before remaining task great the to dedicated be here we living, the us, for rather is It here. did they what forget never can it while here; say we what remember long nor note, little will world The detract. or add to power poor our above far it, hallowed have here, struggled who dead, and living men, brave The -- ground this hallow, not can we -- consecrate not can we -- dedicate not can we sense, larger a in But, do. propriety all in may, we This live. might nation the that here, died who those for place resting final a as it, of portion a dedicate to come We war. that of field battle great a on met are We endure. long can dedicated, so and conceived, so nation any or nation, that whether testing war, civil great a in engaged are we Now equal&quot; created are men &quot;all that proposition the to dedicated and liberty, in conceived nation, new a continent, this upon forth, brought fathers our ago years seven and score Four