Blog Posts

XMLReader and XSLT

Rob Richards (no blog yet :) ) came up with this neat idea about how to use XMLReader and XSLT together. This is especially useful, if your to-be-transformed document is huge and you don't want to or can't load that into memory.

His "trick" uses the possibility to call PHP functions from within XSLT and to get node-trees (generated with the XMLReader::expand method) as return values from them, which then can be further processed with XSLT. See the PHP code and the XSLT code for the full example.

With this approach you always will only have the expand()ed node-tree in memory and not the whole document, which can save you a lot of memory. Or even make it possible to parse that document at all, and still using XSLT for the fine control of the output.

Really nice to see how the different libxml2-based PHP extension can work together, even in a way I didn't think of before :)

Related Entries:
- php xslcache extension by the New York Times
- Added xslt profiling to PHP 5.3 and 6 CVS
- Pimp up your XSLT transformation
- Profile XSLT transformations within PHP
- Calling PHP function from XSLT vs. native XSLT functions benchmark

About the author

Comments [2]

Adam Trachtenberg, 25.03.2006 18:40 CET

Love it!

Maarten Manders, 26.03.2006 11:57 CET

Nice!

Add a comment

Your email adress will never be published. Comment spam will be deleted!