One thing to note about this function. A lot of values need to be converted to a XSLT string using the "string()" function in XLS before you pass them to your functions, and when you return them make sure that if they are strings that you call the "strval()" in php before doing so. This saved me hours.

One of the peskiest things I had problems with was encoding URL parameters. I mean, pretend you want to populate a link with "search+terms" instead of just "search terms". I was including two seperate URLs in the XML and that was ludicrous.

Below is a far more elegant PHP+XSLT solution. You will also see it uses two *undocumented* features of registerPHPFunctions(), namely php:functionString() and the passing of parameters to the function. I figured this out by trial and error; I really hope this note helps you as it *greatly* expands the power of php functions in XSLT!

One thing I have told a lot of people to do if they are having issues with this function is to check for any 'xmlns' attributes that get generated and added to your xml pages by some types of popular software.

//You don't remove them then this function will blow up. $xslt->registerPHPFunctions();$xslt->importStyleSheet(DomDocument::load('../xsl/message.xsl'));print $xslt->transformToXML(DomDocument::loadXML($docxml));

?>

Also a few cool tricks with this function is that you can call built in PHP functions. For example:

That XSL value will now return your normal string but replaceall your new line charactors in your xml with '<br />'s.

Also note the 'disable-output-escaping="yes"' statement. If you don't call this, then the output of that bind will be ran thru basicly a "htmlencode()" type function.

Last but not least, take a look at the 'string()' function I called in XSL before passing it back. That is because without calling that, when it runs it will try and pass the node object, and not its value (which is what you most likely only want).

This function is very awsome and could lead to some very interesting code development. Skins could be loaded remotely. You could write an RSS viewer in PHP without much code. You could parse XHTML pages into another view (either localy or remotely). Then you can take that same XML content and throw it against ASP.NET, Java, or even a command line processing tool using that same exact XSL style sheet and generate the front ends for you page without much change. I'm very excited.

BTW, in 5.1.6 double-colon (::) is the only thing that works when calling a function that resides within a class. However, you must declare your function as static. Using -> as some have suggested (e.g., php:function ('instance_name->function_name','garbage')) doesn't work at all, no matter how you declare your function.

Unfortunately, you can't pass arrays to PHP from XLST.But you can pass an arbitrary number of arguments to a PHP function and then get them with func_get_args() as an array.[There's no sense writing a function that is identical to the array() construct, because a function's return value is converted to a string when passed as an argument to another function. This means deep arrays cannot be handled this way.]

You don't have to return a DOMDocument, DOMElement works just as well. Plus, retuning a DOMElement gets around the problem of discarding the root node which I discuss below and which is also touched on by "Ingram".