xslt.c 1.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#include <string.h>
#include <libxml/xmlmemory.h>
#include <libxml/debugXML.h>
#include <libxml/HTMLtree.h>
#include <libxml/xmlIO.h>
#include <libxml/DOCBparser.h>
#include <libxml/xinclude.h>
#include <libxml/catalog.h>
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>


#include <thread/thread.h>
#include <avl/avl.h>
#include <httpp/httpp.h>
#include <net/sock.h>


#include "connection.h"

#include "global.h"
#include "refbuf.h"
#include "client.h"
#include "stats.h"


void transformXSLT(xmlDocPtr doc, char *xslfilename, client_t *client)
{
    xmlOutputBufferPtr outputBuffer;
	xmlDocPtr	res;
	xsltStylesheetPtr cur;
	const char *params[16 + 1];
    size_t count,nBytes;

	params[0] = NULL;

	xmlSubstituteEntitiesDefault(1);
	xmlLoadExtDtdDefaultValue = 1;

	cur = xsltParseStylesheetFile(xslfilename);
	if (cur == NULL) {
		sock_write_string(client->con->sock, (char *)"Could not parse XSLT file");
        return;
	}

    res = xsltApplyStylesheet(cur, doc, params);

    outputBuffer = xmlAllocOutputBuffer(NULL);

    count = xsltSaveResultTo(outputBuffer, res, cur);

    /*  Add null byte to end. */
    nBytes = xmlOutputBufferWrite(outputBuffer, 1, "");

	sock_write_string(client->con->sock, (char *)outputBuffer->buffer->content);

    xmlFree(outputBuffer);
    xsltFreeStylesheet(cur);
    xmlFreeDoc(res);

    xsltCleanupGlobals(); /* Neccesary? */
}