removing the XSLT filter from the build, only keeping the ALVIS filter
[idzebra-moved-to-github.git] / recctrl / xslt.c
index cb9b8a9..10354bb 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: xslt.c,v 1.20 2006-05-02 08:27:43 marc Exp $
+/* $Id: xslt.c,v 1.27 2006-05-31 16:11:58 marc Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -33,6 +33,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>
@@ -237,6 +238,7 @@ static ZEBRA_RES create_schemas(struct filter_xslt_info *tinfo,
                attr_content(attr, "default", &schema->default_schema);
                attr_content(attr, "snippet", &schema->include_snippet);
            }
+
            if (schema->stylesheet){
               yaz_filepath_resolve(schema->stylesheet, tinfo->profile_path, 
                                    NULL, tmp_xslt_full_name);
@@ -273,16 +275,24 @@ static struct filter_xslt_schema *lookup_schema(struct filter_xslt_info *tinfo,
     struct filter_xslt_schema *schema;
     for (schema = tinfo->schemas; schema; schema = schema->next)
     {
-       if (est)
-       {
+        /* 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;
-       }
-       if (schema->default_schema)
+       } 
+        /* or return default schema if defined */
+        else if (schema->default_schema)
            return schema;
     }
+
+    /* return first schema if no default schema defined */
+    if (tinfo->schemas)
+        return tinfo->schemas;
+    
     return 0;
 }
 
@@ -593,8 +603,8 @@ static const char *snippet_doc(struct recRetrieveCtrl *p, int text_mode,
 
 static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p)
 {
-    const char *esn = zebra_xslt_ns;
-    const char *params[20];
+    const char *esn = 0;
+    const char *params[32];
     struct filter_xslt_info *tinfo = clientData;
     xmlDocPtr resDoc;
     xmlDocPtr doc;
@@ -633,7 +643,17 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p)
        set_param_str(params, "filename", p->fname, p->odr);
     if (p->staticrank >= 0)
        set_param_int(params, "rank", p->staticrank, p->odr);
-    set_param_str(params, "schema", esn, p->odr);
+
+     if (esn)
+        set_param_str(params, "schema", esn, p->odr);
+    else
+        if (schema->name)
+            set_param_str(params, "schema", schema->name, p->odr);
+        else if (schema->identifier)
+            set_param_str(params, "schema", schema->identifier, p->odr);
+        else
+            set_param_str(params, "schema", "", p->odr);
+
     if (p->score >= 0)
        set_param_int(params, "score", p->score, p->odr);
     set_param_int(params, "size", p->recordSize, p->odr);
@@ -674,7 +694,9 @@ 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;
@@ -687,7 +709,9 @@ 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_SUTRS;
        p->rec_len = len_out;
@@ -725,3 +749,11 @@ idzebra_filter
     &filter_type,
     0,
 };
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+