예제 #1
0
파일: Xslt.php 프로젝트: volux/dom
 /**
  * @param string $xslFile
  * @param array  $xsltParameters
  * @param Element|Tag|Field|Set $element
  * @param string $ns namespace
  *
  * @return \DOMDocument
  */
 public function transform($xslFile, $xsltParameters = array(), &$element, $ns = '')
 {
     $this->load($xslFile, LIBXML_NOCDATA, $result);
     if (!$result) {
         return $element;
     }
     foreach ($xsltParameters as $name => $value) {
         $this->processor->setParameter($ns, $name, $value);
     }
     if ($element instanceof Set) {
         $processor = $this->processor;
         $element->each(function (Element $el) use($processor, $xslFile) {
             $result = $processor->transformToDoc($el);
             if (!$result) {
                 $el->after($el->ownerDocument->createComment('not transformed with ' . $xslFile));
             } else {
                 $el->replace($result->documentElement, $el);
             }
         });
         return $element;
     }
     $result = $this->processor->transformToDoc($element);
     if (!$result) {
         $element->after($element->ownerDocument->createComment('not transformed with ' . $xslFile));
     }
     $element->replace($result->documentElement, $element);
     return $element;
 }
예제 #2
0
파일: config.php 프로젝트: zcsevcik/edu
function xmltransform($xml_f, $xslt_f)
{
    $xslt = new XSLTProcessor();
    $xmldoc = DomDocument::load($xml_f);
    $xsltdoc = DomDocument::load($xslt_f);
    $xslt->importStylesheet($xsltdoc);
    if (isset($_SESSION['user'])) {
        $xslt->setParameter("", "login", $_SESSION['user']);
    } else {
        $xslt->setParameter("", "login", "_nobody");
    }
    return $xslt->transformToXML($xmldoc);
}
예제 #3
0
 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
0
 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;
 }
/**
 * @desc Definition des paramètres passés à l'XSL de rendu du formulaire
 * @param XSLTProcessor $xslProc Processeur XSL  
 * @return XSLTProcessor HTML à afficher
 * @author WLT
 * @history le 17/02/2011 par WLT : suppression du filtre investigateur pour la liste des centres  
 **/
function uisubject_getInterface_xslParameters($FormOID, $xslProc, $uisubject)
{
    //Paramètres passés au StudyEventForm pour permettre d'afficher les codelistes en liste déroulantes
    if ($FormOID == "") {
        $xslProc->setParameter('', 'CodeListForceSelect', 'CL.$YN CL.$SYMB');
        //valeurs séparées par un espace
    }
    switch ($FormOID) {
        case 'FORM.ENROL':
            //Liste des centres où l'utilisateur connecté est investigateur
            $profiles = $uisubject->m_ctrl->boacl()->getUserProfiles();
            $sitesList = "<select name='text_string_ENROL@SITEID_0'>";
            foreach ($profiles as $profile) {
                $sitesList .= "<option value='{$profile['siteId']}'>{$profile['siteName']}</option>";
            }
            $sitesList .= "</select>";
            $xslProc->setParameter('', 'sitesList', $sitesList);
            $xslProc->setParameter('', 'SubjectKey', $_GET['SubjectKey']);
            break;
        case 'FORM.SV':
            $xslProc->setParameter('', 'StudyEventOID', $_GET['StudyEventOID']);
            break;
        case 'FORM.HE':
            $xslProc->setParameter('', 'BRTHDTC', $uisubject->m_ctrl->bocdiscoo()->getValue($_GET['SubjectKey'], "1", "0", "FORM.IC", "0", "DM", "0", "DM.BRTHDTC"));
            break;
        case 'FORM.ASS':
            $xslProc->setParameter('', 'StudyEventOID', $_GET['StudyEventOID']);
            break;
        case 'FORM.AE':
            $xslProc->setParameter('', 'FormRepeatKey', $_GET['FormRepeatKey']);
            break;
    }
}
예제 #6
0
 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;
 }
