[xslt] Starting Over - No user context available when apply stylesheet loads an external entity



Hi all,

I'm sorry for this. My second post on this subject was incorrect, so I am starting the whole thing again.

I have an application that uses libxml2 to parse an XHTML file, then uses libxslt to apply one or more XSL stylesheet transformations to the document. The result of this is then extracted as a HTML string and given to a web browser control to display.

I have registered an external entity loader with libxml by calling xmlSetExternalEntityLoader(). I have a set of search paths that are registered with my code, and the loader function handles searching them in the proper order.

The problem that I have is that I need to have multiple windows open, each of which displays a different XHTML document (after parsing and applying stylesheet transformations). Each window can have its own set of search paths for file loading. This means that when my external entity loader is called, I need to have enough context so that I can find the proper set of search paths.

For parsing the XML file, I discovered and started using xmlCtxtReadFile(). I allocate a parser context, use the _private data member to store my context, then retrieve it in the entity loader.

However, when I apply a XSL stylesheet transformation to my document, using xsltApplyStylesheetUser(), it often loads other XHTML source files. This calls the loader, but the parser context that is passed in has no context information that I can use to find the correct path set. The myDoc member has a value of 0, and there is no pointer to the xsltTransformContext, so I can't get at its _private data member. I also tried setting the _private data member in the transform context, hoping that it might be propagated to the parser context, but that doesn't happen.

I tried writing my own XSLT loader function, assuming that it would always be passed a transform context pointer (even if it was cast as void *) and I could copy its _private data member to the new parser context. I registered my loader function by calling xsltSetLoaderFunc() and I see it get called. (My previous post said this didn't happen, but that was a build problem.) The problem with this approach is that the XSLT loader function can get called with a NULL context pointer, so that puts me back in the original position. When the XML external entity loader function gets called, I need information that lets me pick the proper path set to search.

Is this achievable without resorting to some nasty semaphore hack?

Thanks,
Rush


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]