+// Prepare XSLT stylesheets for record normalization
+// Structures are allocated on the session_wide nmem to avoid having
+// to recompute this for every search. This would lead
+// to leaking if a single session was to repeatedly change the PZ_XSLT
+// setting. However, this is not a realistic use scenario.
+static int prepare_map(struct session *se, struct session_database *sdb)
+{
+ struct setting *s;
+
+ if (!sdb->settings)
+ {
+ yaz_log(YLOG_WARN, "No settings on %s", sdb->database->url);
+ return -1;
+ }
+ if ((s = sdb->settings[PZ_XSLT]))
+ {
+ char **stylesheets;
+ struct database_retrievalmap **m = &sdb->map;
+ int num, i;
+
+ nmem_strsplit(se->session_nmem, ",", s->value, &stylesheets, &num);
+ for (i = 0; i < num; i++)
+ {
+ (*m) = nmem_malloc(se->session_nmem, sizeof(**m));
+ (*m)->next = 0;
+ if (!((*m)->stylesheet = conf_load_stylesheet(stylesheets[i])))
+ {
+ yaz_log(YLOG_FATAL, "Unable to load stylesheet: %s",
+ stylesheets[i]);
+ return -1;
+ }
+ m = &(*m)->next;
+ }
+ }
+ if (!sdb->map)
+ yaz_log(YLOG_WARN, "No Normalization stylesheet for target %s",
+ sdb->database->url);
+ return 0;
+}
+