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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…