Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To understand the problem it is important to understand how XSLTProcessor stores data internally and what happens after calling <code>XSLTProcessor::importStylesheet</code>. The code that implements this class is located in the <a href="https://github.com/php/php-src/blob/master/ext/xsl/xsltprocessor.c" rel="nofollow"><code>\ext\xsl\xsltprocessor.c</code></a> from php source code. </p> <p>The explanation will have to simplify things a bit - is written in pure php 'c'. What's in a php object - in terms of <code>с</code> just functions operate on the global context.</p> <p>Web need to understand how and what is happening with the imported data:</p> <ol> <li>XSLTProcessor::importStylesheet accept object of <code>DOMDocument</code> or <code>SimpleXMLElement</code>. </li> <li><p>Firts thing that happends with import (from 409 line of sources, <code>docp</code> is an <code>importStylesheet</code> parameter)</p> <pre><code>//php_libxml_import_node is (in the \ext\libxml\libxml.c) just get //the real `xmlNodePtr` XMLlib2 object pointer by php object pointer. nodep = php_libxml_import_node(docp TSRMLS_CC); if (nodep) { doc = nodep-&gt;doc; } if (doc == NULL) { php_error(E_WARNING, "Invalid Document"); RETURN_FALSE; } //Next lines is an original comments and call of `xmlCopyDoc` which makes copy // of your stylesheet. The main lines in my answer. /* libxslt uses _private, so we must copy the imported stylesheet document otherwise the node proxies will be a mess */ newdoc = xmlCopyDoc(doc, 1); .... //Here we create internal stylesheet object with libxslt function. </code></pre> <p>sheetp = xsltParseStylesheetDoc(newdoc);<br> ...</p> <pre><code>//And some lines later store them to internal variables for this //XSLTProcessor class instance. php_xsl_set_object(id, sheetp TSRMLS_CC); </code></pre></li> <li><p>After <code>importStylesheet</code> you can do anything you want with your $stylesheet object - it does not affect the work of <code>XSLTProcessor</code> becouse it uses copy of $stylesheet. But your cant to refresh or update your $stylesheet without call <code>importStylesheet</code> again. </p></li> </ol> <p>Whats about <code>XSLTProcessor::transformToDoc</code> (<code>php_xsl_apply_stylesheet</code> - from 477 line of same source) and other <code>transform</code> methods. Each of them allocate they output type (DOMDocument in case of <code>XSLTProcessor::transformToDoc</code>) and use internal <code>sheetp</code> object(created in <code>importStylesheet</code>) to transform data. </p> <p><strong>Edited after comments</strong></p> <ol> <li>Some words about conditions of 'when' and/or 'why' the reuse is not valid. Reuse <strong>is valid and recommended</strong> each time you need make <code>transformTo</code> more then once. Should reuse if stylesheep uses <a href="http://www.w3schools.com/xsl/el_key.asp" rel="nofollow">xsl:key</a> on big stylesheets becouse of additional XML node traversal.</li> <li>Caching just XSLTProcessor object dont make any sense - contructor of this object do not allocate anything. And <code>XSLproc_reuse2</code> make sense and should be used. You cache procedure of $stylesheet copying and traverse in <a href="http://www.w3schools.com/xsl/el_key.asp" rel="nofollow">xsl:key</a> usage. Not the pointer but all object and it`s internals.</li> </ol> <p>Let<code>s some more words about how the</code>transformToDoc` works:</p> <ol> <li>Allocate new <code>DOMDocument</code> object. </li> <li>If $stylesheet has <a href="http://www.w3schools.com/xsl/el_key.asp" rel="nofollow">xsl:key</a> it make copy of your $doc parameter.</li> <li>Makes tramsform with <code>xsltNewTransformContext</code> and <code>xsltApplyStylesheetUser</code> from <code>libxslt</code>. </li> <li>Return <code>DOMDocument</code></li> </ol> <p>Where is no any penalty code in <code>XSLTProcessor</code> or <code>libxslt</code> which goes <code>XSLTProcessor</code> reusage wrong. Before 0.7.2 of <a href="http://pecl.php.net/package/xslcache" rel="nofollow"><code>xslcache</code></a> i try to work with this project and tune it to work with out site. There is my experience. At that time we use XSLT as template engine with large XSLT templates (in round of ~3-5mb minificated code). In such cases the caching of <code>importStylesheet</code> has big perfomance boost. But there is no any opportunities to cache <code>transformToDoc</code> results - each time you call it <code>libxslt</code> makes dom manipulation with two prepared objects in memory and gives you new object as result.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload