Hi,
I'm looking for a XSL processor.
I'll explain in brief what is the problem at the moment.
The host i'm working on doesn't have the Sablotron installed and don't want to.
The problem is that i have to change some parameters in an XSL tamplate when parsed with an external XML file.
The parsing works, i've used the phplibxslt from http://nona.net/software/phplibxslt but now i face the problem that i can't send parameters from my PHP to the XLS when parsing it through.
Does anyone have a solution to this?
greetz
I need a XSL processor - sending parameters from PHP file
Moderator: General Moderators
if i read the php_libxslt.c i see that at line 93 params[0] = NULL;
i don't know Zend Engine, but i think it shouldn't be to hard to change that function to accept also parameters from php......
after a very little research, code would like something like: (UNTESTED)
i don't know Zend Engine, but i think it shouldn't be to hard to change that function to accept also parameters from php......
after a very little research, code would like something like: (UNTESTED)
Code: Select all
/* implement function that is meant to be made available to PHP */
ZEND_FUNCTION(libxslt_transform)
{
/* two parameters: xmlstring (XML-Doc) and xslstring (stylesheet) */
zval **xmlstring, **xslstring, **xmlparameters;
/* libxml/xslt stuff */
xsltStylesheetPtr style = NULL;
xmlDocPtr xsl, xml, res;
const char *paramsї2];
xmlOutputBufferPtr outbuf;
if(ZEND_NUM_ARGS() != 3)
{
WRONG_PARAM_COUNT;
}
if(zend_get_parameters_ex(3, &xmlstring, &xslstring, &xmlparameters) != SUCCESS)
{
WRONG_PARAM_COUNT;
}
convert_to_string_ex(xmlstring);
convert_to_string_ex(xslstring);
//paramsї0] = NULL;
convert_to_array_ex(xmlparameters);
xmlInitParser();
xmlSubstituteEntitiesDefault(1);
xmlLoadExtDtdDefaultValue = 1;
xsl = xmlParseMemory((*xslstring)->value.str.val,
(*xslstring)->value.str.len);
style = xsltParseStylesheetDoc(xsl);
xml = xmlParseMemory((*xmlstring)->value.str.val,
(*xmlstring)->value.str.len);
res = xsltApplyStylesheet(style, xml, xmlparameters);
if (res) {
outbuf = xmlAllocOutputBuffer(NULL);
xsltSaveResultTo(outbuf, res, style);
xmlOutputBufferFlush(outbuf);
RETVAL_STRINGL(outbuf->buffer->content, outbuf->buffer->use, 1);
xmlOutputBufferClose(outbuf);
xmlFreeDoc(res);
if (xml) {
xmlFreeDoc(xml);
}
if (style) {
xsltFreeStylesheet(style);
}
xsltCleanupGlobals();
xmlCleanupParser();
xmlMemoryDump();
return;
}
else {
RETURN_STRING((*xmlstring)->value.str.val,1);
}
}