function getXMLSing($xmlHon,$priv_key){ //Carga Certificado $xml = new DomDocument(); $xml->loadXML($xmlHon); //Carga prosedimiento de proceso de cadena original $xsl = new DomDocument; $xsl->load("ostring.xsl"); $proc = new xsltprocessor(); $proc->importStyleSheet($xsl); $original =$proc->transformToXML($xml); //firma la cadena original //$fp = $cert[0]['certificates']['key']; //$priv_key = $f['key']; //die($f['key']); //fclose($fp); $pkeyid = openssl_get_privatekey($priv_key); openssl_sign($original, $signature, $pkeyid,OPENSSL_ALGO_MD5); openssl_free_key($pkeyid); //coloca el sello en xml $esqueletonew=$xmlHon; $esqueletonew=str_replace("#1#",base64_encode($signature),$esqueletonew); $xmlReturn[1]=$esqueletonew; $xmlReturn[2]=$original; $xmlReturn[3]=base64_encode($signature); return $xmlReturn; }
/** * render the product finder using an XSL stylesheet * * @access public * @param string xsl stylesheet * @return string result of the transformation */ public function render($xsl = null) { if (is_string($xsl)) { $xsl = DomDocument::loadXML($xsl); } $proc = new xsltprocessor(); $proc->importStyleSheet($xsl); return $proc->transformToXML($this->dom); }
function render($controller_name, $layout_template = false) { parent::parse($controller_name, $layout_template); $xsl = new DomDocument(); $xsl->load($this->template); $proc = new xsltprocessor(); $proc->importStyleSheet($xsl); echo $proc->transformToXML($this->props_to_xml()); }
private function _xsltProcess($sVml, $sXslFilePath) { $oProcessor = new xsltprocessor(); $oXml = new DomDocument(); $oXml->loadXML($sVml); $oXsl = new DomDocument(); $oXsl->load($sXslFilePath); $oProcessor->importStyleSheet($oXsl); return $oProcessor->transformToXML($oXml); }
protected function renderXSLT($response, $template) { if ($template == '') { throw new Exception(JText::_('COM_AAWS_TEMPLATE_DOES_NOT_EXIST')); } $type = strtolower(substr(get_class($this), strlen('AawsController'))); $path = JPATH_COMPONENT . DS . 'xslt' . DS . $type . DS . $template . '.xslt'; if (!JFile::exists($path)) { throw new Exception(JText::_('COM_AAWS_TEMPLATE_DOES_NOT_EXIST')); } $xml = new DOMDocument(); $xml->loadXML($response); $xsl = new DOMDocument(); $xsl->load($path); $proc = new xsltprocessor(); $proc->importStyleSheet($xsl); $proc->setParameter('', 'language', 'es-ES'); if (method_exists($this, '_setVariablesTo')) { $this->_setVariablesTo($proc, $template); } echo $proc->transformToXML($xml); }
</item> <item date="3247283732"> <caption>Testing...</caption> <content> <![CDATA[ dies ist ein zweiter test... ]]> </content> </item> </news>'; $xsl2str = '<xsl:stylesheet version = "1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template match="content"> <b><xsl:value-of select="." /></b> </xsl:template> '; $xml = new DomDocument(); $xml->loadxml($xmlstr); $xsl = new DomDocument(); $xsl->load("test1.xsl"); $xsl2 = new DomDocument(); $xsl2->load("test1-2.xsl"); $proc = new xsltprocessor(); $proc->importStyleSheet($xsl2); $proc->importStyleSheet($xsl); echo $proc->transformToXML($xml); echo '<br><br>'; printf("%s<br>Count: %d", md5("29o3_DEFAULT_THEME"), strlen(md5("test")));
function _generateRDF() { $model = new MemModel(); $model->setBaseURI($this->doclink); $proc = new xsltprocessor(); include_once RDFAPI_INCLUDE_DIR . PACKAGE_SYNTAX_RDF; $pars = new RdfParser(); foreach ($this->stylelink as $key => $value) { $xsl = new DomDocument(); $xsl->load($value); $proc->importStyleSheet($xsl); $model->addModel($pars->generateModel($proc->transformToXML($this->domdoc), $this->doclink)); } return $model; }
public function applyTransform() { preg_match('#(</OTA_[^>]*>)#', $this->_response, $matches); $xmlString = explode($matches[1], $this->_response); $xmlString = $xmlString[0]; $xmlString .= $this->_getAdministrativeFeeXMLVersion(); $xmlString .= $matches[1]; $xml = new DOMDocument(); $xml->loadXML($xmlString); $path = JPATH_SITE . DS . 'plugins' . DS . 'amadeus' . DS . 'administrativefee' . DS . 'transform.xslt'; if (!JFile::exists($path)) { throw new Exception(JText::_('PLG_AAWS_TEMPLATE_DOES_NOT_EXIST')); } $xsl = new DOMDocument(); $xsl->load($path); $proc = new xsltprocessor(); $proc->importStyleSheet($xsl); $this->_response = substr($proc->transformToXML($xml), 22); return true; }
/** * Render the page - this is ran automaticly * * @return Boolean */ public function render() { /** * Must be a logged in user with admin role to access the admin pages */ $user = User::instance(); if ((!$user->logged_in() || !array_intersect($user->get_role(), User::get_roles())) && $this->request->controller() != 'login') { $this->redirect('admin/login'); } if ($this->transform === TRUE || $this->transform === FALSE || $this->transform == 'auto') { $this->dom->insertBefore($this->dom->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="' . $this->xslt_path . $this->xslt_stylesheet . '.xsl"'), $this->xml); // If the stylesheet name includes an additional path, we need to extract it $extra_xslt_path = ''; $extra_path_parts = explode('/', $this->xslt_stylesheet); foreach ($extra_path_parts as $nr => $extra_path_part) { if ($nr < count($extra_path_parts) - 1) { $extra_xslt_path .= $extra_path_part . '/'; } } // See if we have a user agent that triggers the server side HTML generation $user_agent_trigger = FALSE; foreach (Kohana::$config->load('xslt.user_agents') as $user_agent) { if (strpos($_SERVER['HTTP_USER_AGENT'], $user_agent)) { $user_agent_trigger = TRUE; } } if ($this->transform === TRUE || $this->transform == 'auto' && $user_agent_trigger == TRUE) { $xslt = new DOMDocument(); if (file_exists(getenv('DOCUMENT_ROOT') . $this->xslt_path . $this->xslt_stylesheet . '.xsl')) { // If the stylesheet exists in the specified path, load it directly $xslt->load(getenv('DOCUMENT_ROOT') . $this->xslt_path . $this->xslt_stylesheet . '.xsl'); } else { // Else make a search for it // We need to load all theme modules foreach (scandir(MODPATH) as $modulePath) { if (substr($modulePath, 0, 5) == 'theme') { Kohana::modules(array($modulePath => MODPATH . $modulePath) + Kohana::modules()); } } $xslt->load(Kohana::find_file(rtrim(preg_replace('/^' . str_replace('/', '\\/', Kohana::$base_url) . '/', '', $this->xslt_path), '/'), $this->xslt_stylesheet, 'xsl')); } // We need to update paths to included XSL elements $XPath = new DOMXPath($xslt); $include_nodes = $XPath->query('//xsl:include'); foreach ($include_nodes as $include_node) { foreach ($include_node->attributes as $attribute_node) { $new_filename = Kohana::find_file(rtrim(preg_replace('/^' . str_replace('/', '\\/', Kohana::$base_url) . '/', '', $this->xslt_path . $extra_xslt_path), '/'), substr($attribute_node->nodeValue, 0, strlen($attribute_node->nodeValue) - 4), 'xsl'); $include_node->removeAttribute('href'); $include_node->setAttribute('href', $new_filename); } } // Done updating paths $proc = new xsltprocessor(); $proc->importStyleSheet($xslt); echo $proc->transformToXML($this->dom); } else { $this->response->headers('Content-Type', 'application/xml; encoding=' . Kohana::$charset . ';'); echo $this->dom->saveXML(); } } elseif ($this->transform == 'XML') { $this->response->headers('Content-Type', 'application/xml; encoding=' . Kohana::$charset . ';'); echo $this->dom->saveXML(); } elseif ($this->transform == 'JSON') { $this->response->headers('Content-type: application/json; encoding=' . Kohana::$charset . ';'); echo json_encode(new SimpleXMLElement($this->dom->saveXML(), LIBXML_NOCDATA)); } return TRUE; }
/** * Renders the xsl object to a string. Global and local data are merged * and extracted to create local variables within the xsl file. * * $output = $xsl->render(); * * [!!] Global variables with the same key name as local variables will be * overwritten by the local variable. * * @param string xsl filename * @return string * @throws Kohana_Exception */ public function render($file = NULL) { if ($file !== NULL) { $this->set_filename($file); } if (empty($this->_file)) { throw new Kohana_Exception('You must set the file to use within your xsl before rendering'); } if (Xslt::$_global_data) { // Import the global xsl variables to local namespace and maintain references $this->_data = array_merge(Xslt::$_global_data, $this->_data); } // Create the XML DOM $this->_dom = new DomDocument('1.0', 'UTF-8'); $this->_dom->preserveWhiteSpace = FALSE; $this->_dom->formatOutput = TRUE; // echo $this->array2xml( $this->_data ); $this->_dom->loadXML($this->array2xml($this->_data)); // Link the xml and xsl $this->_dom->insertBefore($this->_dom->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="' . $this->_file . '"')); // Load the xsl $xslt = new DOMDocument(); $doc = array("content" => Xslt::capture($this->_file), "pattern" => "/<!DOCTYPE (.*) PUBLIC \"(.*)\" \"(.*)\">/i", "match" => array(), "method" => "xml", "public" => "", "system" => ""); preg_match($doc["pattern"], $doc["content"], $match); if (!empty($match)) { $doc["content"] = preg_replace($doc["pattern"], "", $doc["content"]); $doc["match"] = $match; $doc["method"] = $doc["match"][1]; $doc["public"] = "doctype-public=\"" . $doc["match"][2] . "\""; $doc["system"] = "doctype-system=\"" . $doc["match"][3] . "\""; } $doc["content"] = $this->get_includes($doc["content"]); $xslt->loadXML("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\t\t\t<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n\t\t\t<xsl:output\n\t\t\t\tmethod=\"xml\"\n\t\t\t\tencoding=\"" . Kohana::$charset . "\"\n\t\t\t\tomit-xml-declaration=\"no\"\n\t\t\t\t" . $doc["public"] . "\n\t\t\t\t" . $doc["system"] . "\n\t\t\t\tindent=\"no\"\n\t\t\t\t/>\n\n\t\t\t<xsl:template match=\"/root\">" . $doc["content"] . "</xsl:template></xsl:stylesheet>"); // Process XSLT $proc = new xsltprocessor(); $proc->importStyleSheet($xslt); // Return HTML $return_html = $proc->transformToDoc($this->_dom)->saveXML(); $return_html = html_entity_decode($return_html); return str_replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n", "", $return_html); }
/** * Transforms the DB4 schema to a Propel one. */ function doConvertSchema() { // XML $xml = new DomDocument(); $xml->loadXML(file_get_contents($this->file_path)); // DB4 xsl $db4_transformation_file = dirname(__FILE__) . '/../vendor/db2/dbd2propel.xsl'; $xsl = new DomDocument(); $xsl->load($db4_transformation_file); // Attach the xsl rules $proc = new xsltprocessor(); $proc->importStyleSheet($xsl); $xmlstr = $proc->transformToXML($xml); // Automatised i18n $i18nlist = array(); preg_match_all('#\\<table name=\\"(.+)_i18n\\"#', $xmlstr, $i18nlist); if (is_array($i18nlist) && isset($i18nlist[1]) && is_array($i18nlist[1])) { foreach ($i18nlist[1] as $tableName) { $xmlstr = str_replace('<table name="' . $tableName . '"', '<table name="' . $tableName . '" isI18N="true" i18nTable="' . $tableName . '_i18n"', $xmlstr); } } // Others replacments $xmlstr = str_replace(array('name="culture"', 'package="lib.model"'), array('name="culture" isCulture="true"', sprintf('package="%s"', $this->package)), $xmlstr); // Delete external tables if (!empty($this->external_tables)) { $this->external_tables_array = explode(',', $this->external_tables); $this->log(' - Removing external tables'); foreach ($this->external_tables_array as $external_table) { $this->log(' > ' . $external_table); $reg_exp = '/(<table name="' . trim($external_table) . ')(((.)*(\\s)*)*?)(<\\/table>)/'; $xmlstr = preg_replace($reg_exp, '', $xmlstr); } } // Xml file save $this->xmlstr = $xmlstr; $this->output_path = sfConfig::get('sf_root_dir') . $this->output_dir . '/' . $this->output . '.xml'; }