1 /* This file is part of Pazpar2.
2 Copyright (C) Index Data
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <libxml/parser.h>
28 #include <libxml/tree.h>
30 #include <yaz/yaz-util.h>
32 #include <yaz/snprintf.h>
33 #include <yaz/xml_include.h>
35 #include "service_xslt.h"
36 #include "pazpar2_config.h"
41 xsltStylesheetPtr xsp;
42 struct service_xslt *next;
45 xsltStylesheetPtr service_xslt_get(struct conf_service *service,
48 struct service_xslt *sx;
49 for (sx = service->xslt_list; sx; sx = sx->next)
50 if (!strcmp(id, sx->id))
55 void service_xslt_destroy(struct conf_service *service)
57 struct service_xslt *sx = service->xslt_list;
58 for (; sx; sx = sx->next)
59 xsltFreeStylesheet(sx->xsp);
62 int service_xslt_config(struct conf_service *service, xmlNode *n)
65 xmlNode *root = n->children;
66 struct service_xslt *sx;
68 struct _xmlAttr *attr;
69 for (attr = n->properties; attr; attr = attr->next)
70 if (!strcmp((const char *) attr->name, "id"))
71 id = (const char *) attr->children->content;
74 yaz_log(YLOG_FATAL, "Invalid attribute %s for xslt element",
75 (const char *) attr->name);
80 yaz_log(YLOG_FATAL, "Missing attribute id for xslt element");
83 while (root && root->type != XML_ELEMENT_NODE)
87 yaz_log(YLOG_FATAL, "Missing content for xslt element");
90 for (sx = service->xslt_list; sx; sx = sx->next)
91 if (!strcmp(sx->id, id))
93 yaz_log(YLOG_FATAL, "Multiple xslt with id=%s", id);
97 sx = nmem_malloc(service->nmem, sizeof(*sx));
98 sx->id = nmem_strdup(service->nmem, id);
99 sx->next = service->xslt_list;
100 service->xslt_list = sx;
102 xsp_doc = xmlNewDoc(BAD_CAST "1.0");
103 xmlDocSetRootElement(xsp_doc, xmlCopyNode(root, 1));
104 sx->xsp = xsltParseStylesheetDoc(xsp_doc);
108 yaz_log(YLOG_FATAL, "Failed to parse XSLT");
117 * c-file-style: "Stroustrup"
118 * indent-tabs-mode: nil
120 * vim: shiftwidth=4 tabstop=8 expandtab