Hi all,
several days ago i’ve to use XSLT transformation in PHP code. One of the requirements is to use external .xml files, so in the .xsl file i have to use references like http://example.com/xml/myfile.xml, but sablotron doesn’t seems to implement this kind of schema. Only works with file: schema.
<xsl:value-of
select="document('http://example.com/xml/myfile.xml')
/items/group/item[./@code='ES']/@value"/>
this is a piece of XSLT that i want to use
I thought an update system that download the external resources, but, i can’t believe that didn’t exist any better solution (of course simpler).
My fist attemp was using xslt_base_dir with and url like:
$xh = xslt_create();
$fileBase = 'http://example.com/xml/';
xslt_set_base ( $xh, $fileBase );
… but didn’t work.
Checking all the XSLT methods in the PHP reference i’ve found one that seems fit: xslt_set_scheme_handlers. Despite it isn’t already documented one comment is enough explanatory.
function mySchemeHandler($processor, $scheme, $rest) {
if($scheme == 'http') {
return file_get_contents($scheme.":".$rest);
}
}
$SchemeHandlerArray = array();
$SchemeHandlerArray["get_all"] = "mySchemeHandler";
$xh = xslt_create();
xslt_set_scheme_handlers($xh,$SchemeHandlerArray);
echo xslt_process($xh, 'arg:/_xml', $config['xslt'], NULL,
array ( '/_xml' => utf8_encode($result) ),
array (
'link' => $link ,
'locale' => $config['locale'] ,
'extra' => $config['extra']
) );
xslt_free($xh);
and .. works!!