예제 #7
0
 /**
  * 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;
 }
예제 #8
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);
 }
예제 #9
0
function runXSLT($xml, $xsl, $params)
{
    $loadfile = new DOMDocument();
    $processor = new XSLTProcessor();
    $loadfile->load($xsl);
    $processor->importStyleSheet($loadfile);
    foreach ($params as $key => $value) {
        $processor->setParameter('', $key, $value);
    }
    $loadfile->load($xml);
    return $processor->transformToXML($loadfile);
}
예제 #10
0
파일: Xslt.php 프로젝트: rali-udem/JSrealB
 public static function applyXsltTemplateToXml($sXmlFileRealPath, $sXslFileRealPath, array $aParameterList = array())
 {
     $xsldoc = new DOMDocument();
     $xsldoc->load($sXslFileRealPath);
     $xmldoc = new DOMDocument();
     $xmldoc->load($sXmlFileRealPath);
     $xsl = new XSLTProcessor();
     $xsl->importStyleSheet($xsldoc);
     foreach ($aParameterList as $sName => $uValue) {
         $xsl->setParameter(null, $sName, $uValue);
     }
     return $xsl->transformToXML($xmldoc);
 }
예제 #11
0
파일: Xslt.php 프로젝트: namesco/Docblox
  /**
   * Generate the documentation pages for the given files.
   *
   * @param string[] $files
   * @param DOMDocument $xml
   *
   * @return void
   */
  protected function generateFiles($files, $xml)
  {
    $this->log('Started generating the static HTML files');

    // prepare the xsl document
    $xsl = new DOMDocument();
    $xsl->load($this->getThemePath() . '/file.xsl');

    // configure the transformer
    $proc = new XSLTProcessor();
    $proc->importStyleSheet($xsl); // attach the xsl rules
    $proc->setParameter('', 'search_template', ($this->getSearchObject() !== false) ? $this->getSearchObject()->getXslTemplateName() : 'none');

    $file_count = count($files);
    foreach ($files as $key => $file)
    {
      $this->log('Processing file #' . str_pad(($key + 1), strlen($file_count), ' ', STR_PAD_LEFT) . ' of ' . $file_count . ': ' . $file);
      $proc->setParameter('', 'file', $file);
      $proc->setParameter('', 'title', $file);
      $this->transformTemplateToFile($xml, $proc, $this->generateFilename($file));
    }
    $this->log('Finished generating the static HTML files');
  }
예제 #12
0
 /**
  * Convert documents between two formats
  *
  * Convert documents of the given type to the requested type.
  *
  * @param ezcDocumentXmlBase $doc
  * @return ezcDocumentXmlBase
  */
 public function convert($doc)
 {
     // Create XSLT processor, if not yet initialized
     if ($this->xsltProcessor === null) {
         $stylesheet = new DOMDocument();
         $stylesheet->load($this->options->xslt);
         $this->xsltProcessor = new XSLTProcessor();
         $this->xsltProcessor->importStyleSheet($stylesheet);
     }
     // Set provided parameters.
     foreach ($this->options->parameters as $namespace => $parameters) {
         foreach ($parameters as $option => $value) {
             $this->xsltProcessor->setParameter($namespace, $option, $value);
         }
     }
     // We want to handle the occured errors ourselves.
     $oldErrorHandling = libxml_use_internal_errors(true);
     // Transform input document
     $dom = $this->xsltProcessor->transformToDoc($doc->getDomDocument());
     $errors = $this->options->failOnError ? libxml_get_errors() : null;
     libxml_clear_errors();
     libxml_use_internal_errors($oldErrorHandling);
     // If there are errors and the error handling is activated throw an
     // exception with the occured errors.
     if ($errors) {
         throw new ezcDocumentErroneousXmlException($errors);
     }
     // Reset parameters, so they are not automatically applied to the next
     // traansformation.
     foreach ($this->options->parameters as $namespace => $parameters) {
         foreach ($parameters as $option => $value) {
             $this->xsltProcessor->removeParameter($namespace, $option);
         }
     }
     // Build document from transformation and return that.
     return $this->buildDocument($dom);
 }
