Put local variables footer in all c, h files.
[idzebra-moved-to-github.git] / recctrl / xslt.c
1 /* $Id: xslt.c,v 1.21 2006-05-10 08:13:31 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 #include <stdio.h>
24 #include <assert.h>
25 #include <ctype.h>
26
27 #include <yaz/diagbib1.h>
28 #include <yaz/tpath.h>
29
30 #include <libxml/xmlversion.h>
31 #include <libxml/parser.h>
32 #include <libxml/tree.h>
33 #include <libxml/xmlIO.h>
34 #include <libxml/xmlreader.h>
35 #include <libxslt/transform.h>
36
37 #include <idzebra/util.h>
38 #include <idzebra/recctrl.h>
39
40 struct filter_xslt_schema {
41     const char *name;
42     const char *identifier;
43     const char *stylesheet;
44     struct filter_xslt_schema *next;
45     const char *default_schema;
46     const char *include_snippet;
47     xsltStylesheetPtr stylesheet_xsp;
48 };
49
50 struct filter_xslt_info {
51     xmlDocPtr doc;
52     char *fname;
53     char *full_name;
54     const char *profile_path;
55     const char *split_level;
56     const char *split_path;
57     ODR odr;
58     struct filter_xslt_schema *schemas;
59     xmlTextReaderPtr reader;
60 };
61
62
63 #define ZEBRA_SCHEMA_XSLT_NS "http://indexdata.dk/zebra/xslt/1"
64
65 #define XML_STRCMP(a,b)   strcmp((char*)a, b)
66 #define XML_STRLEN(a) strlen((char*)a)
67
68 static const char *zebra_xslt_ns = ZEBRA_SCHEMA_XSLT_NS;
69
70 static void set_param_xml(const char **params, const char *name,
71                           const char *value, ODR odr)
72 {
73     while (*params)
74         params++;
75     params[0] = name;
76     params[1] = value;
77     params[2] = 0;
78 }
79
80 static void set_param_str(const char **params, const char *name,
81                           const char *value, ODR odr)
82 {
83     char *quoted = odr_malloc(odr, 3 + strlen(value));
84     sprintf(quoted, "'%s'", value);
85     while (*params)
86         params++;
87     params[0] = name;
88     params[1] = quoted;
89     params[2] = 0;
90 }
91
92 static void set_param_int(const char **params, const char *name,
93                           zint value, ODR odr)
94 {
95     char *quoted = odr_malloc(odr, 30); /* 25 digits enough for 2^64 */
96     while (*params)
97         params++;
98     sprintf(quoted, "'" ZINT_FORMAT "'", value);
99     params[0] = name;
100     params[1] = quoted;
101     params[2] = 0;
102 }
103
104 #define ENABLE_INPUT_CALLBACK 0
105
106 #if ENABLE_INPUT_CALLBACK
107 static int zebra_xmlInputMatchCallback (char const *filename)
108 {
109     yaz_log(YLOG_LOG, "match %s", filename);
110     return 0;
111 }
112
113 static void * zebra_xmlInputOpenCallback (char const *filename)
114 {
115     return 0;
116 }
117
118 static int zebra_xmlInputReadCallback (void * context, char * buffer, int len)
119 {
120     return 0;
121 }
122
123 static int zebra_xmlInputCloseCallback (void * context)
124 {
125     return 0;
126 }
127 #endif
128
129 static void *filter_init(Res res, RecType recType)
130 {
131     struct filter_xslt_info *tinfo 
132       = (struct filter_xslt_info *) xmalloc(sizeof(*tinfo));
133     tinfo->reader = 0;
134     tinfo->fname = 0;
135     tinfo->full_name = 0;
136     tinfo->profile_path = 0;
137     tinfo->split_level = 0;
138     tinfo->split_path = 0;
139     tinfo->odr = odr_createmem(ODR_ENCODE);
140     tinfo->doc = 0;
141     tinfo->schemas = 0;
142
143 #if ENABLE_INPUT_CALLBACK
144     xmlRegisterDefaultInputCallbacks();
145     xmlRegisterInputCallbacks(zebra_xmlInputMatchCallback,
146                               zebra_xmlInputOpenCallback,
147                               zebra_xmlInputReadCallback,
148                               zebra_xmlInputCloseCallback);
149 #endif
150     return tinfo;
151 }
152
153 static int attr_content(struct _xmlAttr *attr, const char *name,
154                         const char **dst_content)
155 {
156     if (!XML_STRCMP(attr->name, name) && attr->children &&
157         attr->children->type == XML_TEXT_NODE)
158     {
159         *dst_content = (const char *)(attr->children->content);
160         return 1;
161     }
162     return 0;
163 }
164
165 static void destroy_schemas(struct filter_xslt_info *tinfo)
166 {
167     struct filter_xslt_schema *schema = tinfo->schemas;
168     while (schema)
169     {
170         struct filter_xslt_schema *schema_next = schema->next;
171         if (schema->stylesheet_xsp)
172             xsltFreeStylesheet(schema->stylesheet_xsp);
173         xfree(schema);
174         schema = schema_next;
175     }
176     tinfo->schemas = 0;
177     xfree(tinfo->fname);
178     if (tinfo->doc)
179         xmlFreeDoc(tinfo->doc);    
180     tinfo->doc = 0;
181 }
182
183 static ZEBRA_RES create_schemas(struct filter_xslt_info *tinfo, 
184                                 const char *fname)
185 {
186     char tmp_full_name[1024];
187     xmlNodePtr ptr;
188     tinfo->fname = xstrdup(fname);
189
190     if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path, 
191                              NULL, tmp_full_name))
192       tinfo->full_name = xstrdup(tmp_full_name);
193     else
194       tinfo->full_name = xstrdup(tinfo->fname);
195
196     yaz_log(YLOG_LOG, "xslt filter: loading config file %s", tinfo->full_name);
197
198     tinfo->doc = xmlParseFile(tinfo->full_name);
199     if (!tinfo->doc) {
200       yaz_log(YLOG_WARN, "xslt filter: could not parse config file %s", 
201               tinfo->full_name);
202       return ZEBRA_FAIL;
203     }
204
205     ptr = xmlDocGetRootElement(tinfo->doc);
206     if (!ptr || ptr->type != XML_ELEMENT_NODE ||
207         XML_STRCMP(ptr->name, "schemaInfo")){
208           yaz_log(YLOG_WARN, 
209                   "xslt filter:  config file %s :" 
210                   " expected root element <schemaInfo>", 
211               tinfo->full_name);  
212       return ZEBRA_FAIL;
213     }
214     
215     for (ptr = ptr->children; ptr; ptr = ptr->next)
216     {
217         if (ptr->type != XML_ELEMENT_NODE)
218             continue;
219         if (!XML_STRCMP(ptr->name, "schema"))
220         {
221             char tmp_xslt_full_name[1024];
222             struct _xmlAttr *attr;
223             struct filter_xslt_schema *schema = xmalloc(sizeof(*schema));
224             schema->name = 0;
225             schema->identifier = 0;
226             schema->stylesheet = 0;
227             schema->default_schema = 0;
228             schema->next = tinfo->schemas;
229             schema->stylesheet_xsp = 0;
230             schema->include_snippet = 0;
231             tinfo->schemas = schema;
232             for (attr = ptr->properties; attr; attr = attr->next)
233             {
234                 attr_content(attr, "identifier", &schema->identifier);
235                 attr_content(attr, "name", &schema->name);
236                 attr_content(attr, "stylesheet", &schema->stylesheet);
237                 attr_content(attr, "default", &schema->default_schema);
238                 attr_content(attr, "snippet", &schema->include_snippet);
239             }
240             if (schema->stylesheet){
241               yaz_filepath_resolve(schema->stylesheet, tinfo->profile_path, 
242                                    NULL, tmp_xslt_full_name);
243               schema->stylesheet_xsp 
244                 = xsltParseStylesheetFile((const xmlChar*) tmp_xslt_full_name);
245               if (!schema->stylesheet_xsp)
246                 yaz_log(YLOG_WARN, 
247                         "xslt filter: could not parse xslt stylesheet %s", 
248                         tmp_xslt_full_name);
249             }
250             
251         }
252         else if (!XML_STRCMP(ptr->name, "split"))
253         {
254             struct _xmlAttr *attr;
255             for (attr = ptr->properties; attr; attr = attr->next)
256             {
257                 attr_content(attr, "level", &tinfo->split_level);
258                 attr_content(attr, "path", &tinfo->split_path);
259             }
260         }
261         else
262         {
263             yaz_log(YLOG_WARN, "Bad element %s in %s", ptr->name, fname);
264             return ZEBRA_FAIL;
265         }
266     }
267     return ZEBRA_OK;
268 }
269
270 static struct filter_xslt_schema *lookup_schema(struct filter_xslt_info *tinfo,
271                                            const char *est)
272 {
273     struct filter_xslt_schema *schema;
274     for (schema = tinfo->schemas; schema; schema = schema->next)
275     {
276         if (est)
277         {
278             if (schema->identifier && !strcmp(schema->identifier, est))
279                 return schema;
280             if (schema->name && !strcmp(schema->name, est))
281                 return schema;
282         }
283         if (schema->default_schema)
284             return schema;
285     }
286     return 0;
287 }
288
289 static ZEBRA_RES filter_config(void *clientData, Res res, const char *args)
290 {
291     struct filter_xslt_info *tinfo = clientData;
292     if (!args || !*args){
293       yaz_log(YLOG_WARN, "xslt filter: need config file");
294       return ZEBRA_FAIL;
295     }
296
297     if (tinfo->fname && !strcmp(args, tinfo->fname))
298         return ZEBRA_OK;
299     
300     tinfo->profile_path 
301       /* = res_get_def(res, "profilePath", DEFAULT_PROFILE_PATH); */
302       = res_get(res, "profilePath");
303     yaz_log(YLOG_LOG, "xslt filter: profilePath %s", tinfo->profile_path);
304
305     destroy_schemas(tinfo);
306     create_schemas(tinfo, args);
307     return ZEBRA_OK;
308 }
309
310 static void filter_destroy(void *clientData)
311 {
312     struct filter_xslt_info *tinfo = clientData;
313     destroy_schemas(tinfo);
314     if (tinfo->reader)
315         xmlFreeTextReader(tinfo->reader);
316     odr_destroy(tinfo->odr);
317     xfree(tinfo);
318 }
319
320 static int ioread_ex(void *context, char *buffer, int len)
321 {
322     struct recExtractCtrl *p = context;
323     return (*p->readf)(p->fh, buffer, len);
324 }
325
326 static int ioclose_ex(void *context)
327 {
328     return 0;
329 }
330
331 static void index_cdata(struct filter_xslt_info *tinfo, struct recExtractCtrl *ctrl,
332                         xmlNodePtr ptr, RecWord *recWord)
333 {
334     for(; ptr; ptr = ptr->next)
335     {
336         index_cdata(tinfo, ctrl, ptr->children, recWord);
337         if (ptr->type != XML_TEXT_NODE)
338             continue;
339         recWord->term_buf = (const char *)ptr->content;
340         recWord->term_len = XML_STRLEN(ptr->content);
341         (*ctrl->tokenAdd)(recWord);
342     }
343 }
344
345 static void index_node(struct filter_xslt_info *tinfo,  struct recExtractCtrl *ctrl,
346                        xmlNodePtr ptr, RecWord *recWord)
347 {
348     for(; ptr; ptr = ptr->next)
349     {
350         index_node(tinfo, ctrl, ptr->children, recWord);
351         if (ptr->type != XML_ELEMENT_NODE || !ptr->ns ||
352             XML_STRCMP(ptr->ns->href, zebra_xslt_ns))
353             continue;
354         if (!XML_STRCMP(ptr->name, "index"))
355         {
356             const char *name_str = 0;
357             const char *type_str = 0;
358             const char *xpath_str = 0;
359             struct _xmlAttr *attr;
360             for (attr = ptr->properties; attr; attr = attr->next)
361             {
362                 attr_content(attr, "name", &name_str);
363                 attr_content(attr, "xpath", &xpath_str);
364                 attr_content(attr, "type", &type_str);
365             }
366             if (name_str)
367             {
368                 int prev_type = recWord->index_type; /* save default type */
369
370                 if (type_str && *type_str)
371                     recWord->index_type = *type_str; /* type was given */
372                 recWord->index_name = name_str;
373                 index_cdata(tinfo, ctrl, ptr->children, recWord);
374
375                 recWord->index_type = prev_type;     /* restore it again */
376             }
377         }
378     }
379 }
380
381 static void index_record(struct filter_xslt_info *tinfo,struct recExtractCtrl *ctrl,
382                          xmlNodePtr ptr, RecWord *recWord)
383 {
384     if (ptr && ptr->type == XML_ELEMENT_NODE && ptr->ns &&
385         !XML_STRCMP(ptr->ns->href, zebra_xslt_ns)
386         && !XML_STRCMP(ptr->name, "record"))
387     {
388         const char *type_str = "update";
389         const char *id_str = 0;
390         const char *rank_str = 0;
391         struct _xmlAttr *attr;
392         for (attr = ptr->properties; attr; attr = attr->next)
393         {
394             attr_content(attr, "type", &type_str);
395             attr_content(attr, "id", &id_str);
396             attr_content(attr, "rank", &rank_str);
397         }
398         if (id_str)
399             sscanf(id_str, "%255s", ctrl->match_criteria);
400         if (rank_str)
401         {
402             ctrl->staticrank = atoi(rank_str);
403             yaz_log(YLOG_LOG, "rank=%d",ctrl->staticrank);
404         }
405         else
406             yaz_log(YLOG_LOG, "no rank");
407         
408         ptr = ptr->children;
409     }
410     index_node(tinfo, ctrl, ptr, recWord);
411 }
412     
413 static int extract_doc(struct filter_xslt_info *tinfo, struct recExtractCtrl *p,
414                        xmlDocPtr doc)
415 {
416     RecWord recWord;
417     const char *params[10];
418     xmlChar *buf_out;
419     int len_out;
420
421     struct filter_xslt_schema *schema = lookup_schema(tinfo, zebra_xslt_ns);
422
423     params[0] = 0;
424     set_param_str(params, "schema", zebra_xslt_ns, tinfo->odr);
425
426     (*p->init)(p, &recWord);
427
428     if (schema && schema->stylesheet_xsp)
429     {
430         xmlNodePtr root_ptr;
431         xmlDocPtr resDoc = 
432             xsltApplyStylesheet(schema->stylesheet_xsp,
433                                 doc, params);
434         if (p->flagShowRecords)
435         {
436             xmlDocDumpMemory(resDoc, &buf_out, &len_out);
437             fwrite(buf_out, len_out, 1, stdout);
438             xmlFree(buf_out);
439         }
440         root_ptr = xmlDocGetRootElement(resDoc);
441         if (root_ptr)
442             index_record(tinfo, p, root_ptr, &recWord);
443         else
444         {
445             yaz_log(YLOG_WARN, "No root for index XML record."
446                     " split_level=%s stylesheet=%s",
447                     tinfo->split_level, schema->stylesheet);
448         }
449         xmlFreeDoc(resDoc);
450     }
451     xmlDocDumpMemory(doc, &buf_out, &len_out);
452     if (p->flagShowRecords)
453         fwrite(buf_out, len_out, 1, stdout);
454     (*p->setStoreData)(p, buf_out, len_out);
455     xmlFree(buf_out);
456     
457     xmlFreeDoc(doc);
458     return RECCTRL_EXTRACT_OK;
459 }
460
461 static int extract_split(struct filter_xslt_info *tinfo, struct recExtractCtrl *p)
462 {
463     int ret;
464     int split_depth = 0;
465     if (p->first_record)
466     {
467         if (tinfo->reader)
468             xmlFreeTextReader(tinfo->reader);
469         tinfo->reader = xmlReaderForIO(ioread_ex, ioclose_ex,
470                                        p /* I/O handler */,
471                                        0 /* URL */, 
472                                        0 /* encoding */,
473                                        XML_PARSE_XINCLUDE);
474     }
475     if (!tinfo->reader)
476         return RECCTRL_EXTRACT_ERROR_GENERIC;
477
478     if (tinfo->split_level)
479         split_depth = atoi(tinfo->split_level);
480     ret = xmlTextReaderRead(tinfo->reader);
481     while (ret == 1) {
482         int type = xmlTextReaderNodeType(tinfo->reader);
483         int depth = xmlTextReaderDepth(tinfo->reader);
484         if (split_depth == 0 ||
485             (split_depth > 0 &&
486              type == XML_READER_TYPE_ELEMENT && split_depth == depth))
487         {
488             xmlNodePtr ptr = xmlTextReaderExpand(tinfo->reader);
489             xmlNodePtr ptr2 = xmlCopyNode(ptr, 1);
490             xmlDocPtr doc = xmlNewDoc((const xmlChar*) "1.0");
491
492             xmlDocSetRootElement(doc, ptr2);
493
494             return extract_doc(tinfo, p, doc);   
495         }
496         ret = xmlTextReaderRead(tinfo->reader);
497     }
498     xmlFreeTextReader(tinfo->reader);
499     tinfo->reader = 0;
500     return RECCTRL_EXTRACT_EOF;
501 }
502
503 static int extract_full(struct filter_xslt_info *tinfo, struct recExtractCtrl *p)
504 {
505     if (p->first_record) /* only one record per stream */
506     {
507         xmlDocPtr doc = xmlReadIO(ioread_ex, ioclose_ex, p /* I/O handler */,
508                                   0 /* URL */,
509                                   0 /* encoding */,
510                                   XML_PARSE_XINCLUDE);
511         if (!doc)
512         {
513             return RECCTRL_EXTRACT_ERROR_GENERIC;
514         }
515         return extract_doc(tinfo, p, doc);
516     }
517     else
518         return RECCTRL_EXTRACT_EOF;
519 }
520
521 static int filter_extract(void *clientData, struct recExtractCtrl *p)
522 {
523     struct filter_xslt_info *tinfo = clientData;
524
525     odr_reset(tinfo->odr);
526
527     if (tinfo->split_level == 0 && tinfo->split_path == 0)
528         return extract_full(tinfo, p);
529     else
530     {
531         return extract_split(tinfo, p);
532     }
533 }
534
535 static int ioread_ret(void *context, char *buffer, int len)
536 {
537     struct recRetrieveCtrl *p = context;
538     return (*p->readf)(p->fh, buffer, len);
539 }
540
541 static int ioclose_ret(void *context)
542 {
543     return 0;
544 }
545
546
547 static const char *snippet_doc(struct recRetrieveCtrl *p, int text_mode,
548                                int window_size)
549 {
550     const char *xml_doc_str;
551     int ord = 0;
552     WRBUF wrbuf = wrbuf_alloc();
553     zebra_snippets *res = 
554         zebra_snippets_window(p->doc_snippet, p->hit_snippet, window_size);
555     zebra_snippet_word *w = zebra_snippets_list(res);
556
557     if (text_mode)
558         wrbuf_printf(wrbuf, "\'");
559     else
560         wrbuf_printf(wrbuf, "<snippet xmlns='%s'>\n", zebra_xslt_ns);
561     for (; w; w = w->next)
562     {
563         if (ord == 0)
564             ord = w->ord;
565         else if (ord != w->ord)
566
567             break;
568         if (text_mode)
569             wrbuf_printf(wrbuf, "%s%s%s ", 
570                          w->match ? "*" : "",
571                          w->term,
572                          w->match ? "*" : "");
573         else
574         {
575             wrbuf_printf(wrbuf, " <term ord='%d' seqno='" ZINT_FORMAT "' %s>", 
576                          w->ord, w->seqno,
577                          (w->match ? "match='1'" : ""));
578             wrbuf_xmlputs(wrbuf, w->term);
579             wrbuf_printf(wrbuf, "</term>\n");
580         }
581     }
582     if (text_mode)
583         wrbuf_printf(wrbuf, "\'");
584     else
585         wrbuf_printf(wrbuf, "</snippet>\n");
586
587     xml_doc_str = odr_strdup(p->odr, wrbuf_buf(wrbuf));
588
589     zebra_snippets_destroy(res);
590     wrbuf_free(wrbuf, 1);
591     return xml_doc_str;
592 }
593
594 static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p)
595 {
596     const char *esn = zebra_xslt_ns;
597     const char *params[20];
598     struct filter_xslt_info *tinfo = clientData;
599     xmlDocPtr resDoc;
600     xmlDocPtr doc;
601     struct filter_xslt_schema *schema;
602     int window_size = -1;
603
604     if (p->comp)
605     {
606         if (p->comp->which == Z_RecordComp_simple
607             && p->comp->u.simple->which == Z_ElementSetNames_generic)
608         {
609             esn = p->comp->u.simple->u.generic;
610         }
611         else if (p->comp->which == Z_RecordComp_complex 
612                  && p->comp->u.complex->generic->elementSpec
613                  && p->comp->u.complex->generic->elementSpec->which ==
614                  Z_ElementSpec_elementSetName)
615         {
616             esn = p->comp->u.complex->generic->elementSpec->u.elementSetName;
617         }
618     }
619     schema = lookup_schema(tinfo, esn);
620     if (!schema)
621     {
622         p->diagnostic =
623             YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_;
624         return 0;
625     }
626
627     if (schema->include_snippet)
628         window_size = atoi(schema->include_snippet);
629
630     params[0] = 0;
631     set_param_int(params, "id", p->localno, p->odr);
632     if (p->fname)
633         set_param_str(params, "filename", p->fname, p->odr);
634     if (p->staticrank >= 0)
635         set_param_int(params, "rank", p->staticrank, p->odr);
636     set_param_str(params, "schema", esn, p->odr);
637     if (p->score >= 0)
638         set_param_int(params, "score", p->score, p->odr);
639     set_param_int(params, "size", p->recordSize, p->odr);
640
641     if (window_size >= 0)
642         set_param_xml(params, "snippet", snippet_doc(p, 1, window_size),
643                       p->odr);
644     doc = xmlReadIO(ioread_ret, ioclose_ret, p /* I/O handler */,
645                     0 /* URL */,
646                     0 /* encoding */,
647                     XML_PARSE_XINCLUDE);
648     if (!doc)
649     {
650         p->diagnostic = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
651         return 0;
652     }
653
654     if (window_size >= 0)
655     {
656         xmlNodePtr node = xmlDocGetRootElement(doc);
657         const char *snippet_str = snippet_doc(p, 0, window_size);
658         xmlDocPtr snippet_doc = xmlParseMemory(snippet_str, strlen(snippet_str));
659         xmlAddChild(node, xmlDocGetRootElement(snippet_doc));
660     }
661     if (!schema->stylesheet_xsp)
662         resDoc = doc;
663     else
664     {
665         resDoc = xsltApplyStylesheet(schema->stylesheet_xsp,
666                                      doc, params);
667         xmlFreeDoc(doc);
668     }
669     if (!resDoc)
670     {
671         p->diagnostic = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
672     }
673     else if (p->input_format == VAL_NONE || p->input_format == VAL_TEXT_XML)
674     {
675         xmlChar *buf_out;
676         int len_out;
677         xmlDocDumpMemory(resDoc, &buf_out, &len_out);
678
679         p->output_format = VAL_TEXT_XML;
680         p->rec_len = len_out;
681         p->rec_buf = odr_malloc(p->odr, p->rec_len);
682         memcpy(p->rec_buf, buf_out, p->rec_len);
683         
684         xmlFree(buf_out);
685     }
686     else if (p->output_format == VAL_SUTRS)
687     {
688         xmlChar *buf_out;
689         int len_out;
690         xmlDocDumpMemory(resDoc, &buf_out, &len_out);
691
692         p->output_format = VAL_SUTRS;
693         p->rec_len = len_out;
694         p->rec_buf = odr_malloc(p->odr, p->rec_len);
695         memcpy(p->rec_buf, buf_out, p->rec_len);
696         
697         xmlFree(buf_out);
698     }
699     else
700     {
701         p->diagnostic = YAZ_BIB1_RECORD_SYNTAX_UNSUPP;
702     }
703     xmlFreeDoc(resDoc);
704     return 0;
705 }
706
707 static struct recType filter_type = {
708     0,
709     "xslt",
710     filter_init,
711     filter_config,
712     filter_destroy,
713     filter_extract,
714     filter_retrieve
715 };
716
717 RecType
718 #ifdef IDZEBRA_STATIC_XSLT
719 idzebra_filter_xslt
720 #else
721 idzebra_filter
722 #endif
723
724 [] = {
725     &filter_type,
726     0,
727 };
728 /*
729  * Local variables:
730  * c-basic-offset: 4
731  * indent-tabs-mode: nil
732  * End:
733  * vim: shiftwidth=4 tabstop=8 expandtab
734  */
735