function xml_xsl($xmlContent, $xslFile, $debug) { if ($xmlContent == '') { die("falta o XML"); } if ($xslFile == '') { die("falta XSL para transformar\n" . $xmlContent); } if (!file_exists($xslFile)) { die($xslFile . " not found."); } $xslt = new XSLTransformer(); $xslt->xml = $this->insertProcessingInstruction(trim($xmlContent)); if ($debug == "XML") { die($xslt->xml); } $xslt->setXsl($xslFile); if ($debug == "XSL") { die($xslt->xsl . '<!--' . $xslFile . '-->'); } $xslt->transform(); //$r = utf8_decode($xslt->getOutput()); $r = $xslt->getOutput(); return $r . $hidden; }
function _cacheMiss(&$cache, $id) { $allCodelistItems =& Registry::get('all' . $this->getListName() . 'CodelistItems', true, null); if ($allCodelistItems === null) { // Add a locale load to the debug notes. $notes =& Registry::get('system.debug.notes'); $locale = $cache->cacheId; if ($locale == null) { $locale = AppLocale::getLocale(); } $filename = $this->getFilename($locale); $notes[] = array('debug.notes.codelistItemListLoad', array('filename' => $filename)); // Reload locale registry file $xmlDao = new XMLDAO(); $listName = $this->getListName(); // i.e., 'List30' import('lib.pkp.classes.codelist.ONIXParserDOMHandler'); $handler = new ONIXParserDOMHandler($listName); import('lib.pkp.classes.xslt.XSLTransformer'); import('lib.pkp.classes.file.FileManager'); import('classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $fileManager = new FileManager(); // Ensure that the temporary file dir exists $tmpDir = $temporaryFileManager->getBasePath(); if (!file_exists($tmpDir)) { mkdir($tmpDir); } $tmpName = tempnam($tmpDir, 'ONX'); $xslTransformer = new XSLTransformer(); $xslTransformer->setParameters(array('listName' => $listName)); $xslTransformer->setRegisterPHPFunctions(true); $xslFile = 'lib/pkp/xml/onixFilter.xsl'; $filteredXml = $xslTransformer->transform($filename, XSL_TRANSFORMER_DOCTYPE_FILE, $xslFile, XSL_TRANSFORMER_DOCTYPE_FILE, XSL_TRANSFORMER_DOCTYPE_STRING); if (!$filteredXml) { assert(false); } $data = null; if (is_writeable($tmpName)) { $fp = fopen($tmpName, 'wb'); fwrite($fp, $filteredXml); fclose($fp); $data = $xmlDao->parseWithHandler($tmpName, $handler); $fileManager->deleteFile($tmpName); } else { fatalError('misconfigured directory permissions on: ' . $tmpDir); } // Build array with ($charKey => array(stuff)) if (isset($data[$listName])) { foreach ($data[$listName] as $code => $codelistData) { $allCodelistItems[$code] = $codelistData; } } if (is_array($allCodelistItems)) { asort($allCodelistItems); } $cache->setEntireCache($allCodelistItems); } return null; }
/** * Create and return a representation node. Extend the parent class * with publication format specific data. * @param $doc DOMDocument * @param $representation Representation * @return DOMElement */ function createRepresentationNode($doc, $representation) { $representationNode = parent::createRepresentationNode($doc, $representation); $representationNode->setAttribute('approved', $representation->getIsApproved() ? 'true' : 'false'); $representationNode->setAttribute('available', $representation->getIsAvailable() ? 'true' : 'false'); $representationNode->setAttribute('physical_format', $representation->getPhysicalFormat() ? 'true' : 'false'); // If all nexessary press settings exist, export ONIX metadata $context = $this->getDeployment()->getContext(); if ($context->getSetting('publisher') && $context->getSetting('location') && $context->getSetting('codeType') && $context->getSetting('codeValue')) { $submission = $this->getDeployment()->getSubmission(); $filterDao = DAORegistry::getDAO('FilterDAO'); $nativeExportFilters = $filterDao->getObjectsByGroup('monograph=>onix30-xml'); assert(count($nativeExportFilters) == 1); // Assert only a single serialization filter $exportFilter = array_shift($nativeExportFilters); $exportFilter->setDeployment(new Onix30ExportDeployment(Request::getContext(), Request::getUser())); $onixDoc = $exportFilter->execute($submission); if ($onixDoc) { // we do this to ensure validation. // assemble just the Product node we want. $publicationFormatDOMElement = $exportFilter->createProductNode($doc, $submission, $representation); if ($publicationFormatDOMElement instanceof DOMElement) { import('lib.pkp.classes.xslt.XSLTransformer'); $xslTransformer = new XSLTransformer(); $xslFile = 'plugins/importexport/native/onixProduct2NativeXml.xsl'; $productXml = $publicationFormatDOMElement->ownerDocument->saveXML($publicationFormatDOMElement); $filteredXml = $xslTransformer->transform($productXml, XSL_TRANSFORMER_DOCTYPE_STRING, $xslFile, XSL_TRANSFORMER_DOCTYPE_FILE, XSL_TRANSFORMER_DOCTYPE_STRING); $representationFragment = $doc->createDocumentFragment(); $representationFragment->appendXML($filteredXml); $representationNode->appendChild($representationFragment); } } } return $representationNode; }
function xml_xsl($xml, $xsl, $debug = "") { $hidden = ''; $xslBaseUri = $this->xslBaseUri; if ($xml == '') { die("falta o XML"); } if ($xsl == '') { die("falta XSL para transformar\n"); } if ($debug == "XML") { die($xml); } if ($debug == "XSL") { die($xsl . '<!--' . $xslBaseUri . $xsl . '-->'); } if (!file_exists($xsl)) { die($xsl . " not found."); } $transform = new XSLTransformer(); if (strpos(' ' . $xml, '/') == 1 || strpos(' ' . $xml, 'http://') == 1 || strpos(' ' . $xml, 'ftp://') == 1) { } else { $xml = $this->insertProcessingInstruction(trim($xml)); } if ($xslBaseUri) { $transform->setXslBaseUri("file://" . $xslBaseUri); } if ($transform->setXml($xml) == false) { die($transform->getErrorMessage()); } if ($transform->setXsl($xsl) == false) { die($transform->getErrorMessage()); } if ($transform->transform() == false) { $r = $transform->getErrorMessage(); } else { //transform sempre retorna UTF-8 $r = $transform->getOutput(); //$r = utf8_decode($r); /* if (!$this->isUTF8($r)){ //necessario fazer utf8_decode $r = html_entity_decode($r); $r = utf8_decode($r); $r = preg_replace("/UTF-8/i",$this->find($r,' encoding="','"'),$r); } */ } //die("XML.php xml é iso?", strpos(strtolower($xml),'iso-8859-1')); //debug("XML.php r é iso?", strpos(strtolower($r),'iso-8859-1')); return $r . $hidden; }
function transform($xml, $xsl, $debug = false) { $xslt = new XSLTransformer(); $xslt->setXml($xml); $xslt->setXsl($xsl); $xslt->transform(); $error = $xslt->getError(); if ($error) { $xslt->destroy(); die($error); } $tranformation = utf8_decode($xslt->getOutput()); if ($debug) { die($tranformation); } $xslt->destroy(); return $tranformation; }
/** * Process the given XML with the configured XSL * @see Filter::process() * @param $xml DOMDocument|string * @return DOMDocument|string */ function &process(&$xml) { // Determine the input type if (is_string($xml)) { $xmlType = XSL_TRANSFORMER_DOCTYPE_STRING; } elseif (is_a($xml, 'DOMDocument')) { $xmlType = XSL_TRANSFORMER_DOCTYPE_DOM; } else { assert(false); } // Determine the result type based on // the input type if it has not been // set explicitly. if (is_null($this->getResultType())) { $this->setResultType($xmlType); } // Transform the input $xslTransformer = new XSLTransformer(); $result =& $xslTransformer->transform($xml, $xmlType, $this->getXsl(), $this->getXslType(), $this->getResultType()); return $result; }
$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $xml .= '<root>'; $xml .= '<vars> <lang>' . $lang . '</lang> <applserver>' . $applServer . '</applserver> </vars>'; $xml .= str_replace('<?xml version="1.0" encoding="ISO-8859-1" ?>', '', $xmlFile); $xml .= '</root>'; if ($_REQUEST['debug'] == 'xml') { die($xml); } $transformer = new XSLTransformer(); $transformer->setXslBaseUri($defFile["PATH_XSL"]); $transformer->setXml($xml); $transformer->setXslFile($defFile["PATH_XSL"] . "datasus.xsl"); $transformer->transform(); $output = $transformer->getOutput(); $output = str_replace('&', '&', $output); $output = str_replace('<', '<', $output); $output = str_replace('>', '>', $output); $output = str_replace('"', '"', $output); $output = str_replace('<p>', ' ', $output); $output = str_replace('</p>', ' ', $output); echo $output; ?> </div> </TD> </TR> </TABLE> </div>
// XML Final que contem os dados que precisamos do XML1 e XML2 $xmlFinal = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $xmlFinal .= substr($xml2, strpos($xml2, "<root>"), strpos($xml2, "<ref_TITLE>") - strpos($xml2, "<root>")) . '<vars><refid>' . $_REQUEST['refid'] . '</refid><htdocs>' . $pathHtdocs . '</htdocs><service_log>' . $flagLog . '</service_log></vars>'; $xmlFinal .= " <ref_TITLE><![CDATA[" . $fullTitle . "]]></ref_TITLE>"; $xmlFinal .= substr($xml2, strpos($xml2, "<TITLE>")); if ($_REQUEST['debug2'] == 'on') { die($xmlFinal); } // Transformação Final, página de links de referencia $transformerFinal = new XSLTransformer(); $xslFinal = $pathHtdocs . "xsl/sci_reflinks.xsl"; //die("socket = true"); $transformerFinal->setXslBaseUri($pathHtdocs . "xsl"); $transformerFinal->setXml($xmlFinal); $transformerFinal->setXslFile($xslFinal); $transformerFinal->transform(); $output = $transformerFinal->getOutput(); if ($transformer->transformedBy == "PHP") { //PHP $output = utf8_decode($output); } if ($transformerFinal->getError()) { echo $transformerFinal->getError(); } $output = str_replace('&', '&', $output); $output = str_replace('<', '<', $output); $output = str_replace('>', '>', $output); $output = str_replace('"', '"', $output); $output = str_replace('<p>', ' ', $output); $output = str_replace('</p>', ' ', $output); echo html_entity_decode($output);
$url = "http://" . $_SERVER['HTTP_HOST'] . "/cgi-bin/wxis.exe/?IsisScript=ScieloXML/sci_issues.xis&def=scielo.def.php&sln={$lang}&script=sci_issues&pid={$pid}&lng={$lang}&nrm=iso"; $xml = file_get_contents($url); $cortado = strstr($xml, '<CURRENT PID="'); if ($cortado != "") { $posInicio = strpos($cortado, "\""); $posFim = strpos($cortado, "\"", $posInicio + 1); $pid = substr($cortado, $posInicio + 1, $posFim - $posInicio - 1); } } /* CHANGE: alterado em 20080314 para utilização do script sci_issuerss.xis (adiconado abstract ao XML) no lugar de sci_issuetoc.xis */ $url = "http://" . $_SERVER['HTTP_HOST'] . "/cgi-bin/wxis.exe/?IsisScript=ScieloXML/sci_issuerss.xis&def=scielo.def.php&sln=en&script=sci_issuetoc&pid={$pid}&lng={$lang}&nrm=iso"; $xml = file_get_contents($url); $xsl = dirname(__FILE__) . "/xsl/createRSS.xsl"; if (isset($debug)) { echo '<h1>XML</h1>'; echo '<textarea cols="120" rows="18">' . "\n"; echo $xml; echo '</textarea>'; echo '<h1>XSL</h1>'; echo '<textarea cols="120" rows="18">' . "\n"; echo $xsl; echo '</textarea>'; die; } $t = new XSLTransformer(); $t->setXml($xml); $t->setXslFile($xsl); $t->transform(); $result = $t->getOutput(); echo $result; ob_flush();
function processTransformation($xml, $xsl) { global $def; $result = ""; $xslParams = array('xml-path' => $def['DATABASE_PATH'] . "xml/"); $transform = new XSLTransformer(); if ($def["LETTER_UNIT"] != "") { $transform->setXslBaseUri("file://" . $def["LETTER_UNIT"] . "/" . $def["SITE_PATH"]); } else { $transform->setXslBaseUri("file://" . $def["SITE_PATH"]); } if ($transform->setXml($xml) == false) { die($transform->getErrorMessage()); } if ($transform->setXsl($xsl) == false) { die($transform->getErrorMessage()); } $transform->setXslParameters($xslParams); if ($transform->transform() == false) { print $transform->getErrorMessage(); } else { $result = utf8_decode($transform->getOutput()); } return $result; }
function generatePayload($ws_client_url, $service, $service_name, $parameters, $xsl) { global $debug, $defFile; //die($service_name." - ".$service); switch ($service_name) { case "Identify": $response = listRecords($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false); break; case "ListMetadataFormats": $response = getAbstractArticle($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false); break; case "ListIdentifiers": $response = listRecords($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false); break; case "ListSets": $response = getTitles($lang = "en", $debug = false); break; case "ListRecords": $response = ListRecords($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false); break; case "GetRecord": $response = getAbstractArticle($pid = $parameters["pid"], $lang = "en", $ws = $parameters["ws_oai"], $debug = false); break; } // $result = ""; if (!$debug) { $transform = new XSLTransformer(); if (getenv("ENV_SOCKET") != "true") { //socket $xsl = file_get_contents($defFile["PATH_OAI"] . $xsl); } else { $xsl = str_replace('.XSL', '', strtoupper($xsl)); } $transform->setXslBaseUri($defFile["PATH_OAI"]); $transform->setXsl($xsl); $transform->setXml($response); $transform->transform(); if ($transform->getError()) { // Transformation error echo "XSL Transformation error\n"; echo $transform->getError(); $transform->destroy(); exit; } $result = $transform->getOutput(); $transform->destroy(); } return $result; }