예제 #13
0
/**
 * Transform template details xml to html form.
 *
 * Param template_xml - string contains template details xml
 * Returns string contains html form
 */
function zetaprints_get_html_from_xml($xml, $xslt, $params)
{
    if (is_string($xml)) {
        $xml_dom = new DOMDocument();
        $xml_dom->loadXML($xml);
    } else {
        $xml_dom = $xml;
    }
    $xslt_dom = new DOMDocument();
    $xslt_dom->load(dirname(__FILE__) . '/xslt/' . $xslt . '.xslt');
    $proc = new XSLTProcessor();
    $proc->importStylesheet($xslt_dom);
    $proc->setParameter('', $params);
    return $proc->transformToXML($xml_dom);
}
 function transform()
 {
     $dir = new PhingFile($this->toDir);
     if (!$dir->exists()) {
         throw new BuildException("Directory '" . $this->toDir . "' does not exist");
     }
     $xslfile = $this->getStyleSheet();
     $xsl = new DOMDocument();
     $xsl->load($xslfile->getAbsolutePath());
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xsl);
     ExtendedFileStream::registerStream();
     // no output for the framed report
     // it's all done by extension...
     $proc->setParameter('', 'output.dir', $dir->getAbsolutePath());
     $proc->transformToXML($this->document);
 }
예제 #15
0
파일: xslt.php 프로젝트: Nolfneo/docvert
function xsltTransform($xmlString, $xsltPath, $xsltArguments = null)
{
    if (!file_exists($xsltPath)) {
        webserviceError('&error-xslt-path-not-found;', 500, array('path' => $xsltPath));
    }
    $result = null;
    $xsltEnabledStatus = getXsltEnabledStatus();
    switch ($xsltEnabledStatus) {
        case 'php5':
            $xslt = new XSLTProcessor();
            $xsltDocument = new DOMDocument();
            $xsltDocument->load($xsltPath);
            $xslt->importStyleSheet($xsltDocument);
            if (is_array($xsltArguments)) {
                foreach ($xsltArguments as $key => $value) {
                    $xslt->setParameter('', $key, $value);
                }
            }
            $errorLevelToDescribeMerelyDeprecatedWarnings = 999999;
            $xmlDocument = new DOMDocument();
            $xmlDocument->loadXML($xmlString);
            $result = $xslt->transformToXML($xmlDocument);
            break;
        case 'php4':
            $xsltproc = xslt_create();
            $xmlString = array('/_xml' => $xmlString);
            $xsltPath = 'file://' . $xsltPath;
            $result = @xslt_process($xsltproc, 'arg:/_xml', $xsltPath, NULL, $xmlString, $xsltArguments) or webServiceError('&error-xslt-processor-error;', 500, array('path' => $xsltPath, 'errorMessage' => xslt_error($xsltproc)));
            if (empty($result) or xslt_error($xsltproc) != null) {
                webServiceError('&error-xslt-processor-error;', 500, array('path' => $xsltPath, 'errorMessage' => xslt_error($xsltproc)));
            }
            xslt_free($xsltproc);
            break;
        default:
            $commandLineMessage = '';
            $phpVersion = getPhpVersion();
            if ($phpVersion >= 5) {
                webServiceError('&error-xslt-not-available;');
            } else {
                webServiceError('&error-php5-required;', 500, array('phpVersion' => $phpVersion));
            }
    }
    return $result;
}
function loadRecordHTML($recHMLFilename, $styleFilename)
{
    global $recID, $outputFilename;
    $recHmlDoc = new DOMDocument();
    $recHmlDoc->load($recHMLFilename);
    $recHmlDoc->xinclude();
    if (!$styleFilename) {
        return $recHmlDoc->saveHTMLFile($outputFilename);
    }
    $xslDoc = DOMDocument::load($styleFilename);
    $xslProc = new XSLTProcessor();
    $xslProc->importStylesheet($xslDoc);
    // set up common parameters for stylesheets.
    //	$xslProc->setParameter('','hbaseURL',HEURIST_BASE_URL);
    //	$xslProc->setParameter('','dbName',HEURIST_DBNAME);
    //	$xslProc->setParameter('','dbID',HEURIST_DBID);
    $xslProc->setParameter('', 'standalone', '1');
    $xslProc->transformToURI($recHmlDoc, $outputFilename);
}
예제 #17
0
 /**
  * Transformation xsl
  */
 static function xsl($xslFile, $dom, $dest = null, $pars = null)
 {
     $xsl = new DOMDocument("1.0", "UTF-8");
     $xsl->load($xslFile);
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xsl);
     // transpose params
     if ($pars && count($pars)) {
         foreach ($pars as $key => $value) {
             $proc->setParameter('', $key, $value);
         }
     }
     // we should have no errors here
     if ($dest) {
         $proc->transformToUri($dom, $dest);
     } else {
         return $proc->transformToXML($dom);
     }
 }
