jgugugiug 发表于 2017-4-12 07:38:51

用PHP将XML用XSLT解析成HTML

/**

* 将xml文件根据xsl文件转换成HTML内容

* @param String $xslFile - xsl文件

* @param String $xmlFile - xml文件

* 需要加载相关的dll,如:iconv,xslt等

*/

function getXmlHtml($xslFile = false, $xmlFile = false)

{

$xslstring = implode('', file($xslFile));



$xmlstring = implode('', file($xmlFile));

$arguments = array('/_xml' => $xmlstring,

'/_xsl' => $xslstring

);

$xh = xslt_create();

$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', null, $arguments);

if ($result) {

return $result;

xslt_free($xh);

} else {

return "Err";

xslt_free($xh);

}

} //end function getXmlHtml()
页: [1]
查看完整版本: 用PHP将XML用XSLT解析成HTML