本文整理汇总了PHP中XSLTProcessor::registerPHPFunctions方法的典型用法代码示例。如果您正苦于以下问题:PHP XSLTProcessor::registerPHPFunctions方法的具体用法?PHP XSLTProcessor::registerPHPFunctions怎么用?PHP XSLTProcessor::registerPHPFunctions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XSLTProcessor
的用法示例。
在下文中一共展示了XSLTProcessor::registerPHPFunctions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processor
/**
* @return \XSLTProcessor
*/
protected function processor()
{
if (!$this->processor) {
$this->processor = new \XSLTProcessor();
if ('php' == $this->root()->attr('exclude-result-prefixes')) {
$this->processor->registerPHPFunctions();
}
$this->processor->importStyleSheet($this);
}
return $this->processor;
}
示例2: render
public function render()
{
eval("\$this->content = \$this->parse{$this->requesttype}();");
$this->checkFor404();
if ($this->format === 'object') {
$this->printObject($this);
} else {
ob_start();
$file = $this->root . '/lib/xml/pigment.xml';
echo '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n";
if (is_file($file)) {
include $file;
}
$xml = ob_get_contents();
ob_end_clean();
}
if ($this->format === 'xml') {
$type = $this->getHeader('xml');
header("Content-Type: {$type}");
echo $xml;
} else {
if ($this->format === 'default') {
if ($this->requesttype === 'Content') {
$type = $this->getHeader('xml');
$file = "{$this->root}/lib/xsl/{$this->version}.xsl";
if (!is_file($file)) {
$file = "{$this->root}/lib/xsl/default.xsl";
}
$xmldoc = DOMDocument::loadXML($xml);
$xsldoc = new DomDocument();
$xsldoc->load($file);
$proc = new XSLTProcessor();
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
$output = $proc->transformToXML($xmldoc);
$selector = '</html>';
if (strstr($output, $selector)) {
$exp = explode($selector, $output);
$uri = $_SERVER['REQUEST_URI'];
$delim = strstr($uri, '?') ? '&' : '?';
$track = '<object type="text/html" width="1" height="1" data="' . $uri . $delim . 'log"></object>';
$output = implode($track . '</html>', $exp);
}
} else {
$output = $this->content;
}
}
}
if (isset($output)) {
if (isset($this->is404) && $this->is404 === true) {
header(' ', true, 404);
} else {
header("Content-Type: {$this->header}");
}
echo $output;
if ($this->preferences['cache'] && !isset($this->querystring) && !isset($this->is404)) {
$this->cache($output);
}
}
}
示例3: getXSLTProcessor
/**
* Returns the XSLTProcessor to use to transform internal XML to HTML5.
*
* @return \XSLTProcessor
*/
protected function getXSLTProcessor()
{
if (isset($this->xsltProcessor)) {
return $this->xsltProcessor;
}
$xslDoc = new DOMDocument();
$xslDoc->load($this->stylesheet);
// Now loading custom xsl stylesheets dynamically.
// According to XSL spec, each <xsl:import> tag MUST be loaded BEFORE any other element.
$insertBeforeEl = $xslDoc->documentElement->firstChild;
foreach ($this->getSortedCustomStylesheets() as $stylesheet) {
if (!file_exists($stylesheet)) {
throw new RuntimeException("Cannot find XSL stylesheet for XMLText rendering: {$stylesheet}");
}
$newEl = $xslDoc->createElement('xsl:import');
$hrefAttr = $xslDoc->createAttribute('href');
$hrefAttr->value = $stylesheet;
$newEl->appendChild($hrefAttr);
$xslDoc->documentElement->insertBefore($newEl, $insertBeforeEl);
}
// Now reload XSL DOM to "refresh" it.
$xslDoc->loadXML($xslDoc->saveXML());
$this->xsltProcessor = new XSLTProcessor();
$this->xsltProcessor->importStyleSheet($xslDoc);
$this->xsltProcessor->registerPHPFunctions();
return $this->xsltProcessor;
}
示例4: doAction
public function doAction(Zend_Controller_Action $action)
{
$entryId = $action->getRequest()->getParam('entry-id');
$xslt = $action->getRequest()->getParam('xslt');
$this->client = Infra_ClientHelper::getClient();
$xml = $this->client->media->getMrss($entryId);
$xslParams = array();
$xslParams['entryDistributionId'] = '';
$xslParams['distributionProfileId'] = '';
ob_start();
$xmlDoc = new DOMDocument();
$xmlDoc->loadXML($xml);
$xsltDoc = new DOMDocument();
$xsltDoc->loadXML($xslt);
$xslt = new XSLTProcessor();
$xslt->registerPHPFunctions();
// it is safe to register all php fuctions here
$xslt->setParameter('', $xslParams);
$xslt->importStyleSheet($xsltDoc);
$ob = ob_get_clean();
ob_end_clean();
if ($ob) {
$action->getHelper('json')->direct(array('error' => $ob));
}
$obj = array('result' => $xslt->transformToXml($xmlDoc));
$action->getHelper('json')->direct($obj);
}
示例5: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$environment = $input->getOption('env');
try {
$transformer = $input->getOption('xsl');
$xsl = new \DOMDocument();
$xsl->load($transformer);
$xslt = new \XSLTProcessor();
$xslt->registerPHPFunctions();
$xslt->importStylesheet($xsl);
$files = $input->getOption('file');
foreach ($files as $file) {
$output->writeln('Transforming file: ' . $file);
$doc = new \DOMDocument();
$doc->load($file);
$xml = $xslt->transformToXml($doc);
$xmlobj = new \SimpleXMLElement($xml);
$xmlobj->asXML('output.xml');
}
} catch (\Exception $ex) {
$exception = new OutputFormatterStyle('red');
$output->getFormatter()->setStyle('exception', $exception);
$output->writeln("\n\n");
$output->writeln('<exception>[Exception in: ' . get_class($this) . ']</exception>');
$output->writeln('<exception>Exception: ' . get_class($ex) . ' with message: ' . $ex->getMessage() . '</exception>');
$output->writeln('<exception>Stack Trace:</exception>');
$output->writeln('<exception>' . $ex->getTraceAsString() . '</exception>');
exit(1);
}
exit(0);
}
示例6: __construct
/**
* Initializes this Class' XSLTProcessor, if not yet instantiated.
*/
public function __construct()
{
if (null === self::$_xsltProcessor) {
self::$_xsltProcessor = new XSLTProcessor();
self::$_xsltProcessor->registerPHPFunctions();
}
}
示例7: xsl_transform_feed
function xsl_transform_feed($feedUrl, $xslPath)
{
$doc = new DOMDocument();
$xsl = new XSLTProcessor();
$doc->load(parse_path($xslPath));
$xsl->importStyleSheet($doc);
$doc->loadXML(file_get_contents(parse_path($feedUrl)));
$xsl->registerPHPFunctions(array('xsl_counter'));
return $xsl->transformToXML($doc);
}
示例8: process
public function process()
{
$xslt = new XSLTProcessor();
$xslt->registerPHPFunctions();
$baseExt = 'Base';
$xslt->setParameter('', 'ext', $baseExt);
$xslt->importStylesheet($this->stylesheet);
$baseTypes = $xslt->transformToXml($this->schema);
$fp = fopen('BaseTypes.php', 'w');
fwrite($fp, $baseTypes);
fclose($fp);
}
示例9: render
/**
* Converts the given XML tree and the given XSL file to a (HTML) file, with respect to the given XSL parameters.
* The given XMLTree parameter may be of the SimpleXMLElement or the DOMDocument type, however, the latter is the fastest.
* The generated output may be considered to be formatted properly.
* @param mixed The XML Tree as a SimpleXMLElement or a DOMDocument
* @param mixed The fullpath to the XSL file, or an instanced \SimpleXMLElement XSL tree
* @param \System\Collection\Map The map with the parameters, or null for no parameters or default
*/
public final function render()
{
$args = func_get_args();
if (count($args) != 3) {
throw new \InvalidArgumentException('Invalid amount of arguments given.');
}
list($xmlTree, $xslFile, $parameters) = $args;
$processor = new \XSLTProcessor();
//register the php functions
if (count(self::$registeredPHPFunctions) > 0) {
$processor->registerPHPFunctions(self::$registeredPHPFunctions);
}
//load the xsl file intro a dom
$xsl = new \DOMDocument();
if ($xslFile instanceof \SimpleXMLElement) {
$xsl->loadXML($xslFile->asXML());
} else {
if (!file_exists($xslFile)) {
throw new \System\Error\Exception\FileNotFoundException('XSL File: ' . $xslFile . ' cannot be found');
}
$xsl->load($xslFile);
}
//attach the xsl dom to the processor
$processor->importStylesheet($xsl);
//when we run as a local debug system, we output the profiling information
if (defined('DEBUG')) {
$processor->setProfiling(PATH_LOGS . 'XSLTRenderProfiling.txt');
}
$dom = new \DOMDocument();
switch (true) {
case $xmlTree instanceof \SimpleXMLElement:
//we need to convert to a domdocument
$dom = \System\XML\XML::convertSimpleXMLElementToDOMDocument($xmlTree);
break;
case $xmlTree instanceof \DOMDocument:
//no conversion needed
break;
default:
throw new \InvalidArgumentException('Given XML tree is of non supported tree type: ' . get_class($xmlTree));
}
$this->preprocessParameters($parameters);
//we do not need any namespaces
$processor->setParameter('', $parameters->getArrayCopy());
$output = $processor->transformToXML($dom);
if (!$output) {
throw new \Exception('Could not transform the given XML and XSL to a valid HTML page');
}
if (MINIFY_ENABLE) {
$output = \System\Web\Minify\HTML\Minify::minify($output);
}
$this->addToBuffer($output);
}
示例10: cbd_run
public static function cbd_run()
{
$proc = new XSLTProcessor();
$proc->importStyleSheet(DOMDocument::load('xsl/cbd.xsl'));
global $registerPHPFunctions;
if ($registerPHPFunctions) {
$proc->registerPHPFunctions($registerPHPFunctions);
}
$cbd_xml = $proc->transformToDoc(DOMDocument::load('db://?all-data'));
$xml = simplexml_import_dom($cbd_xml) or die('import failed');
global $cbd_host, $cbd_db, $cbd_user, $cbd_pwd;
$conn_pg = pg_connect("host='{$cbd_host}' dbname={$cbd_db} user={$cbd_user} password={$cbd_pwd}") or die("error on connection to {$cbd_db}");
Importer::_run($xml, $conn_pg);
}
示例11: parse
public function parse(Session $session)
{
$chan = new DOMDocument();
$chan->loadXML(mb_convert_encoding($session->bytes, 'HTML-ENTITIES', 'UTF-8'));
$sheet = new DOMDocument();
$sheet->load('data/atom2rss/atom2rss.xsl');
/* use stylesheet from this page */
$processor = new XSLTProcessor();
$processor->registerPHPFunctions();
$processor->importStylesheet($sheet);
$session->dom = $processor->transformToDoc($chan);
$session->xpath = new DOMXPath($session->dom);
$session->dom->save('/tmp/atom.xml');
// error_log("RESULT: " . $session->dom->saveXML());
}
示例12: parseContent
public function parseContent()
{
$xml = new \DOMDocument();
$xml->load($this->filename);
$xsl = new \DOMDocument();
$xsl->load('./sheet.xsl');
$proc = new \XSLTProcessor();
$proc->importStyleSheet($xsl);
$proc->setParameter('', 'base_url', $this->config['base_url']);
$proc->setParameter('', 'images_url', $this->config['base_url'] . '/images/sheets/' . $this->id . '/');
$proc->registerPHPFunctions(['OverDocs\\SheetParser::canonicalize', 'OverDocs\\SheetParser::parseAbbreviation']);
$output = $proc->transformToXML($xml);
if (!$this->debug) {
$output = $this->minify($output);
}
return $output;
}
示例13: convertTicket
/**
* @param array $ticket
*/
public function convertTicket($ticket)
{
$processor = new \XSLTProcessor();
$xmlSerializer = new XMLSerializer();
$serializedTicket = $xmlSerializer->serialize($ticket);
$dom = new \DOMDocument();
$dom->loadXML($serializedTicket);
$processor->registerPHPFunctions('config');
try {
$stylesheet = new \DOMDocument();
$stylesheet->load(config('printer.XSLTemplatePath'));
$processor->importStylesheet($stylesheet);
$doc = $processor->transformToDoc($dom);
$doc->save(config('printer.foOutputPath'));
} catch (\Exception $e) {
Log::error($e->getMessage());
}
}
示例14: render
public function render(Page $page)
{
$viewPath = $this->path;
if (strToLower(substr($viewPath, strlen($viewPath) - 5, 5)) == ".xslt") {
// file is XSLT
$objXML = $page->xml;
$objXSL = new DomDocument();
$objXSL->load(getViewPath($viewPath));
$objProc = new XSLTProcessor();
$objProc->registerPHPFunctions();
$objProc->importStyleSheet($objXSL);
echo $objProc->transformToXML($objXML);
} else {
// FILE IS PHP
$PAGE = $page;
include getViewPath($this->path);
}
}
示例15: transform
public static function transform($data, $type)
{
$xslt = APPLICATION_PATH . "/configs/repository/0.1/xslt/" . $type;
$xslt = $xslt . ".xsl";
if (file_exists($xslt)) {
$xsl = new DOMDocument();
$xsl->load($xslt);
$xml = new DOMDocument();
$xml->loadXML($data, LIBXML_NSCLEAN | LIBXML_COMPACT);
$proc = new XSLTProcessor();
$proc->registerPHPFunctions();
$proc->importStylesheet($xsl);
$data = $proc->transformToXml($xml);
$data = str_replace('<?xml version="1.0"?' . '>', '', $data);
} else {
error_log('Cannot find ' . $xslt);
}
return $data;
}