예제 #18
0
 function transform()
 {
     if (file_exists($this->xslPath)) {
         $xml = $this->data->dom();
         $xsl = new DOMDocument();
         $xsl->load($this->xslPath);
         //			$xml = new DOMDocument("1.0","UTF-8");
         //			$xml->loadXML($this->data);
         $proc = new XSLTProcessor();
         $proc->importStyleSheet($xsl);
         if (count($this->xslParam)) {
             $proc->setParameter("", $this->xslParam);
         }
         $this->output = $proc->transformToXML($xml);
     } else {
         $this->output = $this->data->saveXML();
         //			$this->data = "<p><b>No transformation file found</b></p>";
     }
 }
예제 #19
0
 /**
  * Process incoming parameters and display the page.
  *
  * @return void
  * @access public
  */
 public function launch()
 {
     global $configArray;
     header('Content-Type: text/html; charset=ISO-8859-1');
     echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\">\n";
     // Load information on the requested record:
     // Setup Search Engine Connection
     $db = ConnectionManager::connectToIndex();
     // Retrieve the record from the index
     if (!($record = $db->getRecord($_REQUEST['id']))) {
         PEAR::raiseError(new PEAR_Error('Record Does Not Exist'));
     }
     if (strlen($record['fullrecord'])) {
         $xml = $record['fullrecord'];
         $result = simplexml_load_string($xml);
     }
     $url = isset($result->url) ? trim($result->url) : false;
     if (empty($url)) {
         PEAR::raiseError(new PEAR_Error('Not a VuDL Record'));
     }
     // Set up the XSLT processor:
     $xslt = new XSLTProcessor();
     // Register all non-private methods other than "launch" for access via XSLT:
     $class = get_class($this);
     $methods = get_class_methods($class);
     foreach ($methods as $method) {
         if ($method != 'launch' && substr($method, 0, 1) != '_') {
             $xslt->registerPHPFunctions($class . '::' . $method);
         }
     }
     $xsl = new DOMDocument();
     $xsl->load(dirname(__FILE__) . '/xsl/transform.xsl');
     $xslt->importStylesheet($xsl);
     $xslt->setParameter('', 'path', $configArray['Site']['path']);
     $sXml = file_get_contents($url);
     $XML = new DOMDocument();
     $XML->loadXML($sXml);
     $html = $xslt->transformToXML($XML);
     $html = str_replace('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', '', $html);
     $html = preg_replace('/<html[^>]*>/', '<html>', $html);
     echo $html;
 }
