X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Frecord_conv.c;h=9da5a448ea9f4950b596e56eb102c2c8b74535cd;hp=fd250e5bb7b84af1b17f73cf2c556d4198181c04;hb=a5795a2df2095d5a44b012a59426e7b906db3ec9;hpb=91a490267e60208ff28e53a397e261956c4adc59 diff --git a/src/record_conv.c b/src/record_conv.c index fd250e5..9da5a44 100644 --- a/src/record_conv.c +++ b/src/record_conv.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2008 Index Data + * Copyright (C) 1995-2010 Index Data * See the file LICENSE for details. */ /** @@ -58,14 +58,13 @@ enum YAZ_RECORD_CONV_RULE YAZ_RECORD_CONV_RULE_MARC }; - /** \brief tranformation info (rule info) */ struct yaz_record_conv_rule { enum YAZ_RECORD_CONV_RULE which; union { #if YAZ_HAVE_XSLT struct { - xsltStylesheetPtr xsp; + xmlDocPtr xsp_doc; } xslt; #endif struct { @@ -92,7 +91,7 @@ static void yaz_record_conv_reset(yaz_record_conv_t p) #if YAZ_HAVE_XSLT else if (r->which == YAZ_RECORD_CONV_RULE_XSLT) { - xsltFreeStylesheet(r->u.xslt.xsp); + xmlFreeDoc(r->u.xslt.xsp_doc); } #endif } @@ -173,6 +172,7 @@ static int conv_xslt(yaz_record_conv_t p, const xmlNode *ptr) { char fullpath[1024]; xsltStylesheetPtr xsp; + xmlDocPtr xsp_doc; if (!yaz_filepath_resolve(stylesheet, p->path, 0, fullpath)) { wrbuf_printf(p->wr_error, "Element :" @@ -183,7 +183,18 @@ static int conv_xslt(yaz_record_conv_t p, const xmlNode *ptr) return -1; } - xsp = xsltParseStylesheetFile((xmlChar*) fullpath); + xsp_doc = xmlParseFile(fullpath); + if (!xsp_doc) + { + wrbuf_printf(p->wr_error, "Element: :" + " xml parse failed: %s", stylesheet, fullpath); + if (p->path) + wrbuf_printf(p->wr_error, " with path '%s'", p->path); + return -1; + } + /* need to copy this before passing it to the processor. It will + be encapsulated in the xsp and destroyed by xsltFreeStylesheet */ + xsp = xsltParseStylesheetDoc(xmlCopyDoc(xsp_doc, 1)); if (!xsp) { wrbuf_printf(p->wr_error, "Element: :" @@ -198,13 +209,15 @@ static int conv_xslt(yaz_record_conv_t p, const xmlNode *ptr) "EXSLT not supported" #endif ")"); + xmlFreeDoc(xsp_doc); return -1; } else { struct yaz_record_conv_rule *r = add_rule(p, YAZ_RECORD_CONV_RULE_XSLT); - r->u.xslt.xsp = xsp; + r->u.xslt.xsp_doc = xsp_doc; + xsltFreeStylesheet(xsp); } } return 0; @@ -294,6 +307,12 @@ static int conv_marc(yaz_record_conv_t p, const xmlNode *ptr) if (input_charset && !output_charset) output_charset = "utf-8"; } + else if (!strcmp(output_format, "turbomarc")) + { + output_format_mode = YAZ_MARC_TURBOMARC; + if (input_charset && !output_charset) + output_charset = "utf-8"; + } else if (!strcmp(output_format, "marc")) { output_format_mode = YAZ_MARC_ISO2709; @@ -462,7 +481,8 @@ static int yaz_record_conv_record_rule(yaz_record_conv_t p, else ret = -1; } - else if (r->u.marc.input_format == YAZ_MARC_MARCXML) + else if (r->u.marc.input_format == YAZ_MARC_MARCXML || + r->u.marc.input_format == YAZ_MARC_TURBOMARC) { xmlDocPtr doc = xmlParseMemory(wrbuf_buf(record), wrbuf_len(record)); @@ -507,15 +527,16 @@ static int yaz_record_conv_record_rule(yaz_record_conv_t p, } else { - xmlDocPtr res = xsltApplyStylesheet(r->u.xslt.xsp, doc, 0); + xmlDocPtr xsp_doc = xmlCopyDoc(r->u.xslt.xsp_doc, 1); + xsltStylesheetPtr xsp = xsltParseStylesheetDoc(xsp_doc); + xmlDocPtr res = xsltApplyStylesheet(xsp, doc, 0); if (res) { xmlChar *out_buf = 0; int out_len; -#if YAZ_HAVE_XSLTSAVERESULTTOSTRING - xsltSaveResultToString(&out_buf, &out_len, res, - r->u.xslt.xsp); +#if HAVE_XSLTSAVERESULTTOSTRING + xsltSaveResultToString(&out_buf, &out_len, res, xsp); #else xmlDocDumpFormatMemory (res, &out_buf, &out_len, 1); #endif @@ -540,6 +561,7 @@ static int yaz_record_conv_record_rule(yaz_record_conv_t p, ret = -1; } xmlFreeDoc(doc); + xsltFreeStylesheet(xsp); /* frees xsp_doc too */ } } #endif @@ -564,6 +586,7 @@ void yaz_record_conv_set_path(yaz_record_conv_t p, const char *path) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab