+ if (!XML_STRCMP(attr->name, name) && attr->children &&
+ attr->children->type == XML_TEXT_NODE)
+ {
+ *dst_content = (const char *)(attr->children->content);
+ return 1;
+ }
+ return 0;
+}
+
+static void destroy_schemas(struct filter_xslt_info *tinfo)
+{
+ struct filter_xslt_schema *schema = tinfo->schemas;
+ while (schema)
+ {
+ struct filter_xslt_schema *schema_next = schema->next;
+ if (schema->stylesheet_xsp)
+ xsltFreeStylesheet(schema->stylesheet_xsp);
+ xfree(schema);
+ schema = schema_next;
+ }
+ tinfo->schemas = 0;
+ xfree(tinfo->fname);
+ if (tinfo->doc)
+ xmlFreeDoc(tinfo->doc);
+ tinfo->doc = 0;
+}
+
+static ZEBRA_RES create_schemas(struct filter_xslt_info *tinfo,
+ const char *fname)
+{
+ char tmp_full_name[1024];
+ xmlNodePtr ptr;
+ tinfo->fname = xstrdup(fname);
+
+ if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path,
+ NULL, tmp_full_name))
+ tinfo->full_name = xstrdup(tmp_full_name);
+ else
+ tinfo->full_name = xstrdup(tinfo->fname);
+
+ yaz_log(YLOG_LOG, "xslt filter: loading config file %s", tinfo->full_name);
+
+ tinfo->doc = xmlParseFile(tinfo->full_name);
+ if (!tinfo->doc) {
+ yaz_log(YLOG_WARN, "xslt filter: could not parse config file %s",
+ tinfo->full_name);
+ return ZEBRA_FAIL;
+ }
+
+ ptr = xmlDocGetRootElement(tinfo->doc);
+ if (!ptr || ptr->type != XML_ELEMENT_NODE ||
+ XML_STRCMP(ptr->name, "schemaInfo")){
+ yaz_log(YLOG_WARN,
+ "xslt filter: config file %s :"
+ " expected root element <schemaInfo>",
+ tinfo->full_name);
+ return ZEBRA_FAIL;
+ }
+
+ for (ptr = ptr->children; ptr; ptr = ptr->next)
+ {
+ if (ptr->type != XML_ELEMENT_NODE)
+ continue;
+ if (!XML_STRCMP(ptr->name, "schema"))
+ {
+ char tmp_xslt_full_name[1024];
+ struct _xmlAttr *attr;
+ struct filter_xslt_schema *schema = xmalloc(sizeof(*schema));
+ schema->name = 0;
+ schema->identifier = 0;
+ schema->stylesheet = 0;
+ schema->default_schema = 0;
+ schema->next = tinfo->schemas;
+ schema->stylesheet_xsp = 0;
+ schema->include_snippet = 0;
+ tinfo->schemas = schema;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ attr_content(attr, "identifier", &schema->identifier);
+ attr_content(attr, "name", &schema->name);
+ attr_content(attr, "stylesheet", &schema->stylesheet);
+ 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);
+ schema->stylesheet_xsp
+ = xsltParseStylesheetFile((const xmlChar*) tmp_xslt_full_name);
+ if (!schema->stylesheet_xsp)
+ yaz_log(YLOG_WARN,
+ "xslt filter: could not parse xslt stylesheet %s",
+ tmp_xslt_full_name);
+ }
+
+ }
+ else if (!XML_STRCMP(ptr->name, "split"))
+ {
+ struct _xmlAttr *attr;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ attr_content(attr, "level", &tinfo->split_level);
+ attr_content(attr, "path", &tinfo->split_path);
+ }
+ }
+ else
+ {
+ yaz_log(YLOG_WARN, "Bad element %s in %s", ptr->name, fname);
+ return ZEBRA_FAIL;
+ }
+ }
+ return ZEBRA_OK;