예제 #20
0
 /**
  * Generate the proxy class
  *
  */
 public function generateProxy()
 {
     $this->_validateAndBuidOptions();
     $xsl_path = get_cfg_var('ODataphp_path');
     if (strlen($xsl_path) == 0) {
         throw new Exception(self::$_messages['ServicePath_Not_Set']);
     }
     $xsl_path = $xsl_path . "/" . "Common/WCFDataServices2PHPProxy.xsl";
     $xslDoc = new DOMDocument();
     $xslDoc->load($xsl_path);
     $proc = new XSLTProcessor();
     $proc->importStylesheet($xslDoc);
     $proc->setParameter('', 'DefaultServiceURI', $this->_options['/uri_withoutSlash']);
     $this->_metadataDoc = new DOMDocument();
     if (!empty($this->_options['/metadata'])) {
         $this->_metadataDoc->load($this->_options['/metadata']);
     } else {
         $metadata = $this->_getMetaDataOverCurl();
         $this->_metadataDoc->loadXML($metadata);
     }
     $proc->transformToURI($this->_metadataDoc, $this->_options['/out_dir'] . "/" . $this->_getFileName());
 }
예제 #21
0
 public function convert($destination, $destinationNs, array $nsMap, array $allowMap, $ext = 'xml')
 {
     if (is_dir($destination)) {
         throw new \RuntimeException("Destination could not be a directory.");
     }
     if (!$nsMap) {
         throw new \RuntimeException(__CLASS__ . " requires at least one ns-map (for {$destinationNs} namespace).");
     }
     $files = array();
     foreach ($nsMap as $value) {
         $dir = rtrim($value["dir"], "\\//");
         TypeMapper::addNamespace($value["phpNs"], $value["xmlNs"]);
         $files = array_merge($files, glob("{$dir}/*.{$ext}"));
     }
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $root = $dom->createElement('root');
     $dom->appendChild($root);
     foreach ($files as $file) {
         $mapping = new \DOMDocument('1.0', 'UTF-8');
         $mapping->load($file);
         $newnode = $dom->importNode($mapping->documentElement, true);
         $root->appendChild($newnode);
     }
     $this->handleAllowMap($allowMap, $dom);
     $xsd = new \DOMDocument('1.0', 'UTF-8');
     $xsd->load(__DIR__ . '/../Resources/xsd/convert.xsl');
     $processor = new \XSLTProcessor();
     $processor->registerPHPFunctions();
     $processor->setParameter('', 'targetNs', $destinationNs);
     $processor->importStylesheet($xsd);
     $newDom = $processor->transformToDoc($dom);
     $this->fixXsd($newDom, $destinationNs);
     $ret = $newDom->save($destination);
     if ($ret > 0) {
         return true;
     } else {
         return false;
     }
 }
예제 #22
0
파일: Ooo.php 프로젝트: raz0rsdge/horde
 /**
  * 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'));
 }
 /**
  * Apply a process (xslt stylesheet) on an input (xml file) and save output.
  *
  * @param string $input Path of input file.
  * @param string $stylesheet Path of the stylesheet.
  * @param string $output Path of the output file. If none, a temp file will
  * be used.
  * @param array $parameters Parameters array.
  * @return string|null Path to the output file if ok, null else.
  */
 private function _processXsltViaPhp($input, $stylesheet, $output = '', $parameters = array())
 {
     if (empty($output)) {
         $output = tempnam(sys_get_temp_dir(), 'omk_');
     }
     try {
         $domXml = $this->_domXmlLoad($input);
         $domXsl = $this->_domXmlLoad($stylesheet);
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($domXsl);
     $proc->setParameter('', $parameters);
     $result = $proc->transformToURI($domXml, $output);
     @chmod($output, 0640);
     // There is no specific message for error with this processor.
     if ($result === false) {
         $message = __('An error occurs during the xsl transformation of the file "%s" with the sheet "%s".', $input, $stylesheet);
         throw new OaiPmhStaticRepository_Exception($message);
     }
     return $output;
 }
 private function transform(DOMDocument $document)
 {
     $dir = new PhingFile($this->toDir);
     if (!$dir->exists()) {
         throw new BuildException("Directory '" . $this->toDir . "' does not exist");
     }
     $xslfile = $this->getStyleSheet();
     $xsl = new DOMDocument();
     $xsl->load($xslfile->getAbsolutePath());
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xsl);
     if ($this->format == "noframes") {
         $writer = new FileWriter(new PhingFile($this->toDir, "checkstyle-noframes.html"));
         $writer->write($proc->transformToXML($document));
         $writer->close();
     } else {
         ExtendedFileStream::registerStream();
         // no output for the framed report
         // it's all done by extension...
         $dir = new PhingFile($this->toDir);
         $proc->setParameter('', 'output.dir', $dir->getAbsolutePath());
         $proc->transformToXML($document);
     }
 }
