"Re: [xslt] Apply stylesheet to a subbranch of a document"


Daniel Veillard wrote:
> On Tue, Sep 16, 2003 at 01:02:35PM +0200, Kasimier Buchcik wrote:
>>I just wondered if one can apply a stylesheet to a subbranch of a 
>>document. I learned that there is xsltApplyStylesheet that takes a 
>>source document and a stylesheet, but no trace of a function that takes
>>a node from the document and applies a stylesheet. Can someone point out 
>>a way of doing that? Or do I have to clone the node into a separate 
>>document and perform xsltApplyStylesheet on it?
>   If you look at xsltApplyStylesheetInternal() code, there is a bunch
> of processing needed before and after launching the recursive evaluation
> done on the root node by
>    xsltProcessOneNode(ctxt, ctxt->node, NULL);
> I don't think it is wise to try to attempt a direct processing, and
> the document passed to xsltApplyStylesheet() will be modified, you
> may not want that to happen to a subtree. So I suggest building a new
> document with a copy of the subtree as the cleaner approach.
> Daniel

I took a quick look inside xsltApplyStylesheetInternal()...
The given doc is set as the initial context node of the transformation:

ctxt->node = (xmlNodePtr) doc;

Would the transformation still work correctly if we specify a node other 
than the document as the initial context node?
Could there be a public function like:

xsltApplyStylesheet(xsltStylesheetPtr style, 

   xmlDocPtr doc,
   xmlNodePtr ctxNode,
   const char **params);

with ctxNode specifying the initial context node?


Kasimier Buchcik

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