made place for record delete
[idzebra-moved-to-github.git] / recctrl / alvis.c
index 7e9aa76..48de318 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: alvis.c,v 1.13 2006-05-24 08:23:01 marc Exp $
+/* $Id: alvis.c,v 1.16 2006-05-29 13:48:43 marc Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -31,6 +31,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <libxml/xmlIO.h>
 #include <libxml/xmlreader.h>
 #include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
 
 #include <idzebra/util.h>
 #include <idzebra/recctrl.h>
@@ -208,6 +209,11 @@ static ZEBRA_RES create_schemas(struct filter_info *tinfo, const char *fname)
                attr_content(attr, "default", &schema->default_schema);
                attr_content(attr, "snippet", &schema->include_snippet);
            }
+            /*yaz_log(YLOG_LOG, "XSLT add %s %s %s", 
+              schema->name, schema->identifier, schema->stylesheet); */
+
+            /* find requested schema */
+
            if (schema->stylesheet)
                schema->stylesheet_xsp =
                    xsltParseStylesheetFile(
@@ -237,19 +243,20 @@ static struct filter_schema *lookup_schema(struct filter_info *tinfo,
                                           const char *est)
 {
     struct filter_schema *schema;
+
     for (schema = tinfo->schemas; schema; schema = schema->next)
-    {
+    { 
         /* find requested schema */
        if (est) 
-       {
+       {    
            if (schema->identifier && !strcmp(schema->identifier, est))
-               return schema;
+                return schema;
+            
            if (schema->name && !strcmp(schema->name, est))
                return schema;
-       }
-
+       } 
         /* or return default schema if defined */
-       if (schema->default_schema)
+        else if (schema->default_schema)
            return schema;
     }
 
@@ -346,11 +353,12 @@ static void index_node(struct filter_info *tinfo,  struct recExtractCtrl *ctrl,
 static void index_record(struct filter_info *tinfo,struct recExtractCtrl *ctrl,
                         xmlNodePtr ptr, RecWord *recWord)
 {
+    const char *type_str = "update";
+
     if (ptr && ptr->type == XML_ELEMENT_NODE && ptr->ns &&
        !XML_STRCMP(ptr->ns->href, zebra_xslt_ns)
        && !XML_STRCMP(ptr->name, "record"))
     {
-       const char *type_str = "update";
        const char *id_str = 0;
        const char *rank_str = 0;
        struct _xmlAttr *attr;
@@ -362,17 +370,20 @@ static void index_record(struct filter_info *tinfo,struct recExtractCtrl *ctrl,
        }
        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);
+
+    if (!strcmp("update", type_str))
+        index_node(tinfo, ctrl, ptr, recWord);
+    else if (!strcmp("delete", type_str))
+         yaz_log(YLOG_WARN, "alvis filter delete: to be implemented");
+    else
+         yaz_log(YLOG_WARN, "alvis filter: unknown record type '%s'", 
+                 type_str);
 }
     
 static int extract_doc(struct filter_info *tinfo, struct recExtractCtrl *p,
@@ -650,20 +661,23 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p)
     {
        xmlChar *buf_out;
        int len_out;
-       xmlDocDumpMemory(resDoc, &buf_out, &len_out);
+
+        xsltSaveResultToString(&buf_out, &len_out, resDoc,
+                               schema->stylesheet_xsp);        
 
        p->output_format = VAL_TEXT_XML;
        p->rec_len = len_out;
        p->rec_buf = odr_malloc(p->odr, p->rec_len);
        memcpy(p->rec_buf, buf_out, p->rec_len);
-       
        xmlFree(buf_out);
     }
     else if (p->output_format == VAL_SUTRS)
     {
        xmlChar *buf_out;
        int len_out;
-       xmlDocDumpMemory(resDoc, &buf_out, &len_out);
+
+        xsltSaveResultToString(&buf_out, &len_out, resDoc,
+                               schema->stylesheet_xsp);        
 
        p->output_format = VAL_SUTRS;
        p->rec_len = len_out;