예제 #25
0
 /**
  * Applies XSL style sheet to template's parts.
  *
  * @param \DOMDocument $xslDOMDocument
  * @param array $xslOptions
  * @param string $xslOptionsURI
  * @return void
  * @throws \PhpOffice\PhpWord\Exception\Exception
  */
 public function applyXslStyleSheet($xslDOMDocument, $xslOptions = array(), $xslOptionsURI = '')
 {
     $xsltProcessor = new \XSLTProcessor();
     $xsltProcessor->importStylesheet($xslDOMDocument);
     if (false === $xsltProcessor->setParameter($xslOptionsURI, $xslOptions)) {
         throw new Exception('Could not set values for the given XSL style sheet parameters.');
     }
     $xmlDOMDocument = new \DOMDocument();
     if (false === $xmlDOMDocument->loadXML($this->temporaryDocumentMainPart)) {
         throw new Exception('Could not load XML from the given template.');
     }
     $xmlTransformed = $xsltProcessor->transformToXml($xmlDOMDocument);
     if (false === $xmlTransformed) {
         throw new Exception('Could not transform the given XML document.');
     }
     $this->temporaryDocumentMainPart = $xmlTransformed;
 }
예제 #26
0
파일: tinymce.php 프로젝트: dregula/Annotum
/**
 * Prior to outputting the value of the textarea, convert a couple
 * entities that wouldn't be able to be seen, into HTML.  This is
 * done on the fly, so that the XML stored in the DB is correct.
 *
 * @param string $content
 * @return void
 */
