本文整理汇总了PHP中XSLTProcessor::setparameter方法的典型用法代码示例。如果您正苦于以下问题:PHP XSLTProcessor::setparameter方法的具体用法?PHP XSLTProcessor::setparameter怎么用?PHP XSLTProcessor::setparameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XSLTProcessor
的用法示例。
在下文中一共展示了XSLTProcessor::setparameter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xml_apply_stylesheet
function xml_apply_stylesheet($s)
{
$debugging = false;
$message = '';
if (preg_match_all("/<\\?xml-stylesheet[^>]+?\\?>/ms", $s, $matches, PREG_SET_ORDER)) {
foreach ($matches as $m) {
$pi = $m[0];
if (preg_match_all('/\\s+(([a-zA-Z]+)=([\'"])(.*?)\\3)' . '/', $pi, $matches2, PREG_SET_ORDER)) {
$attrs = array();
// $message .= "<pre>".array_dump($matches)."</pre>";
foreach ($matches2 as $a) {
$attrs[$a[2]] = $a[4];
//$s .= "<pre>".$a[2]."=".$a[4]."</pre>";
}
if (!$attrs['href']) {
continue;
}
if (!$attrs['type']) {
$attrs['type'] = 'text/xsl';
}
if ($attrs['type'] == 'text/css') {
$stylesheets[] = array('href' => 'arg:/xsl', 'xsl' => XSL_APPLYCSS_STYLESHEET, 'type' => $attrs['type'], 'params' => array('cssfile' => $attrs['href']));
} elseif ($attrs['type'] == 'debug') {
$debugging = TRUE;
break;
} else {
$stylesheets[] = array('href' => $attrs['href'], 'type' => $attrs['type']);
}
}
}
/* $pi = preg_replace("/<\?xml-stylesheet (.*)\?>/", '\1', $pi);
$stylesheet = preg_replace("/href=(.)(.*)\\1/", '\2', $pi); */
} else {
return $s;
}
$s = preg_replace("/<\\?xml-stylesheet[^>]+?\\?>/ms", '', $s);
if ($debugging) {
return '<pre>' . htmlspecialchars($s) . '</pre>';
}
if (count($stylesheets) == 0) {
$stylesheets[] = array('href' => 'arg:/xsl', 'type' => 'text/xsl', 'xsl' => XSL_DEFAULT_STYLESHEET);
}
$input = $s;
// $message .= 'md5-'.md5($input)."<br />";
foreach ($stylesheets as $stylesheet) {
$xsl = new DomDocument();
$xsl->load($stylesheet['href']);
$xml = new DomDocument();
@$xml->loadXML($input);
if (!isset($stylesheet['params'])) {
$stylesheet['params'] = array();
}
$proc = new XSLTProcessor();
$proc->importStyleSheet($xsl);
foreach ($stylesheet['params'] as $param => $val) {
$proc->setparameter('', $param, $val);
}
if (!($result = $proc->transformToXML($xml))) {
$message .= "Error applying {$stylesheet['href']}: " . '';
$message .= "Failed on:<pre>" . wordwrap(htmlspecialchars($input)) . "</pre>";
$f = fopen("/tmp/dead.xml", "w");
fputs($f, $input);
fclose($f);
system("xmllint /tmp/dead.xml > /tmp/xmllint.log 2>&1");
if (XSL_PROC_MAILTO) {
foreach ($_SERVER as $k => $v) {
$mailmessage .= "{$k} = {$v}\n";
}
$mailmessage .= $message;
$message = 'Stylesheet failed';
$result = $input;
mail(XSL_PROC_MAILTO, 'XML Stylesheet Failed (' . $_SERVER['REQUEST_URI'] . ')', html_entity_decode($mailmessage));
}
} else {
$message .= "<!-- applied {$stylesheet['href']} -->\n";
// $message .= 'md5-'.md5($input)."\n";
$input = $result;
}
#xslt_free($xslt_engine);
}
return $result . $message;
}