Re: [xslt] In memory stylesheet & external entities



Daniel Veillard wrote:
> On Thu, Nov 09, 2006 at 12:03:55AM +0000, david reid wrote:
>> I'm wondering if this is possible as so far everything I've tried seems
>> to have failed :-(
>>
>> Essentially I have a stylesheet in memory that contains external
>> references (via xslo:include) that need to have paths prefixed before
>> they can be loaded.
>>
>> I have added a function to do the external entity loading and set it as
>> default. This is being called OK. The problem I'm facing is that the
>> paths to be checked are contained within a structure whos pointer I need
>> to pass in (using the _private pointer of the ctxt I think).
>>
>> I can create an xsltTransformCtxtPtr and set the _private pointer to the
>> structures address, but by that point it's too late as I need to have
>> parsed the stylesheet to create the context - or at least I couldn't
>> find another way of doing it!
>>
>> Is it possible to do what I want? Hopefully the above explanation is
>> clear enough and there is a solution.
> 
>   I'm pretty sure this was done in the past or at least discussed
> (for example when using libxslt for Webkit).
> I suggest to search thoroughtly the archives of the list in the last 2
> years. Then try to be more explicit in what calls you are using and what
> is missing.

The search seems broken at present but I did go back through the monthly
 thread listings for 2 years and found a few pointers, but nothing that
directly answers my question. :-(

I'll try and explain in more detail!

When the library init's it calls xmlSetExternalEntityLoader() to set a
custom entity loader. This is being called so all is well with this.

During the config stage a number of transformations are setup and paths
to look for includes files are configured.

When we actually do the processing we reference the structures created
during the config stage. When we are using a stylesheet from a file it's
fine if I do

style = xsltParseStylesheetFile(...)
doc = xmlParseMemory(...)
...
ctx = xsltNewTransformContext(style, doc);
ctx->_private = config;
...
result = xsltApplyStylesheetUser(style, doc, parms, NULL, NULL, ctx);

However, when the stylesheet is contained in memory and I instead do

style = xsltParseStylesheetDoc(...)
doc = xmlParseMemory(...)
...
ctx = xsltNewTransformContext(style, doc);
ctx->_private = config;
...
result = xsltApplyStylesheetUser(style, doc, parms, NULL, NULL, ctx);

It dies at an early stage (style is NULL) as the includes in the
stylesheet can't be resolved. My questions are really

- how can i parse a stylesheet in memory using a context?
- how do i create a context without needing a parsed document and
stylesheet? Do I need to?

Does that make it any clearer?

-- 
david

Have you listened to FeatherCast yet?
http://feathercast.org/

Bought the t-shirt?
http://www.cafepress.com/feathercast/


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