return node-set via php:function

liunx

Guest
How do I return a node-set via php:function?
I've had no difficulty returning strings, but xsl refuses to see the result as something I can iterate as real XML.

PHP 5.1.2 ; libxml 2.6.22

php fragment:
function getNodes() {
return '<RESULT>'
. ' <NODE>foo</NODE>'
. ' <NODE>bar</NODE>
. '</RESULT>';
}

xsl fragment:
<xsl:variable name="nodes">
<xsl:copy-of select="php:function('getNodes')" />
</xsl:variable>
cnt=<xsl:value-of select="count($nodes/RESULT/NODE)" />

expected output: cnt=2
actual output: cnt=0

This is because the xsl variable "nodes" contains a string rather than an actual node-set.

I also tried this, but libxml2 evidently does not support this URI form:
<xsl:variable name="tmp">
<xsl:value-of select="php:function('getNodes')" />
</xsl:variable>
<xsl:copy-of select="document(concat('data:text/xml,',$tmp))" />

Any help would be greatly appreciated.
thanksJust to clarify, returning a DOM object from the php function (rather than string) also fails to deliver the desired result:

php fragment:
function getNodes() {
$xml = '<RESULT><NODE>foo</NODE><NODE>bar</NODE></RESULT>';
$doc = DomDocument::loadXML($xml);
return $doc;
}

<xsl:copy-of select="php:function('getNodes')" />
- This still yields a string. I assume the DOM object is being cast somewhere along the line.

<xsl:copy-of select="document(php:function('getNodes'))" />
- This returns and empty node-set

<xsl:variable name="tmp"><xsl:value-of select="php:function('getNodes')" /></xsl:variable>
<xsl:copy-of select="document(concat('data:text/xml,',$tmp))" />
- And this returns an empty node-set


Am I missing something? Is it broken? Or broken by design?
 
Back
Top