From a PHP function, you can pass a nodeset back to XSL using a DOMDocument. For example:
<?php
function getNodeSet() {
$xml =
"<test>" .
"<a-node>This is a node</a-node>" .
"<a-node>This is another node</a-node>" .
"</test>";
$doc = new DOMDocument;
$doc->loadXml($xml);
return $doc;
}
?>
The only problem I've found is that the root level node in your returned DOM document acts like the root level node of your original. SO, it's easy to introduce an infinite loop like so:
<xsl:template match="/">
<xsl:apply-templates select="php:function('getNodeSet')" />
</xsl:template>
To avoid this, I've been using a construct like:
<xsl:template match="/">
<xsl:for-each select="php:function('getNodeSet')" />
<xsl:apply-templates />
</xsl:for-each>
</xsl:template>
which effectively discards the root node. Presumably, it's worth creating a template to do the discard:
<xsl:template select="*" mode="discardRoot">
<xsl:apply-templates select="./*" />
</xsl:template>
Which you can call like so:
<xsl:apply-templates select="php:function('getNodeSet')" mode="discardRoot" />