After playing with "ajax" a little for random images on my pictures from old books Web site, I spent some time investigating other XQuery engines, and in parcticular what used to be Sleepycat's dbxml, and is now Oracle Sleepycat DB XML.
I was using the Perl interface, and maybe that's a mistake, because it's obvious that they don't spend as much effort on it as on the C API. The documentation is very minimal, for example. But in the end, and after uninstalling all unwanted versions of bsd db from my laptop, it worked. Query time went doewn from 11 seconds to 2 seconds, partly because the 11-second version is starting a JVM for each query, partly because dbxml is in C, and partly because I had to remove some features from the query because I couldn't get them to work.
After help from one of the people maintaining the software, I discovered that I'll be able to get the other features to work. The search engine on my Web site isn't actually too slow for most queries (try it here) but it's using more memory than I'd like, and there are some queries on my photographs that do take too long.
The good thing about using XQuery to develop these things is that it's relatively easy to make changes. So maybe some changes are coming.