From 93a9ef80f276ad2676d129e83f6992736a0a17ce Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Wed, 25 Jul 2001 20:20:57 +0000 Subject: [PATCH] fixed an ugly problem with namespaces in templates compilation added a * 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 | 7 +++ libxslt/pattern.c | 113 +++++++++++++++++++++++++++++----------------- libxslt/transform.c | 1 + tests/namespaces/tst4.out | 6 +++ tests/namespaces/tst4.xml | 6 +++ tests/namespaces/tst4.xsl | 14 ++++++ 6 files changed, 105 insertions(+), 42 deletions(-) create mode 100644 tests/namespaces/tst4.out create mode 100644 tests/namespaces/tst4.xml create mode 100644 tests/namespaces/tst4.xsl diff --git a/ChangeLog b/ChangeLog index b27acb7..ffd311b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Jul 26 10:20:19 EDT 2001 Daniel Veillard + + * 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 * configure.in libxslt.spec.in libxslt/xsltwin32config.h: diff --git a/libxslt/pattern.c b/libxslt/pattern.c index 51346f7..fe7aa20 100644 --- a/libxslt/pattern.c +++ b/libxslt/pattern.c @@ -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; diff --git a/libxslt/transform.c b/libxslt/transform.c index 3deecce..7992b9f 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -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 index 0000000..37ef592 --- /dev/null +++ b/tests/namespaces/tst4.out @@ -0,0 +1,6 @@ + + + + matched html:* template + + diff --git a/tests/namespaces/tst4.xml b/tests/namespaces/tst4.xml new file mode 100644 index 0000000..86962bf --- /dev/null +++ b/tests/namespaces/tst4.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/namespaces/tst4.xsl b/tests/namespaces/tst4.xsl new file mode 100644 index 0000000..a7b34f8 --- /dev/null +++ b/tests/namespaces/tst4.xsl @@ -0,0 +1,14 @@ + + + + + + + + + matched html:* template + + + -- 2.7.4