Example #1
0
 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);
 }
Example #2
0
 public function process($page)
 {
     global $_PLUGIN;
     //echoall($page);
     // call plugins
     //		$pageXml = olivxml_create($page,"page");
     if ($page) {
         $pageXml = OLIVPlugin::call(new simpleXmlElement($page), "render");
         //------------------------------------------------------------------------------
         // convert page xml to html
         if (sessionfile_exists(system::OLIV_TEMPLATE_PATH() . "post.xslt")) {
             $postStylesheet = sessionxml_load_file(system::OLIV_TEMPLATE_PATH() . "post.xslt");
         } else {
             OLIVError::fire("postprocessor.php::process - post.xslt file not found");
             die;
         }
         $htmlProcessor = new XSLTProcessor();
         $htmlProcessor->importStylesheet($postStylesheet);
         $pageString = $htmlProcessor->transformToXML($pageXml);
         //echoall($pageXml->asXML());
         //------------------------------------------------------------------------------
         // run markup parser
         $pageString = $this->markup($pageString);
         return $pageString;
     }
 }
 /**
  * return the xslt processor with the xsl stylesheet loaded
  * @param DOMDocument $xsl
  * @return XSLTProcessor
  */
 public static function getProcessor($xsl_dom)
 {
     // get the processor and import stylesheet xsl
     $xsl_processor = new XSLTProcessor();
     $xsl_processor->importStylesheet($xsl_dom);
     return $xsl_processor;
 }
Example #4
0
function xml2html($xmlcontent, $xsl, $settings)
{
    global $debugMode;
    global $Settings;
    $xmlDoc = new DOMDocument();
    $xmlDoc->load($xmlcontent);
    if ($debugMode) {
        $root = $xmlDoc->documentElement;
        $root->setAttribute("debug", "true");
    }
    foreach (array_keys($settings) as $k) {
        $v = $settings[$k];
        $root = $xmlDoc->documentElement;
        $root->setAttribute($k, $v);
    }
    $xslDoc = new DOMDocument();
    $xslDoc->load($xsl);
    // подменить пути overrides
    $xpath = new DOMXpath($xslDoc);
    $includes = $xpath->query("//xsl:include");
    foreach ($includes as $inc) {
        $ref = $inc->getAttribute("href");
        $newRef = preg_replace('/overrides/i', '../' . $Settings["ThisFolder"] . '/' . $Settings["OverridesFolder"], $ref);
        $inc->setAttribute("href", $newRef);
    }
    $proc = new XSLTProcessor();
    $proc->importStylesheet($xslDoc);
    return $proc->transformToXML($xmlDoc);
}
 /**
  * @see OAIMetadataFormat#toXml
  */
 function toXml(&$oaiRecord, $format = null)
 {
     $record =& $oaiRecord->getData('record');
     switch ($format) {
         case 'oai_dc':
             static $xslDoc, $proc;
             if (!isset($xslDoc) || !isset($proc)) {
                 // Cache the XSL
                 $xslDoc = new DOMDocument();
                 $xslDoc->load('http://www.loc.gov/standards/marcxml/xslt/MARC21slim2OAIDC.xsl');
                 $proc = new XSLTProcessor();
                 $proc->importStylesheet($xslDoc);
             }
             $xmlDoc = new DOMDocument();
             $xmlDoc->loadXML($record->getContents());
             $xml = $proc->transformToXML($xmlDoc);
             // Cheesy: strip the XML header
             if (($pos = strpos($xml, '<oai_dc:dc')) > 0) {
                 $xml = substr($xml, $pos);
             }
             return $xml;
         case 'oai_marc':
         case 'marcxml':
             return $record->getContents();
         default:
             fatalError("Unable to convert MARC to {$format}!\n");
     }
 }
Example #6
0
	public function exec() {
		$proc = new \XSLTProcessor; 
		$proc->importStylesheet($this->_stylesheet);
		$content = $proc->transformToXML($this->_datafile);
		
		return $content;
	}                             
