xml - create NodeSet in XSLT from PHP function -


i want create xml in php function , return xslt. in xslt create node-set , use it.

in php have function returns xml string.

function xmlstring() {     $string = ''.         '<test>'.             '<a>1</a>'.             '<b>2</b>'.         '</test>'.         '<test>'.             '<a>3</a>'.         '</test>'.     '';     return $string; } 

i registered function in php , use in xslt

<xsl:variable name="xmlstring">     <xsl:value-of select="php:function('xmlstring')" /> </xsl:variable> 

to disable output escaping used disable-output-escaping="yes" on value-of

i played around exsl:node-set can't work

i use <xsl:value-of select="exsl:node-set($xmlstring)/test/b" />

here example tested php 5.5:

<html> <head> <title>php extension function returns dom document fragment xslt treated node-set in xslt</title> </head> <body> <?php  function makexml() {     $doc = new domdocument();     $frag = $doc->createdocumentfragment();     $frag->appendxml('<test><a>foo</a></test><test><a>bar</a></test>');     return $frag; }   $xml = <<<eob <root></root> eob;  $doc = new domdocument(); $doc->loadxml($xml);  $xsl = <<<'eob' <xsl:stylesheet version="1.0"       xmlns:xsl="http://www.w3.org/1999/xsl/transform"      xmlns:exsl="http://exslt.org/common"      xmlns:php="http://php.net/xsl"      exclude-result-prefixes="exsl php">  <xsl:output method="html" encoding="utf-8" indent="yes"/>   <xsl:template match="/">   <xsl:variable name="frag" select="php:function('makexml')"/>    <ul>     <xsl:apply-templates select="$frag/test/a"/>   </ul>   </xsl:template>   <xsl:template match="a">    <li>      <xsl:apply-templates/>    </li>  </xsl:template> </xsl:stylesheet> eob;  $xsldoc = new domdocument(); $xsldoc->loadxml($xsl);  $proc = new xsltprocessor(); $proc->registerphpfunctions();  $proc->importstylesheet($xsldoc); echo $proc->transformtoxml($doc);   ?>  </body> </html> 

output

<html>                                                                                                                                 <head>                                                                                                                                <title>php extension function returns dom document fragment xslt treated node-set in xslt</title>                                                                                                                                 </head>                                                                                                                                <body>                                                                                                                                 <ul>                                                                                                                                   <li>foo</li>                                                                                                                           <li>bar</li>                                                                                                                           </ul>                                                                                                                                  </body>                                                                          </html> 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -