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?
Right now PHP complains about an array to string conversion using the common setup:
function all_but_first(array $nodes) {
array_shift($nodes);
shuffle($nodes);
return $nodes;
};
$proc = new XSLTProcessor();
$proc->registerPHPFunctions();
$proc->importStylesheet($xslDoc);
$buffer = $proc->transformToXML($xmlDoc);
The XMLDocument ($xmlDoc) to transform can for example be:
<p>
<name>Name-1</name>
<name>Name-2</name>
<name>Name-3</name>
<name>Name-4</name>
</p>
Within the stylesheet it's called like this:
<xsl:template name="listing">
<xsl:apply-templates select="php:function('all_but_first', /p/name)">
</xsl:apply-templates>
</xsl:template>
The notice is the following:
Notice: Array to string conversion
I don't understand why if the function gets an array as input is not able to return an array as well?
I was also trying other "function" names as I've seen there is php:functionString but all tried so far (php:functionArray, php:functionSet and php:functionList) did not work.
In the PHP manual it's written I can return another DOMDocument containing elements, however then those elements aren't from the original document any longer. That does not make much sense to me.
DOMDocumentfrom this function. But then it gets bugly again, because I just got out the plain text and no nodes. (xsl:for-eachdidn't help either)all_but_firstwith example array, your sample xml, xsl? I am interested in this question and have executed a basic example from php.net. I would like to go in depth with this concept because might be I will have this type of requirement in future. Your sample (xml, xsl and value of array in function) data would be helpful to me to go further on this topic.