当前位置: 首页>>代码示例>>PHP>>正文


PHP XSLTProcessor::transformToDoc方法代码示例

本文整理汇总了PHP中XSLTProcessor::transformToDoc方法的典型用法代码示例。如果您正苦于以下问题:PHP XSLTProcessor::transformToDoc方法的具体用法?PHP XSLTProcessor::transformToDoc怎么用?PHP XSLTProcessor::transformToDoc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XSLTProcessor的用法示例。


在下文中一共展示了XSLTProcessor::transformToDoc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: transformToDoc

 /**
  * Transform a node with a stylesheet.
  *
  * @param      DOMNode The node to transform.
  *
  * @return     DOMDocument The resulting DOMDocument.
  *
  * @author     Noah Fontes <noah.fontes@bitextender.com>
  * @author     David Zülke <david.zuelke@bitextender.com>
  * @since      1.0.0
  */
 public function transformToDoc($doc)
 {
     $luie = libxml_use_internal_errors(true);
     libxml_clear_errors();
     $result = parent::transformToDoc($doc);
     // check if result is false, too, as that means the transformation failed for reasons like infinite template recursion
     if ($result === false || libxml_get_last_error() !== false || count(libxml_get_errors())) {
         $errors = array();
         foreach (libxml_get_errors() as $error) {
             $errors[] = sprintf('[%s #%d] Line %d: %s', $error->level == LIBXML_ERR_WARNING ? 'Warning' : ($error->level == LIBXML_ERR_ERROR ? 'Error' : 'Fatal'), $error->code, $error->line, $error->message);
         }
         libxml_clear_errors();
         libxml_use_internal_errors($luie);
         throw new Exception(sprintf('Error%s occurred while transforming the document using an XSL stylesheet: ' . "\n\n%s", count($errors) > 1 ? 's' : '', implode("\n", $errors)));
     }
     libxml_use_internal_errors($luie);
     // turn this into an instance of the class that was passed in, rather than a regular DOMDocument
     $class = $doc instanceof DOMDocument ? $doc : ($doc->ownerDocument ?: 'DOMDocument');
     $document = new $class();
     $document->loadXML($result->saveXML());
     // save the URI just in case
     $document->documentURI = $result->documentURI;
     unset($result);
     return $document;
 }
开发者ID:horros,项目名称:agavi,代码行数:36,代码来源:AgaviXsltProcessor.class.php

