22 #include <yaz/yaz-util.h>
34 #include <libxslt/xslt.h>
35 #include <libxslt/transform.h>
52 NMEM nmem = nmem_create();
65 xmlDoc *xsp_doc = xmlParseMemory(spec, strlen(spec));
71 *m = nmem_malloc(nt->
nmem,
sizeof(**m));
73 (*m)->stylesheet1 = NULL;
74 (*m)->stylesheet2 = NULL;
77 (*m)->stylesheet1 = xsltParseStylesheetDoc(xsp_doc);
78 if (!(*m)->stylesheet1)
88 nmem_strsplit(nt->
nmem,
",", spec, &stylesheets, &num);
90 for (i = 0; i < num; i++)
92 *m = nmem_malloc(nt->
nmem,
sizeof(**m));
94 (*m)->stylesheet1 = NULL;
96 if ((*m)->stylesheet2)
98 else if (!strcmp(&stylesheets[i][strlen(stylesheets[i])-4],
".xsl"))
101 if (!((*m)->stylesheet1 =
102 xsltParseStylesheetFile((xmlChar *) wrbuf_cstr(fname))))
104 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"Unable to load stylesheet: %s",
108 wrbuf_destroy(fname);
110 else if (!strcmp(&stylesheets[i][strlen(stylesheets[i])-5],
".mmap"))
115 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"Unable to load marcmap: %s",
119 wrbuf_destroy(fname);
123 yaz_log(YLOG_FATAL,
"Cannot handle stylesheet: %s", stylesheets[i]);
149 nmem_destroy(nt->
nmem);
164 ndoc = xsltApplyStylesheet(m->
stylesheet1, *doc, parms);
166 ndoc = xsltApplyStylesheet(m->
stylesheet2, *doc, parms);
175 root = xmlDocGetRootElement(ndoc);
177 if (ndoc && root && root->children)
182 yaz_log(YLOG_WARN,
"XSLT produced no document");
184 yaz_log(YLOG_WARN,
"XSLT produced XML with no root node");
185 else if (!root->children)
186 yaz_log(YLOG_WARN,
"XSLT produced XML with no root children nodes");
struct marcmap * marcmap_load(const char *filename, NMEM nmem)
xmlDoc * marcmap_apply(struct marcmap *marcmap, xmlDoc *xml_in)
int normalize_record_transform(normalize_record_t nt, xmlDoc **doc, const char **parms)
void normalize_record_destroy(normalize_record_t nt)
normalize_record_t normalize_record_create(struct conf_service *service, const char *spec)
WRBUF conf_get_fname(struct conf_config *config, const char *fname)
xsltStylesheetPtr service_xslt_get(struct conf_service *service, const char *id)
struct conf_config * config
struct conf_server * server
struct normalize_step * steps
xsltStylesheet * stylesheet1
struct normalize_step * next
xsltStylesheet * stylesheet2