*** ./contrib/xml2/xslt_proc.c.orig	2010-03-03 20:10:22.000000000 +0100
--- ./contrib/xml2/xslt_proc.c	2010-05-03 15:07:17.010918303 +0200
***************
*** 42,50 ****
  extern void pgxml_parser_init(void);
  
  /* local defs */
! static void parse_params(const char **params, text *paramstr);
  
! #define MAXPARAMS 20			/* must be even, see parse_params() */
  
  #endif /* USE_LIBXSLT */
  
--- 42,51 ----
  extern void pgxml_parser_init(void);
  
  /* local defs */
! const char **parse_params(text *paramstr);
  
! #define INIT_PARAMS 20			/* must be even, see parse_params() */
! #define EXTEND_PARAMS 20		/* must be even, see parse_params() */
  
  #endif /* USE_LIBXSLT */
  
***************
*** 59,65 ****
  	text	   *doct = PG_GETARG_TEXT_P(0);
  	text	   *ssheet = PG_GETARG_TEXT_P(1);
  	text	   *paramstr;
! 	const char *params[MAXPARAMS + 1];	/* +1 for the terminator */
  	xsltStylesheetPtr stylesheet = NULL;
  	xmlDocPtr	doctree;
  	xmlDocPtr	restree;
--- 60,66 ----
  	text	   *doct = PG_GETARG_TEXT_P(0);
  	text	   *ssheet = PG_GETARG_TEXT_P(1);
  	text	   *paramstr;
! 	const char **params;
  	xsltStylesheetPtr stylesheet = NULL;
  	xmlDocPtr	doctree;
  	xmlDocPtr	restree;
***************
*** 71,81 ****
  	if (fcinfo->nargs == 3)
  	{
  		paramstr = PG_GETARG_TEXT_P(2);
! 		parse_params(params, paramstr);
  	}
  	else
  		/* No parameters */
  		params[0] = NULL;
  
  	/* Setup parser */
  	pgxml_parser_init();
--- 72,85 ----
  	if (fcinfo->nargs == 3)
  	{
  		paramstr = PG_GETARG_TEXT_P(2);
! 		params = parse_params(paramstr);
  	}
  	else
+ 	{
  		/* No parameters */
+ 		params = palloc(sizeof(char *));
  		params[0] = NULL;
+ 	}
  
  	/* Setup parser */
  	pgxml_parser_init();
***************
*** 143,164 ****
  
  #ifdef USE_LIBXSLT
  
! static void
! parse_params(const char **params, text *paramstr)
  {
  	char	   *pos;
  	char	   *pstr;
- 	int			i;
  	char	   *nvsep = "=";
  	char	   *itsep = ",";
! 
  	pstr = text_to_cstring(paramstr);
  
  	pos = pstr;
! 
! 	for (i = 0; i < MAXPARAMS; i++)
  	{
! 		params[i] = pos;
  		pos = strstr(pos, nvsep);
  		if (pos != NULL)
  		{
--- 147,179 ----
  
  #ifdef USE_LIBXSLT
  
! const char **
! parse_params(text *paramstr)
  {
  	char	   *pos;
  	char	   *pstr;
  	char	   *nvsep = "=";
  	char	   *itsep = ",";
! 	const char **params;
! 	int	nparams;
! 	int	mparams;		/* max params */
! 	
  	pstr = text_to_cstring(paramstr);
+ 	
+ 	mparams = INIT_PARAMS;
+ 	params = (const char **) palloc(INIT_PARAMS * sizeof(char *) + 1);
  
  	pos = pstr;
! 	nparams = 0;
! 	while (*pos != '\0')
  	{
! 		if (nparams >= mparams)
! 		{
! 			/* extend params params */
! 			mparams += EXTEND_PARAMS;
! 			params = (const char **) repalloc(params, mparams * sizeof(char *) + 1);
! 		}
! 		params[nparams++] = pos;
  		pos = strstr(pos, nvsep);
  		if (pos != NULL)
  		{
***************
*** 169,180 ****
  		{
  			/* No equal sign, so ignore this "parameter" */
  			/* We'll reset params[i] to NULL below the loop */
  			break;
  		}
! 		/* Value */
! 		i++;
  		/* since MAXPARAMS is even, we still have i < MAXPARAMS */
! 		params[i] = pos;
  		pos = strstr(pos, itsep);
  		if (pos != NULL)
  		{
--- 184,195 ----
  		{
  			/* No equal sign, so ignore this "parameter" */
  			/* We'll reset params[i] to NULL below the loop */
+ 			nparams--;
  			break;
  		}
! 
  		/* since MAXPARAMS is even, we still have i < MAXPARAMS */
! 		params[nparams++] = pos;
  		pos = strstr(pos, itsep);
  		if (pos != NULL)
  		{
***************
*** 182,194 ****
  			pos++;
  		}
  		else
- 		{
- 			i++;
  			break;
- 		}
  	}
  
! 	params[i] = NULL;
  }
  
  #endif /* USE_LIBXSLT */
--- 197,208 ----
  			pos++;
  		}
  		else
  			break;
  	}
  
! 	params[nparams] = NULL;
! 
! 	return params;
  }
  
  #endif /* USE_LIBXSLT */
