1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2012 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/tpath.h>
34 #include <yaz/xml_include.h>
36 #include "service_xslt.h"
37 #include "pazpar2_config.h"
42 xsltStylesheetPtr xsp;
43 struct service_xslt *next;
46 xsltStylesheetPtr service_xslt_get(struct conf_service *service,
49 struct service_xslt *sx;
50 for (sx = service->xslt_list; sx; sx = sx->next)
51 if (!strcmp(id, sx->id))
56 void service_xslt_destroy(struct conf_service *service)
58 struct service_xslt *sx = service->xslt_list;
59 for (; sx; sx = sx->next)
60 xsltFreeStylesheet(sx->xsp);
63 int service_xslt_config(struct conf_service *service, xmlNode *n)
66 xmlNode *root = n->children;
67 struct service_xslt *sx;
69 struct _xmlAttr *attr;
70 for (attr = n->properties; attr; attr = attr->next)
71 if (!strcmp((const char *) attr->name, "id"))
72 id = (const char *) attr->children->content;
75 yaz_log(YLOG_FATAL, "Invalid attribute %s for xslt element",
76 (const char *) attr->name);
81 yaz_log(YLOG_FATAL, "Missing attribute id for xslt element");
84 while (root && root->type != XML_ELEMENT_NODE)
88 yaz_log(YLOG_FATAL, "Missing content for xslt element");
91 for (sx = service->xslt_list; sx; sx = sx->next)
92 if (!strcmp(sx->id, id))
94 yaz_log(YLOG_FATAL, "Multiple xslt with id=%s", id);
98 sx = nmem_malloc(service->nmem, sizeof(*sx));
99 sx->id = nmem_strdup(service->nmem, id);
100 sx->next = service->xslt_list;
101 service->xslt_list = sx;
103 xsp_doc = xmlNewDoc(BAD_CAST "1.0");
104 xmlDocSetRootElement(xsp_doc, xmlCopyNode(root, 1));
105 sx->xsp = xsltParseStylesheetDoc(xsp_doc);
109 yaz_log(YLOG_FATAL, "Failed to parse XSLT");
118 * c-file-style: "Stroustrup"
119 * indent-tabs-mode: nil
121 * vim: shiftwidth=4 tabstop=8 expandtab