Using Named Buffers
Thus far, all the examples you've seen have assumed the XML and XSLT data to be stored in static files. This assumption is true in most cases; however, some occasions do arise when your XML is dynamically generated, either from a database, by combining two or more files, or from some other dynamic data source. In such cases, saving this dynamically generated XML to a file and then processing it with xslt_process() can be a needlessly long and tedious process.
This is where named buffers come in. Named buffers allow you to store your XML and XSLT data in memory and then pass these variables on to xslt_process() for normal XSLT transformation.
As discussed in the "A Closer Look at xslt_process()" sidebar, the xslt_process() function can actually accept up to six arguments. Typically, the second and third arguments are references to the XML and XSLT files; however, they can also be the names of buffers containing the XML and XSLT data.
The following snippet might make this clearer:
As you can see, I first defined an associative array named $arg_buffer, and set it up with two keys representing the XML and XSL data, respectively. Next, I've used these keys (with the arg: prefix) as arguments to xslt_process(), which reads the data in the corresponding buffer and uses it to perform the transformation.
It should be noted at the outset that this capability is available only if your PHP build uses the Sablotron engine. This is because the arg: URI scheme is a Sablotron-specific extension, and it is not likely to work with other XSLT processors.
When using this technique, it is mandatory to specify the name of the variable containing the buffers as the (otherwise optional) fifth argument to xslt_process().
Listing 4.7 is a detailed example to put it all in context.
You should also take a look at Listing 4.12, which demonstrates how named buffers can be used with dynamically generated XML data from a database.