本文整理汇总了PHP中XsltProcessor::importStyleSheet方法的典型用法代码示例。如果您正苦于以下问题:PHP XsltProcessor::importStyleSheet方法的具体用法?PHP XsltProcessor::importStyleSheet怎么用?PHP XsltProcessor::importStyleSheet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XsltProcessor
的用法示例。
在下文中一共展示了XsltProcessor::importStyleSheet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyTemplate
/**
* Metainformation catalogue
* --------------------------------------------------
*
* Lib_XML for MicKa
*
* @link http://www.bnhelp.cz
* @package Micka
* @category Metadata
* @version 20121206
*
*/
function applyTemplate($xmlSource, $xsltemplate)
{
$rs = FALSE;
if (File_Exists(CSW_XSL . '/' . $xsltemplate)) {
if (!extension_loaded("xsl")) {
if (substr(PHP_OS, 0, 3) == "WIN") {
dl("php_xsl.dll");
} else {
dl("php_xsl.so");
}
}
$xp = new XsltProcessor();
$xml = new DomDocument();
$xsl = new DomDocument();
$xml->loadXML($xmlSource);
$xsl->load(CSW_XSL . '/' . $xsltemplate);
$xp->importStyleSheet($xsl);
//$xp->setParameter("","lang",$lang);
$xp->setParameter("", "user", $_SESSION['u']);
$rs = $xp->transformToXml($xml);
}
if ($rs === FALSE) {
setMickaLog('applyTemplate === FALSE', 'ERROR', 'micka_lib_xml.php');
}
return $rs;
}
示例2: handle
function handle($match, $state, $pos, Doku_Handler $handler)
{
switch ($state) {
case DOKU_LEXER_SPECIAL:
$matches = preg_split('/(&&XML&&\\n*|\\n*&&XSLT&&\\n*|\\n*&&END&&)/', $match, 5);
$data = "XML: " . $matches[1] . "\nXSLT: " . $matches[2] . "(" . $match . ")";
$xsltproc = new XsltProcessor();
$xml = new DomDocument();
$xsl = new DomDocument();
$xml->loadXML($matches[1]);
$xsl->loadXML($matches[2]);
$xsltproc->registerPHPFunctions();
$xsltproc->importStyleSheet($xsl);
$data = $xsltproc->transformToXML($xml);
if (!$data) {
$errors = libxml_get_errors();
foreach ($errors as $error) {
$data = display_xml_error($error, $xml);
}
libxml_clear_errors();
}
unset($xsltproc);
return array($state, $data);
case DOKU_LEXER_UNMATCHED:
return array($state, $match);
case DOKU_LEXER_EXIT:
return array($state, '');
}
return array();
}
示例3: process
/**
* process xsl template with Flow xml
*
* @param string xsl source file
* @return string xsl transformation output
*/
public function process($xslfile)
{
$flow = Nexista_Flow::Singleton('Nexista_Flow');
// The following can be used with the NYT xslt cache.
$use_xslt_cache = "yes";
if (!is_file($xslfile)) {
Nexista_Error::init('XSL Handler - Error processing XSL file,
it is unavailable: ' . $xslfile, NX_ERROR_FATAL);
}
if ($use_xslt_cache != "yes" || !class_exists('xsltCache')) {
$xsl = new DomDocument('1.0', 'UTF-8');
$xsl->substituteEntities = false;
$xsl->resolveExternals = false;
$xslfilecontents .= file_get_contents($xslfile);
$xsl->loadXML($xslfilecontents);
$xsl->documentURI = $xslfile;
$xslHandler = new XsltProcessor();
$xslHandler->importStyleSheet($xsl);
if (4 == 3 && function_exists('setProfiling')) {
$xslHandler->setProfiling("/tmp/xslt-profiling.txt");
}
} else {
$xslHandler = new xsltCache();
$xslHandler->importStyleSheet($xslfile);
}
$output = $xslHandler->transformToXML($flow->flowDocument);
if ($output === false) {
Nexista_Error::init('XSL Handler - Error processing XSL file: ' . $xslfile, NX_ERROR_FATAL);
}
return $output;
}
示例4: translate
/**
* translate xml
*
* @param string $xml_dom
* @param string $xsl_dom
* @param string $params
* @param string $php_functions
* @return void
* @author Andy Bennett
*/
private static function translate($xml_dom, $xsl_dom, $params = array(), $php_functions = array())
{
/* create the processor and import the stylesheet */
$proc = new XsltProcessor();
$proc->importStyleSheet($xsl_dom);
foreach ($params as $name => $param) {
$proc->setParameter('', $name, $param);
}
if (is_array($php_functions)) {
$proc->registerPHPFunctions($php_functions);
}
/* transform and output the xml document */
$newdom = $proc->transformToDoc($xml_dom);
return $newdom->saveXML();
}
示例5: loadDataModels
/**
* Gets all matching XML schema files and loads them into data models for class.
* @return void
*/
protected function loadDataModels()
{
$ads = array();
$totalNbTables = 0;
$this->log('Loading XML schema files...');
// Get all matched files from schemaFilesets
foreach ($this->schemaFilesets as $fs) {
$ds = $fs->getDirectoryScanner($this->project);
$srcDir = $fs->getDir($this->project);
$dataModelFiles = $ds->getIncludedFiles();
sort($dataModelFiles);
$defaultPlatform = $this->getGeneratorConfig()->getConfiguredPlatform();
// Make a transaction for each file
foreach ($dataModelFiles as $dmFilename) {
$this->log("Processing: " . $dmFilename, Project::MSG_VERBOSE);
$xmlFile = new PhingFile($srcDir, $dmFilename);
$dom = new DomDocument('1.0', 'UTF-8');
$dom->load($xmlFile->getAbsolutePath());
// modify schema to include any external schemas (and remove the external-schema nodes)
$this->includeExternalSchemas($dom, $srcDir);
// normalize (or transform) the XML document using XSLT
if ($this->getGeneratorConfig()->getBuildProperty('schemaTransform') && $this->xslFile) {
$this->log("Transforming " . $dmFilename . " using stylesheet " . $this->xslFile->getPath(), Project::MSG_VERBOSE);
if (!class_exists('XSLTProcessor')) {
$this->log("Could not perform XLST transformation. Make sure PHP has been compiled/configured to support XSLT.", Project::MSG_ERR);
} else {
// normalize the document using normalizer stylesheet
$xslDom = new DomDocument('1.0', 'UTF-8');
$xslDom->load($this->xslFile->getAbsolutePath());
$xsl = new XsltProcessor();
$xsl->importStyleSheet($xslDom);
$dom = $xsl->transformToDoc($dom);
}
}
// validate the XML document using XSD schema
if ($this->validate && $this->xsdFile) {
$this->log(" Validating XML using schema " . $this->xsdFile->getPath(), Project::MSG_VERBOSE);
if (!$dom->schemaValidate($this->xsdFile->getAbsolutePath())) {
throw new EngineException("XML schema file (" . $xmlFile->getPath() . ") does not validate. See warnings above for reasons validation failed (make sure error_reporting is set to show E_WARNING if you don't see any).", $this->getLocation());
}
}
$xmlParser = new XmlToAppData($defaultPlatform, $this->getTargetPackage(), $this->dbEncoding);
$xmlParser->setGeneratorConfig($this->getGeneratorConfig());
$ad = $xmlParser->parseString($dom->saveXML(), $xmlFile->getAbsolutePath());
$nbTables = $ad->getDatabase(null, false)->countTables();
$totalNbTables += $nbTables;
$this->log(sprintf(' %d tables processed successfully', $nbTables), Project::MSG_VERBOSE);
$ad->setName($dmFilename);
$ads[] = $ad;
}
$this->log(sprintf('%d tables found in %d schema files.', $totalNbTables, count($dataModelFiles)));
}
if (empty($ads)) {
throw new BuildException("No schema files were found (matching your schema fileset definition).");
}
foreach ($ads as $ad) {
// map schema filename with database name
$this->dataModelDbMap[$ad->getName()] = $ad->getDatabase(null, false)->getName();
}
if (count($ads) > 1 && $this->packageObjectModel) {
$ad = $this->joinDataModels($ads);
$this->dataModels = array($ad);
} else {
$this->dataModels = $ads;
}
foreach ($this->dataModels as &$ad) {
$ad->doFinalInitialization();
}
if ($this->validate) {
foreach ($this->dataModels as $dataModel) {
$validator = new PropelSchemaValidator($dataModel);
if (!$validator->validate()) {
throw new EngineException(sprintf("The database schema contains errors:\n - %s", join("\n - ", $validator->getErrors())));
}
}
}
$this->dataModelsLoaded = true;
}
示例6: getXPath
public function getXPath($entry, $XSLTfilename = NULL, $fetch_associated_counts = NULL)
{
$entry_xml = new XMLElement('entry');
$data = $entry->getData();
$fields = array();
$entry_xml->setAttribute('id', $entry->get('id'));
//Add date created and edited values
$date = new XMLElement('system-date');
$date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('creation_date')), 'created'));
$date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('modification_date')), 'modified'));
$entry_xml->appendChild($date);
//Reflect Workspace and Siteroot params
$workspace = new XMLElement('workspace', URL . '/workspace');
$root = new XMLElement('root', URL);
// Add associated entry counts
if ($fetch_associated_counts == 'yes') {
$associated = $entry->fetchAllAssociatedEntryCounts();
if (is_array($associated) and !empty($associated)) {
foreach ($associated as $section_id => $count) {
$section = SectionManager::fetch($section_id);
if ($section instanceof Section === false) {
continue;
}
$entry_xml->setAttribute($section->get('handle'), (string) $count);
}
}
}
// Add fields:
foreach ($data as $field_id => $values) {
if (empty($field_id)) {
continue;
}
$field = FieldManager::fetch($field_id);
$field->appendFormattedElement($entry_xml, $values, false, null, $entry->get('id'));
}
$xml = new XMLElement('data');
$xml->appendChild($entry_xml);
$xml->appendChild($workspace);
$xml->appendChild($root);
// Build some context
$section = SectionManager::fetch($entry->get('section_id'));
$params = new XMLElement('params');
$params->appendChild(new XMLElement('section-handle', $section->get('handle')));
$params->appendChild(new XMLElement('entry-id', $entry->get('id')));
$xml->prependChild($params);
$dom = new DOMDocument();
$dom->strictErrorChecking = false;
$dom->loadXML($xml->generate(true));
if (!empty($XSLTfilename)) {
$XSLTfilename = UTILITIES . '/' . preg_replace(array('%/+%', '%(^|/)../%'), '/', $XSLTfilename);
if (file_exists($XSLTfilename)) {
$XSLProc = new XsltProcessor();
$xslt = new DomDocument();
$xslt->load($XSLTfilename);
$XSLProc->importStyleSheet($xslt);
// Set some context
$XSLProc->setParameter('', array('section-handle' => $section->get('handle'), 'entry-id' => $entry->get('id')));
$temp = $XSLProc->transformToDoc($dom);
if ($temp instanceof DOMDocument) {
$dom = $temp;
}
}
}
$xpath = new DOMXPath($dom);
if (version_compare(phpversion(), '5.3', '>=')) {
$xpath->registerPhpFunctions();
}
return $xpath;
}
示例7: process
function process()
{
global $gConf;
if ('client' == $gConf['xsl_mode']) {
echo 'depricated';
exit;
}
header($this->_header);
// xml: string, xsl: file
if (!($this->_mode & BXXSLTRANSFORM_XML_FILE) && $this->_mode & BXXSLTRANSFORM_XSL_FILE) {
$args = array('/_xml' => $this->_xml);
validate_unicode($this->_xml);
if ((int) phpversion() >= 5) {
$xml = new DOMDocument();
if (!@$xml->loadXML($this->_xml)) {
$mk = new Mistake();
$mk->log("BxXslTransform::process - can not load xml:\n " . $this->_xml);
$mk->displayError("[L[Site is unavailable]]");
}
$xsl = new DomDocument();
$xsl->load($this->_xsl);
$proc = new XsltProcessor();
$proc->importStyleSheet($xsl);
$res = $proc->transformToXML($xml);
} else {
if (function_exists('domxml_xslt_stylesheet_file')) {
$xmldoc = new DomDocument($this->_xml);
$xsldoc = domxml_xslt_stylesheet_file($this->_xsl);
$result = $xsldoc->process($xmldoc);
$res = $xsldoc->result_dump_mem($result);
} elseif (function_exists('xslt_create')) {
$xh = xslt_create();
xslt_setopt($xh, XSLT_SABOPT_IGNORE_DOC_NOT_FOUND);
$res = xslt_process($xh, 'arg:/_xml', $this->_xsl, NULL, $args);
xslt_free($xh);
} else {
die('Server XSLT support is not enabled, try to use client XSL transformation http://your-domain/orca_folder/?xsl_mode=client');
}
}
return $res;
}
// xml: file, xsl: file
if ($this->_mode & BXXSLTRANSFORM_XML_FILE && $this->_mode & BXXSLTRANSFORM_XSL_FILE) {
if ((int) phpversion() >= 5) {
$xml = new DOMDocument();
$xml->load($this->_xml);
$xsl = new DomDocument();
$xsl->load($this->_xsl);
$proc = new XsltProcessor();
$proc->importStyleSheet($xsl);
$res = $proc->transformToXML($xml);
} else {
if (function_exists('domxml_xslt_stylesheet_file')) {
$xmldoc = new DomDocument($this->_xml);
$xsldoc = domxml_xslt_stylesheet_file($this->_xsl);
$result = $xsldoc->process($xmldoc);
$res = $xsldoc->result_dump_mem($result);
} elseif (function_exists('xslt_create')) {
$xh = xslt_create();
$res = xslt_process($xh, $this->_xml, $this->_xsl, NULL, $args);
xslt_setopt($xh, XSLT_SABOPT_IGNORE_DOC_NOT_FOUND);
xslt_free($xh);
} else {
die('XSLT support is not enabled');
}
}
return $res;
//return `/opt/jre1.5.0_06/bin/java -jar /opt/saxon/saxon.jar -ds {$this->_xml} {$this->_xsl}`;
}
return "<h1>not supported</h1>";
}
示例8: __process
/**
* Uses `DomDocument` to transform the document. Any errors that
* occur are trapped by custom error handlers, `trapXMLError` or
* `trapXSLError`.
*
* @param XsltProcessor $XSLProc
* An instance of `XsltProcessor`
* @param string $xml
* The XML for the transformation to be applied to
* @param string $xsl
* The XSL for the transformation
* @param array $parameters
* An array of available parameters the XSL will have access to
* @return string
*/
private function __process(XsltProcessor $XSLProc, $xml, $xsl, array $parameters = array())
{
// Create instances of the DomDocument class
$xmlDoc = new DomDocument();
$xslDoc = new DomDocument();
// Set up error handling
if (function_exists('ini_set')) {
$ehOLD = ini_set('html_errors', false);
}
// Load the xml document
set_error_handler(array($this, 'trapXMLError'));
// Prevent remote entities from being loaded, RE: #1939
$elOLD = libxml_disable_entity_loader(true);
$xmlDoc->loadXML($xml, LIBXML_NONET | LIBXML_DTDLOAD | LIBXML_DTDATTR | defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0);
libxml_disable_entity_loader($elOLD);
// Must restore the error handler to avoid problems
restore_error_handler();
// Load the xsl document
set_error_handler(array($this, 'trapXSLError'));
// Ensure that the XSLT can be loaded with `false`. RE: #1939
// Note that `true` will cause `<xsl:import />` to fail.
$elOLD = libxml_disable_entity_loader(false);
$xslDoc->loadXML($xsl, LIBXML_NONET | LIBXML_DTDLOAD | LIBXML_DTDATTR | defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0);
libxml_disable_entity_loader($elOLD);
// Load the xsl template
$XSLProc->importStyleSheet($xslDoc);
// Set parameters when defined
if (!empty($parameters)) {
General::flattenArray($parameters);
$XSLProc->setParameter('', $parameters);
}
// Must restore the error handler to avoid problems
restore_error_handler();
// Start the transformation
set_error_handler(array($this, 'trapXMLError'));
$processed = $XSLProc->transformToXML($xmlDoc);
// Restore error handling
if (function_exists('ini_set') && isset($ehOLD)) {
ini_set('html_errors', $ehOLD);
}
// Must restore the error handler to avoid problems
restore_error_handler();
return $processed;
}
示例9: __process
/**
* Uses `DomDocument` to transform the document. Any errors that
* occur are trapped by custom error handlers, `trapXMLError` or
* `trapXSLError`.
*
* @param XsltProcessor $XSLProc
* An instance of `XsltProcessor`
* @param string $xml
* The XML for the transformation to be applied to
* @param string $xsl
* The XSL for the transformation
* @param array $parameters
* An array of available parameters the XSL will have access to
* @return string
*/
private function __process(XsltProcessor $XSLProc, $xml, $xsl, array $parameters = array())
{
// Create instances of the DomDocument class
$xmlDoc = new DomDocument();
$xslDoc = new DomDocument();
// Set up error handling
if (function_exists('ini_set')) {
$ehOLD = ini_set('html_errors', false);
}
// Load the xml document
set_error_handler(array($this, 'trapXMLError'));
$xmlDoc->loadXML($xml);
// Must restore the error handler to avoid problems
restore_error_handler();
// Load the xml document
set_error_handler(array($this, 'trapXSLError'));
$xslDoc->loadXML($xsl);
// Load the xsl template
$XSLProc->importStyleSheet($xslDoc);
// Set parameters when defined
if (!empty($parameters)) {
General::flattenArray($parameters);
$XSLProc->setParameter('', $parameters);
}
restore_error_handler();
// Start the transformation
set_error_handler(array($this, 'trapXMLError'));
$processed = $XSLProc->transformToXML($xmlDoc);
// Restore error handling
if (function_exists('ini_set') && isset($ehOLD)) {
ini_set('html_errors', $ehOLD);
}
restore_error_handler();
return $processed;
}
示例10: XsltProcessor
<?php
$processor = new XsltProcessor();
$xsl = new DOMDocument();
$xsl->load("rules.xsl");
$processor->importStyleSheet($xsl);
$xml = new DomDocument();
$xml->load("feed.xml");
$result = $processor->transformToXml($xml);
echo "<pre>{$result}</pre>";
示例11: 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;
}
示例12: header
if ($format === "lua") {
$xsl->load('xmltolua-compact.xsl');
header('Content-Type: text/plain; charset=UTF-8');
} else {
if ($format === "json") {
$xsl->load('xmltojson-compact.xsl');
header('Content-Type: application/json; charset=UTF-8');
} else {
if ($format === "jsonp") {
$xsl->load('xmltojsonp-compact.xsl');
header('Content-Type: application/javascript; charset=UTF-8');
}
}
}
}
$xp->importStyleSheet($xsl);
$xp->setParameter('', 'decimalSupported', 'no');
if ($callback && $format === "jsonp") {
$xp->setParameter('', 'callback', $callback);
}
$xml = new DomDocument();
$contents = file_get_contents($url);
if ($contents) {
$xml->loadXML($contents);
if ($xform = $xp->transformToXML($xml)) {
echo $xform;
} else {
trigger_error('XSL transformation failed.', E_USER_ERROR);
}
} else {
trigger_error('URL could not be loaded.', E_USER_ERROR);
示例13: google
/**
* create google sitemap
*
* @return void
* @author Andy Bennett
*/
public function google()
{
$xsl_path = Kohana::find_file('xsl', 'sitemap', TRUE, 'xsl');
/* load the xml file and stylesheet as domdocuments */
$xsl = new DomDocument();
$xsl->load($xsl_path);
$inputdom = new DomDocument();
$inputdom->loadXML($this->sitemap_string);
/* create the processor and import the stylesheet */
$proc = new XsltProcessor();
$proc->importStyleSheet($xsl);
$proc->setParameter('', 'siteurl', url::base());
/* transform and output the xml document */
$newdom = $proc->transformToDoc($inputdom);
print $newdom->saveXML();
}
示例14: DomDocument
$xml->save("xml/site.xml");
echo $update_value;
return;
}
}
// Create instances of the DomDocument class
$xml = new DomDocument();
$xsl = new DomDocument();
$xsltproc = new XsltProcessor();
// Load the xml document and the xsl template
$xml->validateOnParse = true;
$xml->preserveWhiteSpace = true;
$xsl->preserveWhiteSpace = true;
$xml->load("xml/site.xml");
if ($isAdmin == true) {
$xsl->load("xml/admin.xsl");
} else {
$xsl->load("xml/online.xsl");
}
// Load the xsl template
$xsltproc->importStyleSheet($xsl);
//Transform to XML in a tempfile and include the result.
//With this method, PHP code embeded in XML is executed.
$tmpfname = tempnam("tmp", $page . "-");
$xsltproc->setParameter('', 'page', $page);
$processed = $xsltproc->transformToURI($xml, $tmpfname);
include $tmpfname;
unlink($tmpfname);
unset($xsltproc);
unset($xsl);
unset($xml);
示例15: array
function basemed24LabelAction()
{
$pkey = (int) $this->_getParam('pkey');
$data = array();
$data['pkey'] = (int) $pkey;
$data['format'] = 'html';
$xmlr = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><medication></medication>');
$n = $xmlr->addChild("data");
$label = $this->lookupMedLabel($data['pkey']);
$med = $n->addChild('medicationLabel');
$doc = new DOMDocument();
$doc->loadXML($label->asXML());
$xp = new XsltProcessor();
$xsl = new DomDocument();
$xsl->load('/var/www/ch30/chmed/includes/spl-common.xsl');
$xp->importStyleSheet($xsl);
$this->view->content = $xp->transformToXML($doc);
}