示例2: transform

 /**
  * @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;
 }
开发者ID:volux,项目名称:dom,代码行数:36,代码来源:Xslt.php

示例3: params

 /**
  * Executes Params XSLT (transformation to be used to convert parameters into query) for given query.
  */
 function params()
 {
     $document =& JFactory::getDocument();
     $viewName = JRequest::getVar('view', 'params');
     $viewType = $document->getType();
     $view =& $this->getView($viewName, $viewType);
     $data = JRequest::getVar('data', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $query_id = JRequest::getInt('id_query', NULL);
     $result = $data;
     if ($query_id != NULL && !empty($data)) {
         $model_queries =& $this->getModel('queries');
         $query = $model_queries->getQuery($query_id);
         if ($query != NULL && !empty($query->paramsxsl)) {
             $xml = new DOMDocument();
             if ($xml->loadXML($data)) {
                 // start xslt
                 $xslt = new XSLTProcessor();
                 $xsl = new DOMDocument();
                 $xsl->loadXML($query->paramsxsl);
                 $xslt->importStylesheet($xsl);
                 $paramset = $xslt->transformToDoc($xml);
                 $result = $xslt->transformToXML($xml);
                 if ($result === false) {
                     // TODO: any joomla function for this?
                     header('HTTP/1.1 500 Internal Server Error');
                 }
             }
         }
     }
     $view->assign('value', $result);
     $view->display();
 }
开发者ID:KIZI,项目名称:sewebar-cms,代码行数:35,代码来源:selector.php

示例4: doRemoveNamespacedNodes

    protected function doRemoveNamespacedNodes(&$pq)
    {
        $xsl = <<<____EOF
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl">
          <xsl:template match="*[local-name()=name()]">
              <xsl:element name="{local-name()}">
                  <xsl:apply-templates select="@* | node()"/>
              </xsl:element>
          </xsl:template>
          <xsl:template match="@* | text()">
              <xsl:copy/>
          </xsl:template>
      </xsl:stylesheet>
____EOF;
        $xsl = \DOMDocument::loadXml($xsl);
        $proc = new \XSLTProcessor();
        $proc->importStyleSheet($xsl);
        $pq->document = $proc->transformToDoc($pq->document);
        for ($i = $pq->document->documentElement->attributes->length; $i >= 0; --$i) {
            $attr = $pq->document->documentElement->attributes->item($i);
            if (substr($attr->name, 0, 6) === 'xmlns:') {
                $pq->document->documentElement->removeAttributeNode($attr);
            }
        }
        $pq = PhpQuery::newDocumentHTML($pq->document->saveHTML());
        return $this;
    }
开发者ID:wittiws,项目名称:php-file-converters,代码行数:27,代码来源:FcHtmlBase.php

示例5: process

 /**
  * Обрабатывает данные.
  * @param string $data XML-строка
  */
 public function process($data)
 {
     $errorHandler = new \WebConstructionSet\Xml\LibxmlErrorHandler();
     $xml = new \DOMDocument();
     if (!$xml->loadXML($data)) {
         throw new \ErrorException('Document parse failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
     }
     $xsl = new \DOMDocument();
     if ($this->xslString) {
         if (!$xsl->loadXML($this->xslString)) {
             throw new \ErrorException('XSL stylesheet load/parse failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
         }
     } else {
         $xslPath = $this->getXslStylesheetPath($xml);
         if (!$xslPath) {
             throw new \ErrorException('XSL stylesheet path is not found.', null, null, __FILE__, __LINE__);
         }
         if (!$xsl->load($xslPath)) {
             throw new \ErrorException('XSL stylesheet load/parse failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
         }
     }
     $xslt = new \XSLTProcessor();
     if (!$xslt->importStylesheet($xsl)) {
         throw new \ErrorException('Import XSL stylesheet failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
     }
     $this->resultDoc = $xslt->transformToDoc($xml);
     if (!$this->resultDoc) {
         throw new \ErrorException('XSLT transform failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
     }
     // no return
 }
开发者ID:roman-rybalko,项目名称:wcs,代码行数:35,代码来源:xslt.php

示例6: showArticleById

 /**
  * @Route("/{volume}/{id}", requirements={"id" = "\d+", "volume" = "\d+"})
  * @param $volume
  * @param $id
  * @param bool|false $showByName
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function showArticleById($volume, $id, $showByName = false)
 {
     $id_article = 'v' . $volume . '-' . $id;
     $xml_source = new \DOMDocument();
     $xml_source->load('../src/AppBundle/Resources/xml/volume' . $volume . '.xml');
     $xslt_root = new \DOMDocument();
     $xslt_root->load('../src/AppBundle/Resources/xslt/article.xsl');
     $transform = new \XSLTProcessor();
     $transform->importStylesheet($xslt_root);
     $xpath = new \DOMXpath($xml_source);
     $page_debut_xpath = $xpath->query("//div[@type='article' and @xml:id='" . $id_article . "']/preceding::pb[position()\n        =1]");
     $num_vue = $page_debut_xpath->item(0)->attributes->item(1)->nodeValue;
     $page_debut = substr($num_vue, strpos($num_vue, "p") + 1);
     $article_result = $xpath->query("//div[@type='article' and @xml:id='" . $id_article . "']");
     $vedette_adresse_text = $xpath->query("//div[@type='article' and @xml:id='" . $id_article . "']/child::div[position()=1]/child::p[position()=1]/child::seg[@type='vedette_adresse']/descendant::text()");
     $vedette_adresse = '';
     if ($vedette_adresse_text->length > 0) {
         for ($i = 0; $i < $vedette_adresse_text->length; $i++) {
             $vedette_adresse .= $vedette_adresse_text->item($i)->nodeValue;
         }
     }
     $pos_article = null;
     if ($article_result->length > 0) {
         $content = $article_result->item(0);
         $xml_transform = new \DOMDocument();
         $xml_transform->appendChild($xml_transform->importNode($content, true));
         $article = $transform->transformToDoc($xml_transform)->saveHTML();
         $pos_article = intval($id);
         $next_article = $pos_article + 1;
         $previous_article = $pos_article - 1;
         if ($pos_article == 1) {
             $previous_article = null;
         } else {
             if ($showByName) {
                 $previous_article_id = 'v' . $volume . '-' . $previous_article;
                 $previous_article_vedette_adresse_text = $xpath->query("//div[@type='article' and @xml:id='" . $previous_article_id . "']/child::div[position()=1]/child::p[position()=1]/child::seg[@type='vedette_adresse']");
                 if ($previous_article_vedette_adresse_text->length > 0) {
                     $previous_article = $previous_article_vedette_adresse_text->item(0)->textContent;
                     $previous_article = str_replace(" ", "_", $previous_article);
                 }
             }
         }
         $next_article_id = 'v' . $volume . '-' . $next_article;
         $xpath_find_next_article = $xpath->query("//div[@type='article' and @xml:id='" . $next_article_id . "']");
         if ($xpath_find_next_article->length == 0) {
             $next_article = null;
         } else {
             if ($showByName) {
                 $next_article_vedette_adresse_text = $xpath->query("//div[@type='article' and @xml:id='" . $next_article_id . "']/child::div[position()=1]/child::p[position()=1]/child::seg[@type='vedette_adresse']");
                 if ($next_article_vedette_adresse_text->length > 0) {
                     $next_article = $next_article_vedette_adresse_text->item(0)->textContent;
                     $next_article = str_replace(" ", "_", $next_article);
                 }
             }
         }
         return $this->render('AppBundle::article.html.twig', array('article' => $article, 'id_article' => $id, 'name_article' => $vedette_adresse, 'next_article' => $next_article, 'previous_article' => $previous_article, 'volume' => $volume, 'first_page' => $page_debut));
     }
     return $this->render('AppBundle::404.html.twig', array('error' => 404));
 }
开发者ID:NHS1991,项目名称:enccre,代码行数:66,代码来源:ArticleController.php

示例7: transformToDoc

 /**
  * @param \DOMNode $doc
  * @return DOMDocument
  */
 public function transformToDoc($doc)
 {
     $styleSheet = $this->styleSheetToDomDocument();
     $transpiler = $this->createTranspiler($styleSheet);
     parent::importStylesheet($this->getTranspiledStyleSheet($transpiler, $styleSheet));
     return $transpiler->transform(function () use($doc) {
         return parent::transformToDoc($doc);
     });
 }
开发者ID:Samshal,项目名称:xsl,代码行数:13,代码来源:XsltProcessor.php

示例8: render

 /**
  * Process given document into template and render it with given values.
  *
  * @param DocumentInterface $document
  * @param array $values
  * @return Result
  */
 public function render(DocumentInterface $document, array $values)
 {
     // fill with values
     $xslt = new \XSLTProcessor();
     $template = $this->getTemplate($document);
     $xslt->importStylesheet($template);
     $content = $xslt->transformToDoc($this->createValuesDocument($values));
     Processor::undoEscapeXsl($content);
     return new Result($content, $document);
 }
开发者ID:noikiy,项目名称:PHPStamp,代码行数:17,代码来源:Templator.php

示例9: xslt

 public function xslt($style)
 {
     if (!$style instanceof QueryPath) {
         $style = qp($style);
     }
     $sourceDoc = $this->src->top()->get(0)->ownerDocument;
     $styleDoc = $style->get(0)->ownerDocument;
     $processor = new XSLTProcessor();
     $processor->importStylesheet($styleDoc);
     return qp($processor->transformToDoc($sourceDoc));
 }
开发者ID:GitError404,项目名称:favrskov.dk,代码行数:11,代码来源:QPXSL.php

示例10: testTransformToDoc

 public function testTransformToDoc()
 {
     $xslDoc = new DOMDocument();
     $xslDoc->load('Stubs/collection.xsl');
     $xmlDoc = new DOMDocument();
     $xmlDoc->load('Stubs/collection.xml');
     $native = new \XSLTProcessor();
     $native->importStylesheet($xslDoc);
     $nativeResult = $native->transformToDoc($xmlDoc);
     $transpiler = new XsltProcessor();
     $transpiler->importStylesheet($xslDoc);
     $transpilerResult = $transpiler->transformToDoc($xmlDoc);
     $this->assertEquals($nativeResult->saveXML(), $transpilerResult->saveXML());
 }
开发者ID:genkgo,项目名称:xsl,代码行数:14,代码来源:ProcessXslt1DocumentsTest.php

示例11: cbd_run

 public static function cbd_run()
 {
     $proc = new XSLTProcessor();
     $proc->importStyleSheet(DOMDocument::load('xsl/cbd.xsl'));
     global $registerPHPFunctions;
     if ($registerPHPFunctions) {
         $proc->registerPHPFunctions($registerPHPFunctions);
     }
     $cbd_xml = $proc->transformToDoc(DOMDocument::load('db://?all-data'));
     $xml = simplexml_import_dom($cbd_xml) or die('import failed');
     global $cbd_host, $cbd_db, $cbd_user, $cbd_pwd;
     $conn_pg = pg_connect("host='{$cbd_host}' dbname={$cbd_db} user={$cbd_user} password={$cbd_pwd}") or die("error on connection to {$cbd_db}");
     Importer::_run($xml, $conn_pg);
 }
开发者ID:radixvinni,项目名称:xml-data-resource,代码行数:14,代码来源:import.php

示例12: render

 /**
  * @param \DOMDocument $xml
  * @param bool|string $specificInstance
  * @param bool $dontEcho
  * @param bool $dontFillXML
  * @param bool $normalize
  * @return bool|string
  * @throws Exception
  */
 public static function render(&$xml, $specificInstance = false, $dontEcho = false, $dontFillXML = false, $normalize = true)
 {
     if ($specificInstance) {
         $instance = $specificInstance;
     } elseif (self::$instance) {
         $instance = self::$instance;
     } else {
         $instance = 'main';
     }
     Debugger::addLine("Render start (instance '{$instance}')");
     if (!($resource = Resourcer::getInstance('xslt')->compile($instance))) {
         throw new Exception("XSLT resource not found");
     }
     $xslDom = new \DomDocument();
     $xslDom->resolveExternals = true;
     $xslDom->substituteEntities = true;
     if (!$xslDom->loadXML($resource)) {
         throw new Exception("XSLT load problem for instance '{$instance}'");
     }
     $xslProcessor = new \XSLTProcessor();
     $xslProcessor->importStylesheet($xslDom);
     if (!$dontFillXML and !HttpError::$error and !Debugger::$shutdown) {
         View\XML::fillXML($xml, $instance);
     }
     // transform template
     if ($html = $xslProcessor->transformToDoc($xml)) {
         if ($normalize) {
             $html = self::normalize($html);
         } else {
             $html->formatOutput = true;
             $html = $html->saveXML();
         }
         if ($dontEcho) {
             return $html;
         }
         echo $html;
         self::$rendered = true;
         if (Debugger::isEnabled()) {
             echo '<!-- Page rendered in ' . Debugger::getTimer() . ' seconds -->';
         }
         if (function_exists('fastcgi_finish_request')) {
             fastcgi_finish_request();
         }
     } else {
         $errormsg = libxml_get_errors();
         //error_get_last();
         throw new Exception($errormsg ? $errormsg['message'] : "Can't render templates");
     }
     return true;
 }
开发者ID:difra-org,项目名称:difra,代码行数:59,代码来源:View.php

示例13: convert

 /**
  * 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);
 }
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:45,代码来源:xslt.php

示例14: parse

 public function parse(Session $session)
 {
     $chan = new DOMDocument();
     $chan->loadXML(mb_convert_encoding($session->bytes, 'HTML-ENTITIES', 'UTF-8'));
     $sheet = new DOMDocument();
     $sheet->load('data/atom2rss/atom2rss.xsl');
     /* use stylesheet from this page */
     $processor = new XSLTProcessor();
     $processor->registerPHPFunctions();
     $processor->importStylesheet($sheet);
     $session->dom = $processor->transformToDoc($chan);
     $session->xpath = new DOMXPath($session->dom);
     $session->dom->save('/tmp/atom.xml');
     // error_log("RESULT: " . $session->dom->saveXML());
 }
开发者ID:kba,项目名称:rssscrpr,代码行数:15,代码来源:AtomParser.php

示例15: transformToDocument

 /**
  * На вход подается содержимое трансформируемого XML и XSL шаблона трансформации
  *
  * @param string $xml
  * @param string $xslt
  * @return \SimpleXMLElement
  * @throws \Exception
  */
 public function transformToDocument($xml, $xslt)
 {
     try {
         $xmlObj = new \DOMDocument('1.0', 'UTF-8');
         $xmlObj->loadXML($xml);
         $xslObj = new \DOMDocument('1.0', 'UTF-8');
         $xslObj->loadXML($xslt);
         $proc = new \XSLTProcessor();
         $proc->importStyleSheet($xslObj);
         $xmlObject = $proc->transformToDoc($xmlObj);
     } catch (\Exception $ex) {
         throw new \Exception('Xslt_Transformer; XSLT Error: ' . $ex->getMessage());
     }
     return $xmlObject;
 }
开发者ID:izyumskiy,项目名称:restsoap,代码行数:23,代码来源:Transformer.php


注:本文中的XSLTProcessor::transformToDoc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。