Example #7
0
 /**
  * Обрабатывает данные.
  * @param string $data XML-строка
  */
 public function process($data)
 {
     $errorHandler = new \WebConstructionSet\Xml\LibxmlErrorHandler();
     $xml = new \DOMDocument();
     if (!$xml->loadXML($data)) {
         throw new \ErrorException('Document parse failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
     }
     $xsl = new \DOMDocument();
     if ($this->xslString) {
         if (!$xsl->loadXML($this->xslString)) {
             throw new \ErrorException('XSL stylesheet load/parse failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
         }
     } else {
         $xslPath = $this->getXslStylesheetPath($xml);
         if (!$xslPath) {
             throw new \ErrorException('XSL stylesheet path is not found.', null, null, __FILE__, __LINE__);
         }
         if (!$xsl->load($xslPath)) {
             throw new \ErrorException('XSL stylesheet load/parse failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
         }
     }
     $xslt = new \XSLTProcessor();
     if (!$xslt->importStylesheet($xsl)) {
         throw new \ErrorException('Import XSL stylesheet failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
     }
     $this->resultDoc = $xslt->transformToDoc($xml);
     if (!$this->resultDoc) {
         throw new \ErrorException('XSLT transform failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
     }
     // no return
 }
 /**
  * {@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);
 }
Example #9
0
 /**
  * Executes Params XSLT (transformation to be used to convert parameters into query) for given query.
  */
 function params()
 {
     $document =& JFactory::getDocument();
     $viewName = JRequest::getVar('view', 'params');
     $viewType = $document->getType();
     $view =& $this->getView($viewName, $viewType);
     $data = JRequest::getVar('data', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $query_id = JRequest::getInt('id_query', NULL);
     $result = $data;
     if ($query_id != NULL && !empty($data)) {
         $model_queries =& $this->getModel('queries');
         $query = $model_queries->getQuery($query_id);
         if ($query != NULL && !empty($query->paramsxsl)) {
             $xml = new DOMDocument();
             if ($xml->loadXML($data)) {
                 // start xslt
                 $xslt = new XSLTProcessor();
                 $xsl = new DOMDocument();
                 $xsl->loadXML($query->paramsxsl);
                 $xslt->importStylesheet($xsl);
                 $paramset = $xslt->transformToDoc($xml);
                 $result = $xslt->transformToXML($xml);
                 if ($result === false) {
                     // TODO: any joomla function for this?
                     header('HTTP/1.1 500 Internal Server Error');
                 }
             }
         }
     }
     $view->assign('value', $result);
     $view->display();
 }
Example #10
0
 /**
  * @Route("/{volume}/{id}", requirements={"id" = "\d+", "volume" = "\d+"})
  * @param $volume
  * @param $id
  * @param bool|false $showByName
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function showArticleById($volume, $id, $showByName = false)
 {
     $id_article = 'v' . $volume . '-' . $id;
     $xml_source = new \DOMDocument();
     $xml_source->load('../src/AppBundle/Resources/xml/volume' . $volume . '.xml');
     $xslt_root = new \DOMDocument();
     $xslt_root->load('../src/AppBundle/Resources/xslt/article.xsl');
     $transform = new \XSLTProcessor();
     $transform->importStylesheet($xslt_root);
     $xpath = new \DOMXpath($xml_source);
     $page_debut_xpath = $xpath->query("//div[@type='article' and @xml:id='" . $id_article . "']/preceding::pb[position()\n        =1]");
     $num_vue = $page_debut_xpath->item(0)->attributes->item(1)->nodeValue;
     $page_debut = substr($num_vue, strpos($num_vue, "p") + 1);
     $article_result = $xpath->query("//div[@type='article' and @xml:id='" . $id_article . "']");
     $vedette_adresse_text = $xpath->query("//div[@type='article' and @xml:id='" . $id_article . "']/child::div[position()=1]/child::p[position()=1]/child::seg[@type='vedette_adresse']/descendant::text()");
     $vedette_adresse = '';
     if ($vedette_adresse_text->length > 0) {
         for ($i = 0; $i < $vedette_adresse_text->length; $i++) {
             $vedette_adresse .= $vedette_adresse_text->item($i)->nodeValue;
         }
     }
     $pos_article = null;
     if ($article_result->length > 0) {
         $content = $article_result->item(0);
         $xml_transform = new \DOMDocument();
         $xml_transform->appendChild($xml_transform->importNode($content, true));
         $article = $transform->transformToDoc($xml_transform)->saveHTML();
         $pos_article = intval($id);
         $next_article = $pos_article + 1;
         $previous_article = $pos_article - 1;
         if ($pos_article == 1) {
             $previous_article = null;
         } else {
             if ($showByName) {
                 $previous_article_id = 'v' . $volume . '-' . $previous_article;
                 $previous_article_vedette_adresse_text = $xpath->query("//div[@type='article' and @xml:id='" . $previous_article_id . "']/child::div[position()=1]/child::p[position()=1]/child::seg[@type='vedette_adresse']");
                 if ($previous_article_vedette_adresse_text->length > 0) {
                     $previous_article = $previous_article_vedette_adresse_text->item(0)->textContent;
                     $previous_article = str_replace(" ", "_", $previous_article);
                 }
             }
         }
         $next_article_id = 'v' . $volume . '-' . $next_article;
         $xpath_find_next_article = $xpath->query("//div[@type='article' and @xml:id='" . $next_article_id . "']");
         if ($xpath_find_next_article->length == 0) {
             $next_article = null;
         } else {
             if ($showByName) {
                 $next_article_vedette_adresse_text = $xpath->query("//div[@type='article' and @xml:id='" . $next_article_id . "']/child::div[position()=1]/child::p[position()=1]/child::seg[@type='vedette_adresse']");
                 if ($next_article_vedette_adresse_text->length > 0) {
                     $next_article = $next_article_vedette_adresse_text->item(0)->textContent;
                     $next_article = str_replace(" ", "_", $next_article);
                 }
             }
         }
         return $this->render('AppBundle::article.html.twig', array('article' => $article, 'id_article' => $id, 'name_article' => $vedette_adresse, 'next_article' => $next_article, 'previous_article' => $previous_article, 'volume' => $volume, 'first_page' => $page_debut));
     }
     return $this->render('AppBundle::404.html.twig', array('error' => 404));
 }
Example #11
0
function xmltransform($xml, $xslt_f)
{
    $xslt = new XSLTProcessor();
    $xmldoc = DomDocument::loadXML($xml, LIBXML_COMPACT);
    $xsltdoc = DomDocument::load($xslt_f, LIBXML_COMPACT);
    $xslt->importStylesheet($xsltdoc);
    return $xslt->transformToXML($xmldoc);
}
 /**
  * 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)));
 }
Example #13
0
 /**
  * XSLT to HTML5 covertation
  * @param $htmlDoc
  * @return string
  */
 public static function normalize($htmlDoc)
 {
     $normalizerXml = View\Normalizer::getXML();
     $normalizerDoc = new \DOMDocument();
     $normalizerDoc->loadXML($normalizerXml);
     $normalizerProc = new \XSLTProcessor();
     $normalizerProc->importStylesheet($normalizerDoc);
     return $normalizerProc->transformToXml($htmlDoc);
 }
Example #14
0
 /**
  * Process given document into template and render it with given values.
  *
  * @param DocumentInterface $document
  * @param array $values
  * @return Result
  */
 public function render(DocumentInterface $document, array $values)
 {
     // fill with values
     $xslt = new \XSLTProcessor();
     $template = $this->getTemplate($document);
     $xslt->importStylesheet($template);
     $content = $xslt->transformToDoc($this->createValuesDocument($values));
     Processor::undoEscapeXsl($content);
     return new Result($content, $document);
 }
 private function convert($tableName, \DOMDocument $schemaDocument, $resourcesPath)
 {
     $template = new \DOMDocument('1.0', 'UTF-8');
     $template->load($resourcesPath . '/mysql-schema.xsl');
     $xslt = new \XSLTProcessor();
     $xslt->importStylesheet($template);
     $xslt->setParameter('', 'tableName', $tableName);
     $conversionResult = $this->xslt->transformToXml($schemaDocument);
     return $conversionResult;
 }
function xslt($xmlFile, $xslFile)
{
    $xslDoc = new DOMDocument();
    $xslDoc->load($xslFile);
    $xmlDoc = new DOMDocument();
    $xmlDoc->load($xmlFile);
    $proc = new XSLTProcessor();
    $proc->importStylesheet($xslDoc);
    return $proc->transformToXML($xmlDoc);
}
Example #17
0
function xml2html($xmldata, $xsl)
{
    $xmlDoc = new DOMDocument();
    $xmlDoc->load($xmldata);
    $xslDoc = new DOMDocument();
    $xslDoc->load($xsl);
    $proc = new XSLTProcessor();
    $proc->importStylesheet($xslDoc);
    return $proc->transformToXML($xmlDoc);
}
 function PerformXslTransform()
 {
     $xmlObject = new DOMDocument();
     $xmlObject->loadXml($this->xml);
     $xslt = new XSLTProcessor();
     $xsl = new DOMDocument();
     $xsl->load($this->xslFile, LIBXML_NOCDATA);
     $xslt->importStylesheet($xsl);
     // TODO - Need to pass back xsl styled xml as string, currently does not work
 }
 /**
  * Output a html view of the given wsdl
  *
  * @param string $wsdl_uri https://example.com/plugins/statistics/soap/?wsdl
  */
 public function render($wsdl_uri)
 {
     $proc = new XSLTProcessor();
     $xslDoc = new DOMDocument();
     $xslDoc->load(Config::get('codendi_dir') . "/src/www/soap/wsdl-viewer.xsl");
     $proc->importStylesheet($xslDoc);
     $xmlDoc = new DOMDocument();
     $xmlDoc->loadXML(file_get_contents($wsdl_uri));
     echo $proc->transformToXML($xmlDoc);
 }
function generate($inputTransformation, $outputFile)
{
    $xml = new DOMDocument();
    $xml->load('../universal.xml');
    $xsl = new DOMDocument();
    $xsl->load($inputTransformation);
    $proc = new XSLTProcessor();
    $proc->importStylesheet($xsl);
    $newXml = $proc->transformToXML($xml);
    file_put_contents($outputFile, $newXml);
}
Example #21
0
 public function xslt($style)
 {
     if (!$style instanceof QueryPath) {
         $style = qp($style);
     }
     $sourceDoc = $this->src->top()->get(0)->ownerDocument;
     $styleDoc = $style->get(0)->ownerDocument;
     $processor = new XSLTProcessor();
     $processor->importStylesheet($styleDoc);
     return qp($processor->transformToDoc($sourceDoc));
 }
Example #22
0
	public function render() {
		try {
			$xsltproc = new XSLTProcessor;
			$xsltproc->importStylesheet($this->_styleSheet);
			$this->_outputData = $xsltproc->transformToXML($this->_inputData);
			
			return $this->_outputData;
		} catch (Exception $e) {
			print "Could not process the Datafile with the given Stylesheet: " . $e->getMessage();
		}
	}
Example #23
0
 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);
 }
 /**
  * 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;
 }
function xsl_transform($xml)
{
    // load XML file
    $XML = new DOMDocument();
    $XML->loadXML($xml);
    // XSL transform
    $xslt = new XSLTProcessor();
    $XSL = new DOMDocument();
    $XSL->load('tumblr-dashboard-rss.xsl', LIBXML_NOCDATA);
    $xslt->importStylesheet($XSL);
    echo $xslt->transformToXML($XML);
}
 public static function Transform($xml, $xsl)
 {
     $xml_file = "file://" . $xml;
     $xmlDoc = new DOMDocument();
     $xmlDoc->load($xml_file);
     $xsl_file = "file://" . $xsl;
     $xslDoc = new DOMDocument();
     $xslDoc->load($xsl_file);
     $proc = new XSLTProcessor();
     $proc->importStylesheet($xslDoc);
     return $proc->transformToXML($xmlDoc);
 }
Example #27
0
function xmlconvert($sXml, $xslsheet)
{
    # LOAD XML FILE
    $XML = new DOMDocument();
    $XML->loadXML($sXml);
    # START XSLT
    $xslt = new XSLTProcessor();
    $XSL = new DOMDocument();
    $XSL->load($xslsheet, LIBXML_NOCDATA);
    $xslt->importStylesheet($XSL);
    return $xslt->transformToXML($XML);
}
Example #28
0
 function printXML($xml_path, $xsl_path)
 {
     $xml_dom = new DOMDocument();
     $xml_dom->load($xml_path);
     $xsl_dom = new DOMDocument();
     $xsl_dom->load($xsl_path);
     $proc = new XSLTProcessor();
     $proc->importStylesheet($xsl_dom);
     $doc = $proc->transformToDOC($xml_dom);
     $doc->formatOutput = true;
     return $doc->saveHTML();
 }
Example #29
0
 /**
  * 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);
 }
 /**
  * The main function of this object which simply renders the accumulated data using PHP's XSLTProcessor
  * @access public
  */
 public function render()
 {
     try {
         $xsltproc = new \XSLTProcessor();
         $xsltproc->importStylesheet($this->_styleSheet);
         if (isset($this->_profilerLogPath)) {
             $xsltproc->setProfiling($this->_profilerLogPath);
         }
         return $xsltproc->transformToXML($this->_inputData);
     } catch (Exception $e) {
         echo "Could not process the Datafile with the given Stylesheet: " . $e->getMessage();
     }
 }