However, when using PHP functions in XSLT, many people encounter the following two errors:
(1) Warning: effectprocessor: transformToXml (): xmlXPathCompiledEval: 1 objects left o
N the stack.
(2) PHP Warning: effectprocessor: transformToXml (): xmlXPathCompOpEval: function func
Tion bound to undefined prefix php in ....
The code is as follows: |
Copy code |
<? Php $ Xml = <EOB <Allusers> <User> <Uid> bob </uid> </User> <User> <Uid> joe </uid> </User> </Allusers> EOB; $ Xsl = <EOB <? Xml version = "1.0" encoding = "UTF-8"?> <Xsl: stylesheetversion = "1.0" Xmlns: xsl = "http://www.w3.org/1999/XSL/Transform"> <Xsl: output method = "html" encoding = "UTF-8" indent = "yes"/> <Xsl: template match = "allusers"> <Html> <body> <H2> Users <Table> <Xsl: for-each select = "user"> <Tr> <td> <Xsl: value- Select = "php: function ('ucfirst', string (uid)"/> </Td> </tr> </Xsl: for-each> </Table> </Body> </Xsl: template> </Xsl: stylesheet> EOB; $ Xmldoc = DOMDocument: loadXML ($ xml ); $ Export doc = DOMDocument: loadXML ($ xsl ); $ Proc = new effectprocessor (); $ Proc-> registerPHPFunctions (); $ Proc-> importStyleSheet ($ export Doc ); Echo $ proc-> transformToXML ($ xmldoc ); ?> |
In fact, this error occurs because we have not defined the PHP namespace.
The code is as follows: |
Copy code |
<Xsl: stylesheetversion = "1.0" Xmlns: xsl = "http://www.w3.org/1999/XSL/Transform">
|
Add xmlns: php = "http://php.net/xsl" to solve this problem, that is
The code is as follows: |
Copy code |
<Xsl: stylesheetversion = "1.0" Xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" Xmlns: php = "http://php.net/xsl"> |