-/*
- * Copyright (C) 2005-2007, Index Data ApS
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2008 Index Data
* See the file LICENSE for details.
- *
- * $Id: record_conv.c,v 1.16 2007-05-06 20:12:20 adam Exp $
*/
/**
* \file record_conv.c
#include <yaz/xmalloc.h>
#include <yaz/nmem.h>
#include <yaz/tpath.h>
+#include <yaz/z-opac.h>
#if YAZ_HAVE_XML2
#include <libxml/parser.h>
if (!yaz_filepath_resolve(stylesheet, p->path, 0, fullpath))
{
wrbuf_printf(p->wr_error, "Element <xslt stylesheet=\"%s\"/>:"
- " could not locate stylesheet '%s' with path '%s'",
- stylesheet, fullpath, p->path);
+ " could not locate stylesheet '%s'",
+ stylesheet, fullpath);
+ if (p->path)
+ wrbuf_printf(p->wr_error, " with path '%s'", p->path);
+
return -1;
}
xsp = xsltParseStylesheetFile((xmlChar*) fullpath);
if (!xsp)
{
- wrbuf_printf(p->wr_error, "Element <xslt stylesheet=\"%s\"/>:"
- " parsing stylesheet '%s' with path '%s' failed,"
+ wrbuf_printf(p->wr_error, "Element: <xslt stylesheet=\"%s\"/>:"
+ " xslt parse failed: %s", stylesheet, fullpath);
+ if (p->path)
+ wrbuf_printf(p->wr_error, " with path '%s'", p->path);
+ wrbuf_printf(p->wr_error, " ("
#if YAZ_HAVE_EXSLT
- " EXSLT enabled",
+
+ "EXSLT enabled"
#else
- " EXSLT not supported",
+ "EXSLT not supported"
#endif
- stylesheet, fullpath, p->path);
+ ")");
return -1;
}
else
return 0;
}
+static int yaz_record_conv_record_rule(yaz_record_conv_t p,
+ struct yaz_record_conv_rule *r,
+ const char *input_record_buf,
+ size_t input_record_len,
+ WRBUF output_record);
+
+int yaz_record_conv_opac_record(yaz_record_conv_t p,
+ Z_OPACRecord *input_record,
+ WRBUF output_record)
+{
+ int ret = 0;
+ struct yaz_record_conv_rule *r = p->rules;
+ WRBUF res = wrbuf_alloc();
+ yaz_marc_t mt = yaz_marc_create();
+
+ wrbuf_rewind(p->wr_error);
+ yaz_marc_xml(mt, r->u.marc.output_format);
+ if (r->u.marc.iconv_t)
+ yaz_marc_iconv(mt, r->u.marc.iconv_t);
+ yaz_opac_decode_wrbuf(mt, input_record, res);
+ if (ret != -1)
+ {
+ ret = yaz_record_conv_record_rule(p,
+ r->next,
+ wrbuf_buf(res), wrbuf_len(res),
+ output_record);
+ }
+ yaz_marc_destroy(mt);
+ wrbuf_destroy(res);
+ return ret;
+}
+
int yaz_record_conv_record(yaz_record_conv_t p,
const char *input_record_buf,
size_t input_record_len,
WRBUF output_record)
{
+ return yaz_record_conv_record_rule(p, p->rules,
+ input_record_buf,
+ input_record_len, output_record);
+}
+
+static int yaz_record_conv_record_rule(yaz_record_conv_t p,
+ struct yaz_record_conv_rule *r,
+ const char *input_record_buf,
+ size_t input_record_len,
+ WRBUF output_record)
+{
int ret = 0;
WRBUF record = output_record; /* pointer transfer */
- struct yaz_record_conv_rule *r = p->rules;
wrbuf_rewind(p->wr_error);
wrbuf_write(record, input_record_buf, input_record_len);