Ejemplo n.º 1
0
 protected function getLexicon()
 {
     $sXmlFileRealPath = Config::get('path.real.root') . Config::get('path.relative.root_to_app') . Config::get('path.relative.app_to_data') . Config::get('jsreal.lexicon.simple_nlg.xml.' . $this->sLanguage);
     $sXslFileRealPath = Config::get('path.real.root') . Config::get('path.relative.root_to_app') . Config::get('path.relative.app_to_xsl') . Config::get('jsreal.lexicon.simple_nlg.xsl');
     $sJsonLexicon = Xslt::applyXsltTemplateToXml($sXmlFileRealPath, $sXslFileRealPath);
     return Conversion::getArrayFromJson($sJsonLexicon);
 }
Ejemplo n.º 2
0
 /**
  * Loads the template [View] object.
  */
 public function before()
 {
     if ($this->auto_render === TRUE) {
         // Load the template
         $this->template = Xslt::factory($this->template);
     }
     return parent::before();
 }
Ejemplo n.º 3
0
 public function action_index()
 {
     $xsl = Xslt::factory("welcome");
     $xsl->media = array("script" => array("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"));
     $xsl->snippets = array("header" => Xslt::factory("snippets/header")->render(), "footer" => Xslt::factory("snippets/footer")->render());
     $xsl->title = "Teste";
     $xsl->items = array("item" => array(array("name" => "test 1", "value" => "value 1"), array("name" => "test 2", "value" => "value 2"), array("name" => "test 3", "value" => "value 3")));
     $this->request->response = $xsl->render();
 }
Ejemplo n.º 4
0
 /**
  * @param string|callable $xslFile absolute o relative path to XSL file used include path
  * @param array $xsltParameters
  * @param null|\DOMNode|Set  $element
  *
  * @return Element|Tag|Field
  */
 public function xslt($xslFile, $xsltParameters = array(), &$element = null)
 {
     if (is_null($element)) {
         $element = $this->documentElement;
     }
     return Xslt::doc()->transform($xslFile, $xsltParameters, $element);
 }
Ejemplo n.º 5
0
 protected function getTestConjugatedVerb()
 {
     $sXmlFileRealPath = Config::get('path.real.root') . Config::get('path.relative.root_to_app') . Config::get('path.relative.app_to_data') . Config::get('jsreal.test.conjugation.xml.' . $this->sLanguage);
     $sXslFileRealPath = Config::get('path.real.root') . Config::get('path.relative.root_to_app') . Config::get('path.relative.app_to_xsl') . Config::get('jsreal.test.conjugation.xsl.' . $this->sLanguage);
     $sJsonConjugatedVerb = Xslt::applyXsltTemplateToXml($sXmlFileRealPath, $sXslFileRealPath);
     $aOriginalList = Conversion::getArrayFromJson($sJsonConjugatedVerb);
     $aProperConjugationTest = array();
     foreach ($aOriginalList as $sUnit => $aInfo) {
         if (!empty($aInfo)) {
             $aProperConjugationTest[$sUnit] = $aInfo;
         }
     }
     return $aProperConjugationTest;
 }
Ejemplo n.º 6
0
 /**
  * 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);
 }
Ejemplo n.º 7
0
<?php

include_once "class_xslt.php";
$xslt = new Xslt();
$xslt->setXml("applications.xml");
$xslt->setXsl("tr1.xsl");
if ($xslt->transform()) {
    $ret = $xslt->getOutput();
    echo $ret;
} else {
    print "Error:" . $xslt->getError();
}