doutan2111 2013-03-04 13:35
浏览 33

PHP在XSLT1中注册了函数,如何用PHP返回XML片段?

I am using PHP with XSL and registerPHPfunctions.

It is ok for return PHP string values with xsl:value-of, but I not know how to return XML fragments from PHP.


Example at XSLT:

 <xsl:template match="table">
     <xsl:copy-of select="php:function('myfunc',.)"/>
 </xsl:template>

Example at PHP:

 function myfunc($x) {return '<table><tr><td>ok</td></tr></table>';}

Result is not XML but a "lt/gt/amp enconded XML". Use of copy-of or value-of at XSL, not modify the return behaviour. It is a cast problem?

PS: even with identity function, I tested, it not returns the XML node,

 function myfunc($x) {return $x;}
  • 写回答

2条回答 默认 最新

  • douzhi0107 2013-03-04 20:16
    关注

    OPS, it is some kind of magic! Now the @hek2mgi tip is working!

    I am using

     <xsl:template match="table">
      <xsl:copy-of select="php:function('myfunc',.)" disable-output-escaping="yes" />
     </xsl:template>
    

    ...I will back here in some days to say something more about "stable solution" and conclusions...

    评论

报告相同问题?