Re: [xslt] xsltInit preventing multiple transformations with libxslt:node-set



On Mon, Jan 24, 2005 at 04:44:18PM -0700, Allen, Erik wrote:
> 	I have the following code within my program:
[...]
> xsltCleanupGlobals();
> xmlCleanupParser();
> 
> 	This is pretty much taken from the example code
> 	The problem I'm having is that if it is run twice in a row with
> a particular XSL file, the second pass will not work. The first pass
> will work perfectly. I've traced through the code, and I know what the
> problem is.
> 	The XSLT being used has the following line in a template
> 
> 	<xsl:variable name="issueXML"
> select="libxslt:node-set($issueList)"/>
> 	
> 	The libxslt:node-set function doesn't work the second time.
> 	The problem is happening in xsltInit() in xslt.c:
> 
> static void
> xsltInit (void) {
>     static int initialized = 0;
> 
>     if (initialized == 0) {
> 	initialized = 1;
> 	xsltRegisterAllExtras();
>     }
> }
> 
> 	This function uses a static local variable 'initialized' to see
> if it needs to call xsltRegisterAllExtras(). That will fill in the
> global 'xsltFunctionsHash' which contains the information about the
> libxslt:node-set function. The 'xsltFunctionsHash' global is being
> unloaded with the xsltCleanupGlobals() call. That doesn't have access to
> xsltInit::initialized, and so can't clear it.
> 	The second time through, xsltInit() sees that 'initialized' is
> still set to 1, and so it doesn't need to call xsltRegisterAllExtras().
> 'xsltFunctionsHash' remains NULL, and when the libxslt:node-set function
> is encountered, it is unrecognized.
> 	I can see how this problem can be missed, because
> libxslt:node-set isn't a standard xslt function and it works the first
> time. I think the best solution to this problem would be to change
> 'initialized' into a global, so that xsltCleanupGlobals() could reset it
> to 0. Another possibility is to have the check for initialization
> instead just check if xsltFunctionsHash is not NULL.

  Makes sense this should be fixed.
  Please bugzilla this (our global memory !), but you should only call 
xsltCleanupGlobals(); when your are really done with libxslt and
xmlCleanupParser(); when you are really done with both libxslt and libxml2,

Daniel

-- 
Daniel Veillard      | Red Hat Desktop team http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/


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