-/* $Id: xslt.c,v 1.9 2005-06-07 13:10:52 adam Exp $
+/* $Id: xslt.c,v 1.13 2005-08-18 12:50:18 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
return 0;
}
-
-
-
-
static void *filter_init_xslt(Res res, RecType recType)
{
struct filter_info *tinfo = (struct filter_info *) xmalloc(sizeof(*tinfo));
return tinfo;
}
-static void *filter_init_xslt1(Res res, RecType recType)
-{
- struct filter_info *tinfo = (struct filter_info *)
- filter_init_xslt(res, recType);
- tinfo->split_level = "1";
- return tinfo;
-}
-
static int attr_content(struct _xmlAttr *attr, const char *name,
const char **dst_content)
{
return 0;
}
-static void index_field(struct filter_info *tinfo, struct recExtractCtrl *ctrl,
+static void index_cdata(struct filter_info *tinfo, struct recExtractCtrl *ctrl,
xmlNodePtr ptr, RecWord *recWord)
{
for(; ptr; ptr = ptr->next)
{
- index_field(tinfo, ctrl, ptr->children, recWord);
+ index_cdata(tinfo, ctrl, ptr->children, recWord);
if (ptr->type != XML_TEXT_NODE)
continue;
recWord->term_buf = ptr->content;
continue;
if (!strcmp(ptr->name, "index"))
{
- char *field_str = 0;
+ const char *name_str = 0;
+ const char *type_str = 0;
const char *xpath_str = 0;
struct _xmlAttr *attr;
for (attr = ptr->properties; attr; attr = attr->next)
{
- if (!strcmp(attr->name, "field")
- && attr->children && attr->children->type == XML_TEXT_NODE)
- field_str = attr->children->content;
- if (!strcmp(attr->name, "xpath")
- && attr->children && attr->children->type == XML_TEXT_NODE)
- xpath_str = attr->children->content;
+ attr_content(attr, "name", &name_str);
+ attr_content(attr, "xpath", &xpath_str);
+ attr_content(attr, "type", &type_str);
}
- if (field_str)
+ if (name_str)
{
- recWord->attrStr = field_str;
- index_field(tinfo, ctrl, ptr->children, recWord);
+ int prev_type = recWord->index_type; /* save default type */
+
+ if (type_str && *type_str)
+ recWord->index_type = *type_str; /* type was given */
+ recWord->index_name = name_str;
+ index_cdata(tinfo, ctrl, ptr->children, recWord);
+
+ recWord->index_type = prev_type; /* restore it again */
}
}
}
}
+static void index_record(struct filter_info *tinfo,struct recExtractCtrl *ctrl,
+ xmlNodePtr ptr, RecWord *recWord)
+{
+ if (ptr && ptr->type == XML_ELEMENT_NODE && ptr->ns &&
+ !strcmp(ptr->ns->href, zebra_xslt_ns)
+ && !strcmp(ptr->name, "record"))
+ {
+ const char *type_str = "update";
+ const char *id_str = 0;
+ const char *rank_str = 0;
+ struct _xmlAttr *attr;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ attr_content(attr, "type", &type_str);
+ attr_content(attr, "id", &id_str);
+ attr_content(attr, "rank", &rank_str);
+ }
+ if (id_str)
+ sscanf(id_str, "%255s", ctrl->match_criteria);
+ if (rank_str)
+ {
+ ctrl->staticrank = atoi(rank_str);
+ yaz_log(YLOG_LOG, "rank=%d",ctrl->staticrank);
+ }
+ else
+ yaz_log(YLOG_LOG, "no rank");
+
+ ptr = ptr->children;
+ }
+ index_node(tinfo, ctrl, ptr, recWord);
+}
+
static int extract_doc(struct filter_info *tinfo, struct recExtractCtrl *p,
xmlDocPtr doc)
{
set_param_str(params, "schema", zebra_xslt_ns, tinfo->odr);
(*p->init)(p, &recWord);
- recWord.reg_type = 'w';
if (schema && schema->stylesheet_xsp)
{
+ xmlNodePtr root_ptr;
xmlDocPtr resDoc =
xsltApplyStylesheet(schema->stylesheet_xsp,
doc, params);
fwrite(buf_out, len_out, 1, stdout);
xmlFree(buf_out);
}
- index_node(tinfo, p, xmlDocGetRootElement(resDoc), &recWord);
+ root_ptr = xmlDocGetRootElement(resDoc);
+ if (root_ptr)
+ index_record(tinfo, p, root_ptr, &recWord);
+ else
+ {
+ yaz_log(YLOG_WARN, "No root for index XML record."
+ " split_level=%s stylesheet=%s",
+ tinfo->split_level, schema->stylesheet);
+ }
xmlFreeDoc(resDoc);
}
xmlDocDumpMemory(doc, &buf_out, &len_out);
if (p->score >= 0)
set_param_int(params, "score", p->score, p->odr);
set_param_int(params, "size", p->recordSize, p->odr);
-
+ set_param_int(params, "id", p->localno, p->odr);
+
if (window_size >= 0)
set_param_xml(params, "snippet", snippet_doc(p, 1, window_size),
p->odr);
filter_retrieve
};
-static struct recType filter_type_xslt1 = {
- 0,
- "xslt1",
- filter_init_xslt1,
- filter_config,
- filter_destroy,
- filter_extract,
- filter_retrieve
-};
-
RecType
#ifdef IDZEBRA_STATIC_XSLT
idzebra_filter_xslt
[] = {
&filter_type_xslt,
-#ifdef LIBXML_READER_ENABLED
- &filter_type_xslt1,
-#endif
0,
};