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 :)