* Copyright (C) 2005-2006, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: record_conv.c,v 1.8 2006-05-08 16:58:25 quinn Exp $
+ * $Id: record_conv.c,v 1.11 2006-07-06 10:17:53 adam Exp $
*/
/**
* \file record_conv.c
#include <yaz/nmem.h>
#include <yaz/tpath.h>
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xinclude.h>
-#if HAVE_XSLT
+#if YAZ_HAVE_XSLT
#include <libxslt/xsltutils.h>
#include <libxslt/transform.h>
#endif
-#if HAVE_EXSLT
+#if YAZ_HAVE_EXSLT
#include <libexslt/exslt.h>
#endif
struct yaz_record_conv_rule {
enum YAZ_RECORD_CONV_RULE which;
union {
-#if HAVE_XSLT
+#if YAZ_HAVE_XSLT
struct {
xsltStylesheetPtr xsp;
} xslt;
if (r->u.marc.iconv_t)
yaz_iconv_close(r->u.marc.iconv_t);
}
-#if HAVE_XSLT
+#if YAZ_HAVE_XSLT
else if (r->which == YAZ_RECORD_CONV_RULE_XSLT)
{
xsltFreeStylesheet(r->u.xslt.xsp);
p->rules = 0;
p->path = 0;
-#if HAVE_EXSLT
+#if YAZ_HAVE_EXSLT
exsltRegisterAll();
#endif
yaz_record_conv_reset(p);
/** \brief parse 'xslt' conversion node */
static int conv_xslt(yaz_record_conv_t p, const xmlNode *ptr)
{
-#if HAVE_XSLT
+#if YAZ_HAVE_XSLT
struct _xmlAttr *attr;
const char *stylesheet = 0;
}
else if (!strcmp((const char *) ptr->name, "exslt"))
{
-#if HAVE_EXSLT
+#if YAZ_HAVE_EXSLT
if (conv_xslt(p, ptr))
return -1;
#else
}
yaz_marc_destroy(mt);
}
-#if HAVE_XSLT
+#if YAZ_HAVE_XSLT
else if (r->which == YAZ_RECORD_CONV_RULE_XSLT)
{
xmlDocPtr doc = xmlParseMemory(wrbuf_buf(record),
xmlDocPtr res = xsltApplyStylesheet(r->u.xslt.xsp, doc, 0);
if (res)
{
- xmlChar *out_buf;
+ xmlChar *out_buf = 0;
int out_len;
- xmlDocDumpFormatMemory (res, &out_buf, &out_len, 1);
-
- wrbuf_rewind(record);
- wrbuf_write(record, (const char *) out_buf, out_len);
- xmlFree(out_buf);
+#if YAZ_HAVE_XSLTSAVERESULTTOSTRING
+ xsltSaveResultToString(&out_buf, &out_len, res,
+ r->u.xslt.xsp);
+#else
+ xmlDocDumpFormatMemory (res, &out_buf, &out_len, 1);
+#endif
+ if (!out_buf)
+ {
+ wrbuf_printf(p->wr_error,
+ "xsltSaveResultToString failed");
+ ret = -1;
+ }
+ else
+ {
+ wrbuf_rewind(record);
+ wrbuf_write(record, (const char *) out_buf, out_len);
+
+ xmlFree(out_buf);
+ }
xmlFreeDoc(res);
}
else
{
- wrbuf_printf(p->wr_error, "xsltApplyStylesheet faailed");
+ wrbuf_printf(p->wr_error, "xsltApplyStylesheet failed");
ret = -1;
}
xmlFreeDoc(doc);