+Wed Jan 30 12:35:28 CET 2002 Daniel Veillard <daniel@veillard.com>
+
+ * libxslt/keys.c: Bob Stayton pointed out a problem when
+ using unions in key match patterns.
+ * tests/docs/Makefile.am tests/docs/bug-70.xml
+ tests/general/Makefile.am tests/general/bug-70.*: added a
+ specific example in the regression tests
+
Sun Jan 27 13:54:10 CET 2002 Daniel Veillard <daniel@veillard.com>
* libxslt/transform.c: avoid a problem with Sun's Workshop CC,
const xmlChar *use, xmlNodePtr inst) {
xsltKeyDefPtr key;
xmlChar *pattern = NULL;
+ int current, end, start;
if ((style == NULL) || (name == NULL) || (match == NULL) || (use == NULL))
return(-1);
key->use = xmlStrdup(use);
key->inst = inst;
- if (key->match[0] != '/') {
- pattern = xmlStrdup((xmlChar *)"//");
- pattern = xmlStrcat(pattern, key->match);
- } else {
- pattern = xmlStrdup(key->match);
+ /*
+ * Split the | and register it as as many keys
+ */
+ current = end = 0;
+ while (match[current] != 0) {
+ start = current;
+ while (IS_BLANK(match[current]))
+ current++;
+ end = current;
+ while ((match[end] != 0) && (match[end] != '|')) {
+ end++;
+ }
+ if (current == end) {
+ xsltPrintErrorContext(NULL, style, inst);
+ xsltGenericError(xsltGenericErrorContext,
+ "key pattern is empty\n");
+ style->errors++;
+ goto error;
+ }
+ if (match[start] != '/') {
+ pattern = xmlStrcat(pattern, (xmlChar *)"//");
+ if (pattern == NULL) {
+ style->errors++;
+ goto error;
+ }
+ }
+ pattern = xmlStrncat(pattern, &match[start], end - start);
+ if (pattern == NULL) {
+ style->errors++;
+ goto error;
+ }
+
+ if (match[end] == '|') {
+ pattern = xmlStrcat(pattern, (xmlChar *)"|");
+ end++;
+ }
+ current = end;
}
+#ifdef WITH_XSLT_DEBUG_KEYS
+ xsltGenericDebug(xsltGenericDebugContext,
+ " resulting pattern %s\n", pattern);
+#endif
key->comp = xmlXPathCompile(pattern);
if (key->comp == NULL) {
xsltPrintErrorContext(NULL, style, inst);
}
key->next = style->keys;
style->keys = key;
+error:
if (pattern != NULL)
xmlFree(pattern);
return(0);
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<div id="div111" href="div111href">
+<div id="div222" href="div222href" >
+<obj id="obj333" href="obj333href" ></obj>
+</div>
+<link linkend="div111"/>
+<link linkend="div222"/>
+<link linkend="obj333"/>
+</div>
+
--- /dev/null
+<?xml version='1.0'?>
+<xsl:stylesheet
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
+
+<xsl:key name="mykey" match="div|obj" use="@id" />
+
+<xsl:template match="link">
+ <xsl:value-of select="@linkend"/>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="key('mykey', @linkend)/@href" />
+</xsl:template>
+
+</xsl:stylesheet>