title: How to filter a select nodeset with a PHP function?
body: <p>I wonder if and how it is possible to register a PHP userspace function with the XSLT processor that is able not only to take an array of nodes but also to return it?</p>
  
  <p>Right now PHP complains about an array to string conversion using the common setup:</p>
  
  <pre><code>function all_but_first(array $nodes) {        
      array_shift($nodes);
      shuffle($nodes);
      return $nodes;
  };
  
  $proc = new XSLTProcessor();
  $proc-&gt;registerPHPFunctions();
  $proc-&gt;importStylesheet($xslDoc);
  $buffer = $proc-&gt;transformToXML($xmlDoc);
  </code></pre>
  
  <p>The XMLDocument (<code>$xmlDoc</code>) to transform can for example be:</p>
  
  <pre><code>&lt;p&gt;
     &lt;name&gt;Name-1&lt;/name&gt;
     &lt;name&gt;Name-2&lt;/name&gt;
     &lt;name&gt;Name-3&lt;/name&gt;
     &lt;name&gt;Name-4&lt;/name&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>Within the stylesheet it's called like this:</p>
  
  <pre><code>&lt;xsl:template name="listing"&gt;
      &lt;xsl:apply-templates select="php:function('all_but_first', /p/name)"&gt;
      &lt;/xsl:apply-templates&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>The notice is the following:</p>
  
  <blockquote>
    <p>Notice: Array to string conversion</p>
  </blockquote>
  
  <p>I don't understand why if the function gets an array as input is not able to return an array as well?</p>
  
  <p>I was also trying other "function" names as I've seen there is <code>php:functionString</code> but all  tried so far (<code>php:functionArray</code>, <code>php:functionSet</code> and <code>php:functionList</code>) did not work.</p>
  
  <p>In the PHP manual it's written I can return another <code>DOMDocument</code> containing elements, however then those elements aren't from the original document any longer. That does not make much sense to me.</p>