Recently I’ve been using libxslt to do some XSLT transformations within a C application and, as you’d expect, it works well and is quite easy to use when you use templates stored in files. One of my use cases though involves using a template that is in memory – something that causes a few problems.
The problem is that the template uses xsl:include to include some file based templates, but as the main template is in memory there is no path from which libxslt can work to build the filenames for the included files. When I came across this I confidently went to a search engine and looked for a solution, expecting that I wouldn’t be the only person who had come across this problem. When nothing seemed obvious I joined the mailing list and asked there.
The solution is to write an xsltDocLoaderFunc and add the require path logic to that function. This works. The paths to be searched are, however, contained in a structure related to the template being processed, a structure whos pointer I need for this to work. At the moment I can’t see anyway of passing the pointer to the library such that it’s available within the xsltDocLoaderFunc function and so it doesn’t work. I’ve looked at lots of different ways of doing it, but nothing seems to work.
If anyone has any ideas I’d love to hear them.