function anno_process_editor_content($content)
{
    // Break to BR
    $content = str_replace('<break />', '<br />', $content);
    // Load the XML source
    $xml = new DOMDocument();
    $xml->loadXML('<textorum>' . $content . '</textorum>');
    $xsl = new DOMDocument();
    $xsl->load(trailingslashit(get_template_directory()) . 'js/textorum/dist/textorum/xsl/xml2cke.xsl');
    // Configure the transformer
    $proc = new XSLTProcessor();
    $proc->importStyleSheet($xsl);
    // attach the xsl rules
    $proc->setParameter(null, 'inlineelements', 'named-content,ext-link,inline-graphic,alt-text,lbl,long-desc,copyright-statement,permissions,copyright-holder,license,license-p,attrib,inline-formula,xref');
    $proc->setParameter(null, 'bold', 'bold');
    $proc->setParameter(null, 'italic', 'italic');
    $proc->setParameter(null, 'monospace', 'monospace');
    $proc->setParameter(null, 'underline', 'underline');
    $proc->setParameter(null, 'fixedelements', 'textorum,table,thead,tbody,td,tr,th,sub,sup');
    $content = $proc->transformToXML($xml);
    $content = preg_replace('/<\\/?textorum[^>]*>/', '', $content);
    return $content;
    phpQuery::newDocument($content);
    // Convert inline-graphics to <img> tags so they display
    anno_xml_to_html_replace_inline_graphics($content);
    // Convert caption to cap
    anno_replace_caption_tag($content);
    // Convert label to lbl
    anno_replace_label_tag($content);
    // Remove p tags wrapping list items
    anno_remove_p_from_list_items($content);
    // Remove p tags from disp-quotes
    //anno_remove_p_from_disp_quote_items($content);
    // We need a clearfix for floated images.
    $figs = pq('fig');
    foreach ($figs as $fig) {
        $fig = pq($fig);
        $img_src = '';
        // Check if we're using bugged version of libxml
        if (version_compare(LIBXML_DOTTED_VERSION, '2.6.29', '<')) {
            $img_src = anno_get_attribute_value_regex($fig, 'media', 'xlink:href');
        } else {
            $img_src = $fig->find('media')->attr('xlink:href');
        }
        $fig->prepend('<img src="' . $img_src . '" />');
        // _mce_bogus stripped by tinyMCE on save
        $fig->append('<div _mce_bogus="1" class="clearfix"></div>');
    }
    return phpQuery::getDocument();
}
예제 #27
0
function processTransformation($xml, $xsl, $params = 0)
{
    global $def;
    $domXml = new DOMDocument("1.0", "iso-8859-1");
    $domXml->loadXML($xml);
    $domXsl = new DOMDocument("1.0", "iso-8859-1");
    $domXsl->load($xsl);
    $proc = new XSLTProcessor();
    $proc->importStylesheet($domXsl);
    $proc->setParameter('', 'xml-path', $def['DATABASE_PATH'] . "xml/");
    if ($params) {
        foreach ($params as $key => $value) {
            $proc->setParameter('', $key, $value);
        }
    }
    $result = $proc->transformToXML($domXml);
    //    $result = (String) $result->saveXML();
    return $result;
}
예제 #28
0
 /**
  * Performs XSL transformation and render the output.
  * @param THtmlWriter The writer used for the rendering purpose
  */
 public function render($writer)
 {
     if (($document = $this->getSourceXmlDocument()) === null) {
         $textWriter = new TTextWriter();
         parent::render(new THtmlWriter($textWriter));
         $document = new DOMDocument();
         $document->loadXML($textWriter->flush());
     }
     $stylesheet = $this->getTransformXmlDocument();
     // Perform XSL transformation
     $xslt = new XSLTProcessor();
     $xslt->importStyleSheet($stylesheet);
     // Check for parameters
     $parameters = $this->getParameters();
     foreach ($parameters as $name => $value) {
         $xslt->setParameter('', $name, $value);
     }
     $output = $xslt->transformToXML($document);
     // Write output
     $writer->write($output);
 }
