本文整理汇总了PHP中XSLTProcessor::transformToXml方法的典型用法代码示例。如果您正苦于以下问题:PHP XSLTProcessor::transformToXml方法的具体用法?PHP XSLTProcessor::transformToXml怎么用?PHP XSLTProcessor::transformToXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XSLTProcessor
的用法示例。
在下文中一共展示了XSLTProcessor::transformToXml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveXML
public function saveXML($me = true)
{
$xml = new XMLDom();
if (!self::$xsl instanceof \XSLTProcessor) {
self::$xsl = new \XSLTProcessor();
self::$xsl->importStylesheet(XMLDom::loadXMLString('<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" method="xml"/>
<xsl:template match="node()|@*" priority="-4">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="/" priority="-4">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>'));
}
if ($me) {
$xml->appendChild($xml->importNode($this, true));
return self::$xsl->transformToXml($xml);
} else {
foreach ($this->childNodes as $node) {
$xml->appendChild($xml->importNode($node, true));
}
}
return self::$xsl->transformToXml($xml);
}
示例2: xsl_transform
function xsl_transform($filename, $xslname = null)
{
// Get the original XML document
$xml = new DOMDocument();
$xml->load($filename);
if ($xslname == null) {
// extract bound stylesheet from embedded link
$xp = new DOMXPath($xml);
// use xpath to get the directive
$pi = $xp->evaluate('/processing-instruction("xml-stylesheet")')->item(0);
// extract the "data" part of it
$data = $pi->data;
// find out where the href starts
$start = strpos($data, 'href=');
// and extract the stylesheet name
$xslname = XML_FOLDER . substr($data, $start + 6, -1);
}
// load the XSL stylesheet
$xsl = new DOMDocument();
$xsl->load($xslname);
// prime the transform engine
$xslt = new XSLTProcessor();
$xslt->importStyleSheet($xsl);
// and away we go!
return $xslt->transformToXml($xml);
}
示例3: 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);
}
示例4: DataAsHTML
function DataAsHTML($xslFileName)
{
$xmlData = new SimpleXMLElement('<page/>');
$this->generateXML($xmlData, $this->data);
$xmlfilemodule = simplexml_load_file("modules/" . $this->data['name'] . "/elements.xml");
$xmlData = dom_import_simplexml($xmlData)->ownerDocument;
foreach (dom_import_simplexml($xmlfilemodule)->childNodes as $child) {
$child = $xmlData->importNode($child, TRUE);
$xmlData->documentElement->appendChild($child);
}
$xslfile = "templates/" . $this->template_name . "/" . $xslFileName . ".xsl";
$xslfilemodule = "modules/" . $this->data['name'] . "/elements.xsl";
if (in_array($this->data['name'], $this->selfPages)) {
$xslfile = "templates/" . $this->template_name . "/" . $this->data['name'] . ".xsl";
}
$domXSLobj = new DOMDocument();
$domXSLobj->load($xslfile);
$xpath = new DomXPath($domXSLobj);
$next = $xpath->query('//xsl:include');
$next = $next->item(0);
$next->setAttribute('href', $xslfilemodule);
$next->setAttribute('xml:base', ROOT_SYSTEM);
$xsl = new XSLTProcessor();
$xsl->importStyleSheet($domXSLobj);
return $xsl->transformToXml($xmlData);
}
示例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: testHeaderDoesNotContainCompleteLogFileContentXsltProcessor
/**
* Tests that the header stylesheet does not reprints the complete log file
* content. This issue occured with some CC versions because the corresponding
* template does not include a default template for <b>/</b>.
*
* @return void
* @group stylesheet
*/
public function testHeaderDoesNotContainCompleteLogFileContentXsltProcessor()
{
$xsl = $this->createXslStylesheet('header.xsl');
$xml = $this->createCruiseControlLog();
$proc = new XSLTProcessor();
$proc->importStylesheet($xsl);
$this->assertSame($this->loadExpectedResult(), trim($proc->transformToXml($xml)));
}
示例7: transformToXML
/**
* @param DOMDocument|SimpleXMLElement $doc
* @return string
*/
public function transformToXML($doc)
{
$styleSheet = $this->styleSheetToDomDocument();
$transpiler = $this->createTranspiler($styleSheet);
libxml_use_internal_errors();
parent::importStylesheet($this->getTranspiledStyleSheet($transpiler, $styleSheet));
return $transpiler->transform(function () use($doc) {
return parent::transformToXml($doc);
});
}
示例8: execute
/**
* Transform the XML/XSL documents into an XML (probably XHTML) document
* @return string
*/
public function execute($parameters = array())
{
$xslt = new XSLTProcessor();
$xslt->importStylesheet($this->xsl);
$xslt->setParameter(null, $parameters);
//unfortunately this doesn't capture any warnings generated whilst transforming
$transformation = $xslt->transformToXml($this->xml);
if ($transformation === false) {
throw new MalformedPage("There was an error tranforming the page");
}
return $transformation;
}
示例9: 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);
}
示例10: render_instance
public static function render_instance(BlockInstance $instance, $editing = false)
{
// Check if XSLT extension is loaded properly, because we will need it...
// The XSL extension implements the XSL standard, performing XSLT transformations using the libxslt library.
$xslext = extension_loaded('xsl');
if (!$xslext) {
$missingextensions = array();
!$xslext && ($missingextensions[] = 'xsl');
$errormsg = '<p>' . get_string('europassextensionmissing', 'artefact.europass') . '</p>';
$errormsg .= '<ul>';
foreach ($missingextensions as $extension) {
$errormsg .= '<li><a href="http://www.php.net/' . $extension . '">' . $extension . '</a></li>';
}
$errormsg .= '</ul>';
return $errormsg;
exit;
}
global $USER;
$configdata = $instance->get('configdata');
if ($configdata == array()) {
$locale = set_default_locale(get_config('lang'));
} else {
$locale = $configdata['locale'];
}
$configdata['viewid'] = $instance->get('view');
// Load up the Europass CV generated XML string
//$xmlDoc = new DOMDocument;
//$xmlDoc->loadXML(generate_europasscv_xml((!empty($configdata['userid']) ? $configdata['userid'] : $USER->get('id')), true, $locale, (!empty($configdata['internaldate']) ? $configdata['internaldate'] : 'dmy11'), (!empty($configdata['externaldate']) ? $configdata['externaldate'] : '/numeric/long')));
$xmlDoc = simplexml_load_string(generate_europasscv_xml(!empty($configdata['userid']) ? $configdata['userid'] : $USER->get('id'), true, $locale, !empty($configdata['internaldate']) ? $configdata['internaldate'] : 'dmy11', !empty($configdata['externaldate']) ? $configdata['externaldate'] : '/numeric/long'));
// Load up the appropriate XSL file, according to selected locale
//$xslDoc = new DOMDocument;
//$xslDoc->load(get_config('docroot') . 'artefact/europass/blocktype/europasscv/xsl/cv_' . $locale . '_V2.0.xsl');
$xslDoc = simplexml_load_string(file_get_contents(get_config('wwwroot') . 'artefact/europass/blocktype/europasscv/xsl/cv_' . $locale . '_V2.0.xsl'));
//Start the XSLT processor and import stylesheet
$xslt = new XSLTProcessor();
$xslt->importStyleSheet($xslDoc);
// Apply the transformation
$html = $xslt->transformToXml($xmlDoc);
$start = stripos($html, '<body>');
$finish = stripos($html, '</body>');
$result = '<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'artefact/europass/theme/raw/static/style/html.css">';
//$result .= '<table width="700" border="0" cellspacing="0" cellpadding="0" class="CV" id="CV">';
$result .= substr($html, $start + 6, $finish - $start);
//$result .= '</table>';
$result = html_entity_decode($result);
// Replace the following reference because it does not exist anymore:
// http://europass.cedefop.europa.eu/instruments/images/logospace.gif
$result = str_replace('http://europass.cedefop.europa.eu/instruments/images/logospace.gif', get_config('wwwroot') . 'artefact/europass/images/space.png', $result);
return $result;
}
示例11: getHtmlForObjectId
public function getHtmlForObjectId(\FrameResponseObject $frameResponseObject)
{
$mplme = \steam_factory::get_object($GLOBALS["STEAM"]->get_id(), $this->id);
if (isset($this->params[1]) && !strstr($this->params[1], "?")) {
$doc = \steam_factory::get_object_by_name($GLOBALS["STEAM"]->get_id(), $mplme->get_path() . "/" . $this->params[1]);
if (isset($doc) && $doc !== 0 && $doc instanceof \steam_document) {
echo $doc->download();
//echo $doc->get_content();
} else {
echo "404";
}
die;
}
$elements = $mplme->get_inventory();
$html = "";
foreach ($elements as $element) {
if ($element->get_name() == "data.xml") {
$xmlContent = $element->get_content();
//$html .= "<b>".$element->get_name()."</b><br><pre>". htmlentities($element->get_content()) . "</pre><br>";
} else {
if ($element->get_name() == $_REQUEST["xslName"] . ".xsl") {
$xslContent = $element->get_content();
//$html .= "<b>".$element->get_name()."</b><br><pre>". htmlentities($element->get_content()) . "</pre><br>";
} else {
//$html .= "<b>".$element->get_name()."</b><br>";
}
}
}
if (isset($xmlContent) && isset($xslContent)) {
$xml = new \DOMDocument();
$xml->loadXML($xmlContent);
$searchstring = '/<includexslt[ 0-9a-zA-Z=\\/\\"]*url="([~\\-0-9a-zA-Z=\\:\\?\\&\\.\\/]+)"[ 0-9a-zA-Z=\\/"]*[ \\-0-9a-zA-Z=\\/"]*\\/>/i';
$xslContent = preg_replace_callback($searchstring, array(&$this, 'cb_replace'), $xslContent);
$xsl = new \DOMDocument();
$xsl->loadXML($xslContent);
$proc = new \XSLTProcessor();
$proc->importStylesheet($xsl);
$html .= $proc->transformToXml($xml);
}
if (isset($_REQUEST['output']) && $_REQUEST['output'] === "download") {
header('Content-Disposition: attachment; filename=data.' . $_REQUEST['xslName']);
}
$rawHtml = new \Widgets\RawHtml();
$rawHtml->setHtml($html);
$frameResponseObject->addWidget($rawHtml);
$frameResponseObject->setHeadline(array(array("name" => "zurück", "link" => "javascript:history.back()"), array("name" => "Mplme")));
return $frameResponseObject;
}
示例12: render
public function render()
{
//return $this->xml;
// processor
$processor = new XSLTProcessor();
// xsl DOMDoc
$xslDoc = new DOMDocument();
$xslDoc->loadXML('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" doctype-system="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN" indent="yes"/>
' . $this->xsl . '</xsl:stylesheet>');
// xml DOMDoc
$xmlDoc = new DOMDocument();
$xmlDoc->loadXML($this->xml);
$processor->importStyleSheet($xslDoc);
return $processor->transformToXml($xmlDoc);
}
示例13: odt2spip_traiter_mathml
function odt2spip_traiter_mathml($chemin_fichier) {
// recuperer le contenu du fichier
if (!$mathml = file_get_contents($chemin_fichier)) return(_T('odtspip:err_transformation_xslt_mathml'));
// virer le DOCTYPE qui plante le parseur vu que la dtd n'est pas disponible
$mathml = preg_replace('/<!DOCTYPE.*?>/i', '', $mathml);
// variable en dur pour xslt utilisée
// $xml_entre = _DIR_TMP.'odt2spip/'.$id_auteur.'/content.xml'; // chemin du fichier xml à lire
$xslt_texte = _DIR_PLUGIN_ODT2SPIP.'inc/xsltml/mmltex.xsl'; // chemin de la xslt à utiliser pour les maths
// appliquer la transformation XSLT sur le fichier content.xml
// déterminer les fonctions xslt à utiliser (php 4 ou php 5)
if (!class_exists('XSLTProcessor')) {
// on est en php4 : utiliser l'extension et les fonction xslt de Sablotron
// Crée le processeur XSLT
$xh = xslt_create();
// si on est sur un serveur Windows utiliser xslt_set_base avec le préfixe file://
if (strpos($_SERVER['SERVER_SOFTWARE'], 'Win') !== false) xslt_set_base($xh, 'file://' . getcwd () . '/');
// lancer le parseur
$arguments = array('/_xml' => $mathml);
$latex_sortie = xslt_process($xh, 'arg:/_xml', $xslt_texte, NULL, $arguments);
if (!$latex_sortie) return(_T('odtspip:err_transformation_xslt_mathml'));
// Détruit le processeur XSLT
xslt_free($xh);
}
else {
// on est php5: utiliser les fonctions de la classe XSLTProcessor
$proc = new XSLTProcessor();
$xml = new DOMDocument();
$xml->loadXML($mathml);
$xsl = new DOMDocument();
$xsl->load($xslt_texte);
$proc->importStylesheet($xsl); // attachement des règles xsl
// lancer le parseur
if (!$latex_sortie = $proc->transformToXml($xml)) return(_T('odtspip:err_transformation_xslt_mathml'));
}
return $latex_sortie;
}
示例14: 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;
}
示例15: _render
/**
* Return the full rendered version of the Horde_Mime_Part object.
*
* @return array See parent::render().
* @throws Horde_Exception
*/
protected function _render()
{
$has_xsl = Horde_Util::extensionExists('xsl');
if ($has_xsl) {
$tmpdir = Horde_Util::createTempDir(true) . '/';
}
$fnames = array('content.xml', 'styles.xml', 'meta.xml');
$tags = array('text:p' => 'p', 'table:table' => 'table border="0" cellspacing="1" cellpadding="0" ', 'table:table-row' => 'tr bgcolor="#cccccc"', 'table:table-cell' => 'td', 'table:number-columns-spanned=' => 'colspan=');
if (!$this->getConfigParam('zip')) {
$this->setConfigParam('zip', Horde_Compress::factory('Zip'));
}
$list = $this->getConfigParam('zip')->decompress($this->_mimepart->getContents(), array('action' => Horde_Compress_Zip::ZIP_LIST));
foreach ($list as $key => $file) {
if (in_array($file['name'], $fnames)) {
$content = $this->getConfigParam('zip')->decompress($this->_mimepart->getContents(), array('action' => Horde_Compress_Zip::ZIP_DATA, 'info' => $list, 'key' => $key));
if ($has_xsl) {
file_put_contents($tmpdir . $file['name'], $content);
} elseif ($file['name'] == 'content.xml') {
return array($this->_mimepart->getMimeId() => array('data' => str_replace(array_keys($tags), array_values($tags), $content), 'status' => array(), 'type' => 'text/html; charset=UTF-8'));
}
}
}
if (!$has_xsl) {
return array();
}
$xslt = new XSLTProcessor();
$xsl = new DOMDocument();
$xsl->load(realpath(__DIR__ . '/Ooo/export/xhtml/opendoc2xhtml.xsl'));
$xslt->importStylesheet($xsl);
$xslt->setParameter('http://www.w3.org/1999/XSL/Transform', array('metaFileURL' => 'file://' . $tmpdir . 'meta.xml', 'stylesFileURL' => 'file://' . $tmpdir . 'styles.xml', 'java' => false));
$xml = new DOMDocument();
$xml->load(realpath($tmpdir . 'content.xml'));
$result = $xslt->transformToXml($xml);
if (!$result) {
$result = libxml_get_last_error()->message;
}
return array($this->_mimepart->getMimeId() => array('data' => $result, 'status' => array(), 'type' => 'text/html; charset=UTF-8'));
}