+int Yaz_Proxy::convert_xsl(Z_NamePlusRecordList *p, Z_APDU *apdu)
+{
+ if (!m_stylesheet_xsp || p->num_records <= 0)
+ return 0; /* no XSLT to be done ... */
+
+ m_stylesheet_offset = 0;
+ m_stylesheet_nprl = p;
+ m_stylesheet_apdu = apdu;
+ timeout(0);
+ return 1;
+}
+
+void Yaz_Proxy::convert_xsl_delay()
+{
+ Z_NamePlusRecord *npr = m_stylesheet_nprl->records[m_stylesheet_offset];
+ if (npr->which == Z_NamePlusRecord_databaseRecord)
+ {
+ Z_External *r = npr->u.databaseRecord;
+ if (r->which == Z_External_octet)
+ {
+#if 0
+ fwrite((char*) r->u.octet_aligned->buf, 1, r->u.octet_aligned->len, stdout);
+#endif
+ xmlDocPtr res, doc = xmlParseMemory(
+ (char*) r->u.octet_aligned->buf,
+ r->u.octet_aligned->len);
+
+
+ yaz_log(LOG_LOG, "%sXSLT convert %d",
+ m_session_str, m_stylesheet_offset);
+ res = xsltApplyStylesheet(m_stylesheet_xsp, doc, 0);
+
+ if (res)
+ {
+ xmlChar *out_buf;
+ int out_len;
+ xmlDocDumpFormatMemory (res, &out_buf, &out_len, 1);
+
+ m_stylesheet_nprl->records[m_stylesheet_offset]->
+ u.databaseRecord =
+ z_ext_record(odr_encode(), VAL_TEXT_XML,
+ (char*) out_buf, out_len);
+ xmlFree(out_buf);
+ xmlFreeDoc(res);
+ }
+
+ xmlFreeDoc(doc);
+ }
+ }
+ m_stylesheet_offset++;
+ if (m_stylesheet_offset == m_stylesheet_nprl->num_records)
+ {
+ m_stylesheet_nprl = 0;
+ if (m_stylesheet_xsp)
+ xsltFreeStylesheet(m_stylesheet_xsp);
+ m_stylesheet_xsp = 0;
+ timeout(m_client_idletime);
+ send_PDU_convert(m_stylesheet_apdu);
+ }
+ else
+ timeout(0);
+}
+