+Thu Feb 15 12:41:44 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+ * libxslt/pattern.[ch]: exported pattern matching interfaces
+ for numbers.c and future debug module
+ * libxslt/numbers.c: updated to new interface, should avoid
+ unnecessary recompilation of patterns.
+ * libxslt/xsltutils.[ch]: cleanup
+ * tests/REC/gmon.out: removed :-)
+
Wed Feb 14 19:13:33 CET 2001 Bjorn Reese <breese@users.sourceforge.net>
* libxslt/numbers.c: implemented level=any
xmlNodePtr ancestor;
xmlNodePtr preceding;
xmlXPathParserContextPtr parser;
-
+ xsltCompMatchPtr countPat;
+ xsltCompMatchPtr fromPat;
+
+ if (count != NULL)
+ countPat = xsltCompilePattern(count);
+ else
+ countPat = NULL;
+ if (from != NULL)
+ fromPat = xsltCompilePattern(from);
+ else
+ fromPat = NULL;
context->xpathCtxt->node = node;
parser = xmlXPathNewParserContext(NULL, context->xpathCtxt);
if (parser) {
preceding != NULL;
preceding = xmlXPathNextPreceding(parser, preceding)) {
if ((from != NULL) &&
- xsltMatchPattern(context, preceding, from)) {
+ xsltTestCompMatchList(context, preceding, fromPat)) {
keep_going = FALSE;
break; /* for */
}
xmlStrEqual(node->name, preceding->name))
cnt++;
} else {
- if (xsltMatchPattern(context, preceding, count))
+ if (xsltTestCompMatchList(context, preceding, countPat))
cnt++;
}
}
ancestor != NULL;
ancestor = xmlXPathNextAncestor(parser, ancestor)) {
if ((from != NULL) &&
- xsltMatchPattern(context, ancestor, from)) {
+ xsltTestCompMatchList(context, ancestor, fromPat)) {
break; /* for */
}
if (count == NULL) {
xmlStrEqual(node->name, ancestor->name))
cnt++;
} else {
- if (xsltMatchPattern(context, ancestor, count))
+ if (xsltTestCompMatchList(context, ancestor, countPat))
cnt++;
}
}
}
array[amount++] = (double)cnt;
}
+ xsltFreeCompMatchList(countPat);
+ xsltFreeCompMatchList(fromPat);
return amount;
}
xmlNodePtr ancestor;
xmlNodePtr preceding;
xmlXPathParserContextPtr parser;
-
+ xsltCompMatchPtr countPat;
+ xsltCompMatchPtr fromPat;
+
+ if (count != NULL)
+ countPat = xsltCompilePattern(count);
+ else
+ countPat = NULL;
+ if (from != NULL)
+ fromPat = xsltCompilePattern(from);
+ else
+ fromPat = NULL;
context->xpathCtxt->node = node;
parser = xmlXPathNewParserContext(NULL, context->xpathCtxt);
if (parser) {
ancestor = xmlXPathNextAncestor(parser, ancestor)) {
if ((from != NULL) &&
- xsltMatchPattern(context, ancestor, from))
+ xsltTestCompMatchList(context, ancestor, fromPat))
break; /* for */
if ((count == NULL) ||
- xsltMatchPattern(context, ancestor, count)) {
+ xsltTestCompMatchList(context, ancestor, countPat)) {
/* count(preceding-sibling::*) */
cnt = 0;
for (preceding = ancestor;
preceding != NULL;
- preceding = xmlXPathNextPrecedingSibling(parser, preceding)) {
+ preceding =
+ xmlXPathNextPrecedingSibling(parser, preceding)) {
if (count == NULL) {
if ((preceding->type == ancestor->type) &&
/* FIXME */
xmlStrEqual(preceding->name, ancestor->name))
cnt++;
} else {
- if (xsltMatchPattern(context, preceding, count))
+ if (xsltTestCompMatchList(context, preceding,
+ countPat))
cnt++;
}
}
}
xmlXPathFreeParserContext(parser);
}
+ xsltFreeCompMatchList(countPat);
+ xsltFreeCompMatchList(fromPat);
return amount;
}
} else if (data->level) {
- if (xmlStrEqual(data->level, "single")) {
+ if (xmlStrEqual(data->level, (const xmlChar *) "single")) {
amount = xsltNumberFormatGetMultipleLevel(ctxt,
node,
data->count,
array_amount,
output);
}
- } else if (xmlStrEqual(data->level, "multiple")) {
+ } else if (xmlStrEqual(data->level, (const xmlChar *) "multiple")) {
double numarray[1024];
int max = sizeof(numarray)/sizeof(numarray[0]);
amount = xsltNumberFormatGetMultipleLevel(ctxt,
array_amount,
output);
}
- } else if (xmlStrEqual(data->level, "any")) {
+ } else if (xmlStrEqual(data->level, (const xmlChar *) "any")) {
amount = xsltNumberFormatGetAnyLevel(ctxt,
node,
data->count,
xmlChar *value3;
};
-typedef struct _xsltCompMatch xsltCompMatch;
-typedef xsltCompMatch *xsltCompMatchPtr;
struct _xsltCompMatch {
struct _xsltCompMatch *next; /* siblings in the name hash */
float priority; /* the priority */
/**
* xsltNewCompMatch:
- * @mode: the mode name or NULL
- * @modeURI: the mode URI or NULL
*
* Create a new XSLT CompMatch
*
* Returns the newly allocated xsltCompMatchPtr or NULL in case of error
*/
xsltCompMatchPtr
-xsltNewCompMatch(const xmlChar *mode, const xmlChar *modeURI) {
+xsltNewCompMatch(void) {
xsltCompMatchPtr cur;
cur = (xsltCompMatchPtr) xmlMalloc(sizeof(xsltCompMatch));
}
memset(cur, 0, sizeof(xsltCompMatch));
cur->maxStep = 20;
- cur->mode = xmlStrdup(mode);
- cur->modeURI = xmlStrdup(modeURI);
return(cur);
}
return(1);
}
+/**
+ * xsltTestCompMatchList:
+ * @ctxt: a XSLT process context
+ * @node: a node
+ * @comp: the precompiled pattern list
+ *
+ * Test wether the node matches one of the patterns in the list
+ *
+ * Returns 1 if it matches, 0 if it doesn't and -1 in case of failure
+ */
+int
+xsltTestCompMatchList(xsltTransformContextPtr ctxt, xmlNodePtr node,
+ xsltCompMatchPtr comp) {
+ int ret;
+
+ if ((ctxt == NULL) || (node == NULL))
+ return(-1);
+ while (comp != NULL) {
+ ret = xsltTestCompMatch(ctxt, comp, node, NULL, NULL);
+ if (ret == 1)
+ return(1);
+ comp = comp->next;
+ }
+ return(0);
+}
+
/************************************************************************
* *
* Dedicated parser for templates *
/**
* xsltCompilePattern:
* @pattern an XSLT pattern
- * @mode: the mode name or NULL
- * @modeURI: the mode URI or NULL
*
- * Compile the XSLT pattern and generates a precompiled form suitable
+ * Compile the XSLT pattern and generates a list of precompiled form suitable
* for fast matching.
- * Note that the splitting as union of patterns is expected to be handled
- * by the caller
*
* [1] Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern
*
- * Returns the generated xsltCompMatchPtr or NULL in case of failure
+ * Returns the generated pattern list or NULL in case of failure
*/
xsltCompMatchPtr
-xsltCompilePattern(const xmlChar *pattern, const xmlChar *mode,
- const xmlChar *modeURI) {
+xsltCompilePattern(const xmlChar *pattern) {
xsltParserContextPtr ctxt = NULL;
xsltCompMatchPtr element, first = NULL, previous = NULL;
int current, start, end;
"xsltCompilePattern : NULL pattern\n");
goto error;
}
- element = xsltNewCompMatch(mode, modeURI);
+ element = xsltNewCompMatch();
if (element == NULL) {
goto error;
}
return(NULL);
}
-
/************************************************************************
* *
* Module interfaces *
if ((style == NULL) || (cur == NULL) || (cur->match == NULL))
return(-1);
- pat = xsltCompilePattern(cur->match, mode, modeURI);
+ pat = xsltCompilePattern(cur->match);
while (pat) {
next = pat->next;
pat->next = NULL;
pat->template = cur;
+ if (mode != NULL)
+ pat->mode = xmlStrdup(mode);
+ if (modeURI != NULL)
+ pat->modeURI = xmlStrdup(modeURI);
if (pat->priority != XSLT_PAT_NO_PRIORITY)
cur->priority = pat->priority;
else
}
/**
- * xsltMatchTemplate
+ * xsltMatchPattern
* @node: a node in the source tree
* @pattern: an XSLT pattern
*
xsltCompMatchPtr first, comp;
if ((context != NULL) && (pattern != NULL)) {
- first = xsltCompilePattern(pattern, NULL, NULL);
+ first = xsltCompilePattern(pattern);
for (comp = first; comp != NULL; comp = comp->next) {
match = xsltTestCompMatch(context, comp, node, NULL, NULL);
if (match)
}
return match;
}
+
extern "C" {
#endif
+/*
+ * The implementation of patterns is kept private
+ */
+typedef struct _xsltCompMatch xsltCompMatch;
+typedef xsltCompMatch *xsltCompMatchPtr;
+
+/*
+ * Pattern related interfaces
+ */
+
+xsltCompMatchPtr xsltCompilePattern (const xmlChar *pattern);
+void xsltFreeCompMatchList (xsltCompMatchPtr comp);
+int xsltTestCompMatchList (xsltTransformContextPtr ctxt,
+ xmlNodePtr node,
+ xsltCompMatchPtr comp);
+
+/*
+ * Template related interfaces
+ */
int xsltAddTemplate (xsltStylesheetPtr style,
xsltTemplatePtr cur,
const xmlChar *mode,
}
if ((cur != NULL) && (cur->name != NULL)) {
xmlOutputBufferWriteString(buf, "<!DOCTYPE ");
- xmlOutputBufferWriteString(buf, cur->name);
+ xmlOutputBufferWriteString(buf, (const char *) cur->name);
if (doctypePublic != NULL) {
if (doctypeSystem != NULL) {
xmlOutputBufferWriteString(buf, " PUBLIC ");
void xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs);
xmlAttrPtr xmlSetNsProp (xmlNodePtr node, xmlNsPtr ns, const xmlChar *name,
const xmlChar *value);
+xmlNodePtr xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt, xmlNodePtr cur);
+xmlNodePtr xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt, xmlNodePtr cur);
+xmlNodePtr xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur);
/*********
void xmlXPathRegisterVariableLookup(xmlXPathContextPtr ctxt,
xmlXPathVariableLookupFunc f, void *data)