[xslt] please help. problem with output buffers



hello

I have the following code: (problem description below the code)

---------
......
int xml_output_write_callback(void * context, const char *buffer, int len) {
	char tmp[5000];

/* 	printf("xml output write callback\n"); */
/* 	printf("len:%d\n", len); */
	if (len > 0) {
		snprintf(tmp, len + 1, "%s", buffer);
		tmp[len] = '\0';
		//printf("%s", tmp);
		return(len);
	}
	return(0);
}

int transform(char *xslFile, char *xmlFile) {
	int se;
	xsltStylesheetPtr cur = NULL;
	xmlDocPtr xsldoc = NULL, doc = NULL, res = NULL;
	xmlOutputBufferPtr buf;
	int bytes;
    
	doc = xmlParseFile(xmlFile);
	xsldoc = xmlParseFile(xslFile);
        
    cur = xsltParseStylesheetDoc(xsldoc);
    if (cur == NULL) {
		xmlFreeDoc(xsldoc);
		return 1;
    }
    
    res = xsltApplyStylesheet(cur, doc, NULL);
    
    if (res != NULL) {
		buf = xmlOutputBufferCreateIO(xml_output_write_callback, 
		xml_output_close_callback, NULL, NULL);
		if (buf != NULL) {
			bytes = xsltSaveResultTo(buf, res, cur);
			printf("content: %s\n", buf->buffer->content);
			printf("size:    %d\n", buf->buffer->size);
			printf("use:     %d\n", buf->buffer->use);
			printf("written: %d\n", buf->written);
			printf("bytes:   %d\n", bytes);
		}
		else printf("Something is wrong");
    }
    xmlFreeDoc(doc);
    xmlFreeDoc(res);
    xsltFreeStylesheet(cur);
    
    return 0;
}
........
----

the output is the following:
content: 
size:    4000
use:     0
written: 3136
bytes:   3136


why is "content" empty and "use" == 0
when I print the variable "tmp" in the function "xml_output_write_callback" 
the correct result of the XSLT transformation is printed.

can somebody tell me, what wrong here??

thanks
markus








[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]