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 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; }
$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> </div>
$xml .= '</root>'; if (getenv("ENV_SOCKET") == "true"){ //socket $xslFile = strtoupper($xslName); //die("socket = false"); } else { $xslFile = file_get_contents($defFile->getKeyValue("PATH_XSL").$xslName.".xsl"); } $xsl = $xslFile; if(isset($_REQUEST['debug'])) { echo '<textarea cols="80" rows="10">'; echo $xml; echo '</textarea>'; echo '<textarea cols="80" rows="10">'; echo file_get_contents($xslFile); echo '</textarea>'; } $transformer->setXslBaseUri($defFile->getKeyValue("PATH_XSL")); //$transformer->setXml(utf8_encode($xml)); $transformer->setXml($xml); $transformer->setXsl($xsl); $transformer->transform(); $result = $transformer->getOutput(); if($transformer->getError()){ echo $transformer->getError(); } echo $result; ?>
$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; }