예제 #29
0
 /**
  * Use PHP5's DOMDocument and XSLTProcessor to do the transformation
  * @param $xml mixed
  * @param $xmlType integer
  * @param $xsl mixed
  * @param $xslType integer
  * @param $resultType integer
  * @return mixed return type depends on the $returnType parameter and can be
  *  DOMDocument or string. Returns boolean "false" on error.
  */
 function &_transformPHP5(&$xml, $xmlType, &$xsl, $xslType, $resultType)
 {
     // Prepare the XML DOM
     if ($xmlType == XSL_TRANSFORMER_DOCTYPE_DOM) {
         // We already have a DOM document, no need to create one
         assert(is_a($xml, 'DOMDocument'));
         $xmlDOM =& $xml;
     } else {
         // Instantiate and configure the XML DOM document
         $xmlDOM = new DOMDocument('1.0', XSLT_PROCESSOR_ENCODING);
         // These are required for external entity resolution (eg. &nbsp;), but can slow processing
         // substantially (20-100x), often up to 60s.  This can be solved by use of local catalogs, ie.
         // putenv("XML_CATALOG_FILES=/path/to/catalog.ent");
         //
         // see:  http://www.whump.com/moreLikeThis/link/03815
         $xmlDOM->recover = true;
         $xmlDOM->substituteEntities = true;
         $xmlDOM->resolveExternals = true;
         // Load the XML based on its type
         switch ($xmlType) {
             case XSL_TRANSFORMER_DOCTYPE_FILE:
                 $xmlDOM->load($xml);
                 break;
             case XSL_TRANSFORMER_DOCTYPE_STRING:
                 $xmlDOM->loadXML($xml);
                 break;
             default:
                 assert(false);
         }
     }
     // Prepare the XSL DOM
     if ($xslType == XSL_TRANSFORMER_DOCTYPE_DOM) {
         // We already have a DOM document, no need to create one
         assert(is_a($xsl, 'DOMDocument'));
         $xslDOM =& $xsl;
     } else {
         // Instantiate the XSL DOM document
         $xslDOM = new DOMDocument('1.0', XSLT_PROCESSOR_ENCODING);
         // Load the XSL based on its type
         switch ($xslType) {
             case XSL_TRANSFORMER_DOCTYPE_FILE:
                 $xslDOM->load($xsl);
                 break;
             case XSL_TRANSFORMER_DOCTYPE_STRING:
                 $xslDOM->loadXML($xsl);
                 break;
             default:
                 assert(false);
         }
     }
     // Create and configure the XSL processor
     $processor = new XSLTProcessor();
     // Register PHP functions if requested.
     // NB: This can open potential security issues; see FAQ/README
     if ($this->registerPHPFunctions) {
         $processor->registerPHPFunctions($this->registerPHPFunctions);
     }
     // Set XSL parameters (if any)
     if (is_array($this->parameters)) {
         foreach ($this->parameters as $param => $value) {
             $processor->setParameter(null, $param, $value);
         }
     }
     //  Import the style sheet
     $processor->importStylesheet($xslDOM);
     // Process depending on the requested result type
     switch ($resultType) {
         case XSL_TRANSFORMER_DOCTYPE_STRING:
             $resultXML = $processor->transformToXML($xmlDOM);
             return $resultXML;
         case XSL_TRANSFORMER_DOCTYPE_DOM:
             $resultDOM = $processor->transformToDoc($xmlDOM);
             return $resultDOM;
         default:
             assert(false);
     }
 }
 /**
  * transformCollectionXML
  *
  * Transforms Collection XML to Desired Format
  *
  * @param string $source      The source of the Hierarchy Tree
  * @param string $context     The Context in which the tree is being displayed
  * @param string $mode        The Mode in which the tree is being displayed
  * @param string $hierarchyID The hierarchy to get the tree for
  * @param string $recordID    The currently selected Record
  *
  * @return string A HTML List
  * @access public
  */
 protected function transformCollectionXML($source, $context, $mode, $hierarchyID, $recordID)
 {
     global $configArray;
     $transformation = ucfirst($context) . ucfirst($mode);
     $inHierarchies = $this->recordDriver->getHierarchyTopID();
     $inHierarchiesTitle = $this->recordDriver->getHierarchyTopTitle();
     $hierarchyTitle = $this->getHierarchyName($hierarchyID, $inHierarchies, $inHierarchiesTitle);
     $hierarchyType = $this->recordDriver->getHierarchyType();
     $hierarchyDriver = HierarchyFactory::initHierarchy($hierarchyType);
     $base = $configArray['Site']['url'];
     if ($source == "XMLFile") {
         $xmlFile = "services/Collection/xml/" . $hierarchyID . ".xml";
         $xmlFile = file_get_contents($xmlFile);
     } elseif ($source == "Solr") {
         $xmlFile = $this->getXMLFromSolr($hierarchyID);
     }
     $xslFile = "services/Collection/xsl/Storeto" . $transformation . ".xsl";
     if (!file_exists($xslFile) || $xmlFile == false) {
         return false;
     }
     $doc = new DOMDocument();
     $xsl = new XSLTProcessor();
     $doc->load($xslFile);
     $xsl->importStyleSheet($doc);
     $doc->loadXML($xmlFile);
     // Append Collection ID, Collection Title && Record ID
     $xsl->setParameter('', 'titleText', translate("collection_view_record"));
     $xsl->setParameter('', 'collectionID', $hierarchyID);
     $xsl->setParameter('', 'collectionTitle', $hierarchyTitle);
     $xsl->setParameter('', 'baseURL', $base);
     $xsl->setParameter('', 'context', $context);
     $xsl->setParameter('', 'recordID', $recordID);
     return $xsl->transformToXML($doc);
 }