本文整理汇总了PHP中XsltProcessor::registerPhpFunctions方法的典型用法代码示例。如果您正苦于以下问题:PHP XsltProcessor::registerPhpFunctions方法的具体用法?PHP XsltProcessor::registerPhpFunctions怎么用?PHP XsltProcessor::registerPhpFunctions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XsltProcessor
的用法示例。
在下文中一共展示了XsltProcessor::registerPhpFunctions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* Simple, dynamic xsl transform
*/
protected function transform($xml, $path_to_xsl, $output_type = null, array $params = array(), array $import_array = array(), $to_string = true)
{
if ($path_to_xsl == "") {
throw new \Exception("no stylesheet supplied");
}
// make sure we have a domdocument
if (is_string($xml)) {
$xml = Parser::convertToDOMDocument($xml);
}
// create xslt processor
$processor = new \XsltProcessor();
$processor->registerPhpFunctions();
// add parameters
foreach ($params as $key => $value) {
$processor->setParameter(null, $key, $value);
}
// add stylesheet
$xsl = $this->generateBaseXsl($path_to_xsl, $import_array, $output_type);
$processor->importStylesheet($xsl);
// transform
if ($to_string == true) {
return $processor->transformToXml($xml);
} else {
return $processor->transformToDoc($xml);
}
}
示例2: transform
/**
* Simple XSLT transformation function
*
* @param mixed $xml DOMDocument or string containing xml
* @param string $strXsltPath Relative file path to xslt document. Will look in both library location and
* local app location for documents, and combine them so local overrides library
* templates, if neccesary.
* @param array $arrParams [optional] array of parameters to pass to stylesheet
* @param bool $bolDoc [optional] return result as DOMDocument (default false)
* @param array $arrInclude [optional] additional stylesheets that should be included in the transform
* @return mixed newly formatted document as string or DOMDocument
* @static
*/
public static function transform($xml, $strXsltPath, $arrParams = null, $bolDoc = false, $arrInclude = array())
{
if ($strXsltPath == "") {
throw new Exception("no stylesheet supplied");
}
if (is_string($xml)) {
// load xml document from string
$objXml = new DOMDocument();
$objXml->loadXML($xml);
$xml = $objXml;
}
$objXsl = self::generateBaseXsl($strXsltPath, $arrInclude);
// create XSLT Processor
$objProcessor = new XsltProcessor();
$objProcessor->registerPhpFunctions();
if ($arrParams != null) {
// add in parameters
foreach ($arrParams as $key => $value) {
$objProcessor->setParameter(null, $key, $value);
}
}
// transform
$objXsl = $objProcessor->importStylesheet($objXsl);
if ($bolDoc == true) {
return $objProcessor->transformToDoc($xml);
} else {
return $objProcessor->transformToXml($xml);
}
}
示例3: transform
public function transform($xsl_file = null, $xml_data = null)
{
CI()->benchmark->mark('xsl_transform (' . $xsl_file . ')_start');
set_error_handler(array('XSL_Transform', 'handleError'));
$xsl = new DOMDocument('1.0', 'UTF-8');
$xsl->load($this->_getXSL($xsl_file));
$inputdom = new DomDocument('1.0', 'UTF-8');
$inputdom->loadXML($this->_getXML($xml_data));
$proc = new XsltProcessor();
$proc->importStylesheet($xsl);
$proc->registerPhpFunctions($this->_allowedFunctions());
$result = $proc->transformToXML($inputdom);
// http://www.php.net/manual/en/xsltprocessor.transformtoxml.php#62081
//$result = $proc->transformToDoc($inputdom);
//$result = $result->saveHTML();
restore_error_handler();
// Strip out any <?xml stuff at top out output
$result = preg_replace('/\\<\\?xml.+\\?\\>/', '', $result, 1);
CI()->benchmark->mark('xsl_transform (' . $xsl_file . ')_end');
return $result;
}
示例4: transform
static function transform($xsl_file, $xml, $params = null, $charset = 'UTF-8', $nohead = false)
{
global $o_global;
$ent = '<!DOCTYPE page [
<!ENTITY nbsp " ">
<!ENTITY copy "©">
<!ENTITY reg "®">
<!ENTITY trade "™">
<!ENTITY mdash "—">
<!ENTITY ldquo "«">
<!ENTITY rdquo "»">
<!ENTITY pound "£">
<!ENTITY sum "Ø">
<!ENTITY yen "¥">
<!ENTITY euro "€">
]>';
if (!$nohead) {
$xml = "<?xml version=\"1.0\" encoding=\"" . $charset . "\"?>\n" . $ent . $xml;
}
$browser = null;
if (empty($xml)) {
$xml = '<empty_xml>Empty xml</empty_xml>';
}
//$xml=iconv('cp1251','cp1251',$xml);
if (!$nohead && $charset == 'windows-1251') {
$xml = preg_replace("{[�]}i", "", $xml);
}
$xsl = new DomDocument();
//$xsl->resolveExternals = true;
$xsl->substituteEntities = true;
if (file_exists($o_global->themes_site_root . $xsl_file)) {
$xsl->load($o_global->themes_site_root . $xsl_file);
} elseif (file_exists($o_global->themes_engine_root . $xsl_file)) {
$xsl->load($o_global->themes_engine_root . $xsl_file);
} elseif (_GL_DEBUG === true) {
return 'Function "transform". Error. File "' . $xsl_file . '" not found (' . $o_global->themes_site_root . $xsl_file . ', ' . $o_global->themes_engine_root . $xsl_file . ')<BR/>' . "\n";
} else {
return '';
}
//$inputdom = new DomDocument();
//$inputdom->loadXML($xml);
/* create the processor and import the stylesheet */
$proc = new XsltProcessor();
$proc->registerPhpFunctions();
//$xsl = $proc->importStylesheet($xsl);
if ($params) {
foreach ($params as $key => $value) {
$proc->setParameter(null, $key, $value);
}
}
$inputdom = new DomDocument();
$inputdom->substituteEntities = true;
$inputdom->loadXML($xml);
$proc->importStyleSheet($xsl);
$res = $proc->transformToXML($inputdom);
return $res;
}
示例5: __autoload
<?php
function __autoload($className)
{
var_dump($className);
exit;
}
$xsl = new DomDocument();
$xsl->loadXML('<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl">
<xsl:template match="/">
<xsl:value-of select="php:function(\'TeSt::dateLang\')" />
</xsl:template>
</xsl:stylesheet>');
$inputdom = new DomDocument();
$inputdom->loadXML('<?xml version="1.0" encoding="iso-8859-1" ?>
<today></today>');
$proc = new XsltProcessor();
$proc->registerPhpFunctions();
$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($inputdom);
?>
===DONE===