PHP function workaround cannot be called after registerphpfunctions in xsltprocessor _php tutorial

Source: Internet
Author: User
Tags xsl xslt
XSLT is a very handy tool for translating XML, which is implemented through xsltprocessor, with many useful functions built into the XSLT, and only the Registerphpfunctions method that calls the Xsltprocessor instance, I We can use PHP's functions directly in XSLT, which greatly enhances the processing power of XSLT.

However, when using PHP functions in XSLT, many people encounter the following two types of errors:

(1) warning:xsltprocessor::transformtoxml (): Xmlxpathcompiledeval:1 objects left O
n the stack.
(2) PHP warning:xsltprocessor::transformtoxml (): xmlxpathcompopeval:function func
tion bound to undefined prefix php in ....

The code is as follows Copy Code

$xml = <<


Bob


Joe


EOB;
$xsl = <<


Xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >



Users








select= "php:function (' Ucfirst ', string (UID))"/>




EOB;
$xmldoc = Domdocument::loadxml ($xml);
$xsldoc = Domdocument::loadxml ($xsl);

$proc = new Xsltprocessor ();
$proc->registerphpfunctions ();
$proc->importstylesheet ($xsldoc);
echo $proc->transformtoxml ($xmldoc);
?>

In fact, this error occurs because we don't have a PHP namespace defined, just

The code is as follows Copy Code

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


Xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform"
xmlns:php= "Http://php.net/xsl" >

http://www.bkjia.com/PHPjc/632243.html www.bkjia.com true http://www.bkjia.com/PHPjc/632243.html techarticle XSLT is a very handy tool for translating XML, which is implemented by Xsltprocessor, and there are many useful functions built into XSLT, and you only need to invoke Xsltprocessor instances ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.