struct _xsltCompMatch {
struct _xsltCompMatch *next; /* siblings in the name hash */
float priority; /* the priority */
+ const xmlChar *pattern; /* the pattern */
const xmlChar *mode; /* the mode */
const xmlChar *modeURI; /* the mode URI */
xsltTemplatePtr template; /* the associated template */
if (comp == NULL)
return;
+ if (comp->pattern != NULL)
+ xmlFree((xmlChar *)comp->pattern);
if (comp->mode != NULL)
xmlFree((xmlChar *)comp->mode);
if (comp->modeURI != NULL)
return(NULL);
}
-#ifdef WITH_XSLT_DEBUG_PATTERN
- xsltGenericDebug(xsltGenericDebugContext,
- "xsltCompilePattern : parsing '%s'\n", pattern);
-#endif
-
ctxt = xsltNewParserContext();
if (ctxt == NULL)
return(NULL);
ctxt->comp = element;
ctxt->base = xmlStrndup(&pattern[start], end - start);
+ if (ctxt->base == NULL)
+ goto error;
ctxt->cur = &(ctxt->base)[current - start];
+ element->pattern = ctxt->base;
+
+#ifdef WITH_XSLT_DEBUG_PATTERN
+ xsltGenericDebug(xsltGenericDebugContext,
+ "xsltCompilePattern : parsing '%s'\n",
+ element->pattern);
+#endif
xsltCompileLocationPathPattern(ctxt);
- if (ctxt->base)
- xmlFree((xmlChar *)ctxt->base);
if (ctxt->error)
goto error;
(element->steps[0].value != NULL) &&
(element->steps[1].op == XSLT_OP_END)) {
element->priority = 0;
+#if 0
} else if ((element->steps[0].op == XSLT_OP_ROOT) &&
(element->steps[1].op == XSLT_OP_END)) {
element->priority = 0;
+#endif
} else if ((element->steps[0].op == XSLT_OP_PI) &&
(element->steps[0].value != NULL) &&
(element->steps[1].op == XSLT_OP_END)) {
} else {
element->priority = 0.5;
}
+#ifdef WITH_XSLT_DEBUG_PATTERN
+ xsltGenericDebug(xsltGenericDebugContext,
+ "xsltCompilePattern : parsed %s, default priority %f\n",
+ element->pattern, element->priority);
+#endif
if (pattern[end] == '|')
end++;
current = end;
const xmlChar *mode, const xmlChar *modeURI) {
xsltCompMatchPtr pat, list, *top = NULL, next;
const xmlChar *name = NULL;
+ float priority; /* the priority */
if ((style == NULL) || (cur == NULL) || (cur->match == NULL))
return(-1);
+ priority = cur->priority;
pat = xsltCompilePattern(cur->match, style->doc, cur->elem);
while (pat) {
next = pat->next;
pat->next = NULL;
+ name = NULL;
pat->template = cur;
if (mode != NULL)
pat->mode = xmlStrdup(mode);
if (modeURI != NULL)
pat->modeURI = xmlStrdup(modeURI);
- if (cur->priority == XSLT_PAT_NO_PRIORITY)
- cur->priority = pat->priority;
- else
- pat->priority = cur->priority;
+ if (priority != XSLT_PAT_NO_PRIORITY)
+ pat->priority = priority;
/*
* insert it in the hash table list corresponding to its lookup name
if (mode)
xsltGenericDebug(xsltGenericDebugContext,
"added pattern : '%s' mode '%s' priority %f\n",
- pat->template->match, pat->mode, pat->priority);
+ pat->pattern, pat->mode, pat->priority);
else
xsltGenericDebug(xsltGenericDebugContext,
"added pattern : '%s' priority %f\n",
- pat->template->match, pat->priority);
+ pat->pattern, pat->priority);
#endif
pat = next;
xsltTemplatePtr ret = NULL;
const xmlChar *name = NULL;
xsltCompMatchPtr list = NULL;
+ float priority;
if ((ctxt == NULL) || (node == NULL))
return(NULL);
}
while ((curstyle != NULL) && (curstyle != style)) {
+ priority = XSLT_PAT_NO_PRIORITY;
/* TODO : handle IDs/keys here ! */
if (curstyle->templatesHash != NULL) {
/*
if (xsltTestCompMatch(ctxt, list, node,
ctxt->mode, ctxt->modeURI)) {
ret = list->template;
+ priority = list->priority;
break;
}
list = list->next;
}
while ((list != NULL) &&
- ((ret == NULL) || (list->priority > ret->priority))) {
+ ((ret == NULL) || (list->priority > priority))) {
if (xsltTestCompMatch(ctxt, list, node,
ctxt->mode, ctxt->modeURI)) {
ret = list->template;
if (node->_private != NULL) {
list = curstyle->keyMatch;
while ((list != NULL) &&
- ((ret == NULL) || (list->priority > ret->priority))) {
+ ((ret == NULL) || (list->priority > priority))) {
if (xsltTestCompMatch(ctxt, list, node,
ctxt->mode, ctxt->modeURI)) {
ret = list->template;
if (node->type == XML_ATTRIBUTE_NODE) {
#ifdef WITH_XSLT_DEBUG_PROCESS
xsltGenericDebug(xsltGenericDebugContext,
- "xsltProcessOneNode: applying template for attribute %s\n",
- node->name);
+ "xsltProcessOneNode: applying template '%s' for attribute %s\n",
+ template->match, node->name);
#endif
templPush(ctxt, template);
xsltApplyOneTemplate(ctxt, node, template->content, 1);
#ifdef WITH_XSLT_DEBUG_PROCESS
if (node->type == XML_DOCUMENT_NODE)
xsltGenericDebug(xsltGenericDebugContext,
- "xsltProcessOneNode: applying template for /\n");
+ "xsltProcessOneNode: applying template '%s' for /\n",
+ template->match);
else
xsltGenericDebug(xsltGenericDebugContext,
- "xsltProcessOneNode: applying template for %s\n", node->name);
+ "xsltProcessOneNode: applying template '%s' for %s\n",
+ template->match, node->name);
#endif
oldNode = ctxt->node;
ctxt->node = node;
--- /dev/null
+<?xml version='1.0'?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version='1.0'>
+
+<xsl:template match="/">
+ <root>
+ <xsl:apply-templates />
+ </root>
+</xsl:template>
+
+<xsl:template match="x">
+ <xsl:text>Matched x template</xsl:text>
+ <xsl:apply-templates />
+</xsl:template>
+
+<!-- Case 1: y=0.0 /*=0.0, even though /* should be 0.5 -->
+<!-- works if split up to:
+<xsl:template match="/*"> or of course you reverse the order
+so the y pattern is screwed instead
+-->
+<xsl:template match="y|/*">
+ <xsl:text>Matched /* or y template</xsl:text>
+ <xsl:apply-templates />
+</xsl:template>
+
+<!--
+Case 2: Here, both should have 5.0 priority but /* seems to have 0.0!
+<xsl:template match="y|/*" priority="5.0">
+ <xsl:text>Matched /* or y template</xsl:text>
+ <xsl:apply-templates />
+</xsl:template>
+-->
+
+</xsl:stylesheet>