Re: [xslt] xsltSaveTo() problem



On Mon, Jun 18, 2001 at 01:49:29PM +0100, Fabrice DESRE - FT.BD/FTRD/DMI/GRI wrote:
>   Hello,
> 
>  I'm facing a strange problem with xsltSaveTo() :
> When the ouput method of the stylesheet is not
> xml (eg, html or text), the buffer's write callback
> is never called. On the other hand xsltSaveToFile() 
> works nicely...
>  I attach a small test program that fails.

  If you look at xsltSaveToFile() it simply create an output buffer,
call xsltSaveTo(), close the buffer and return the number of byte
written.

  Right, I forgot to call xmlOutputBufferFlush(buf) in the text and
HTML cases.

  But you forgot to call xmlOutputBufferClose(buf) which would
have forced the flush like xsltSaveToFile() does.
  And write_xml_res is completely broken, not returning the
the number of byte written, tmp[len] = 0 is missing after 
the call to snprintf(tmp, len, ...), and the call to snprintf
should be  snprintf(tmp, len + 1, ...), making the whole test not
accurate at all.

  I don't like receiving C code for tests since I usually end up debugging
it and it's not what I ought to do. I admit that in this case there is
no facilities in xmllint or xsltproc allowing to trigger the associated
bug... it also had the benefit of showing a bug in the xsl:output='text'
(where text node not under the root were not saved).

  The patches are commited in CVS as:
http://cvs.gnome.org/bonsai/cvsquery.cgi?module=libxslt&branch=HEAD&branchtype=match&dir=libxslt&file=&filetype=match&who=veillard&whotype=match&sortby=Date&hours=&date=explicit&mindate=06%2F18%2F01+12%3A38&maxdate=06%2F18%2F01+12%3A38&cvsroot=%2Fcvs%2Fgnome

  thanks for the report !

Daniel

P.S.: the fixed routine looks like the following and still miss a check
      against len >= 8192. Next time I will negociate an exemption of my
      ADSL bill before doing this extra consulting work ;-)

int write_xml_res(void * ctx, const char *buffer, int len) {
   char tmp[8192];

   fprintf(stderr, "\nWrite callback called : %d\n", len);
   if (len > 0) {
       snprintf(&tmp[0], len + 1, "%s", buffer);
       tmp[len] = 0;
       fprintf(stderr, "%s", tmp);
       return(len);
   }
   return(0);
}

-- 
Daniel Veillard      | Red Hat Network http://redhat.com/products/network/
veillard@redhat.com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
Sep 17-18 2001 Brussels Red Hat TechWorld http://www.redhat-techworld.com




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