[SOLVED] For anyone who follows, the problem was with the xmlDocDumpFormatMemoryEnc call. When that line and the following "if (buffer)" conditional expression were replaced with "if (!xsltSaveResultToString(&buffer, &length, pDocOutput, cur))", the problem went away.
Thanks for your input. -Al On Wed, Jul 22, 2009 at 12:14 PM, Michael Ludwig<[email protected]> wrote: > Al Pacifico schrieb: >> >> The xsl:output element attributes omit-xml-declaration and method are >> correctly set to "yes" and "text" respectively. My JSON result string >> produced by the following code is prefaced by an XML declaration, >> which is unwanted. > >> //Use the parsed stylesheet on the XML: >> xmlDocPtr pDocOutput = xsltApplyStylesheet(cur, >> const_cast<xmlDoc*>(xml_document.cobj()), 0); >> xsltFreeStylesheet(cur); >> >> //Get the output text: >> xmlChar* buffer = 0; >> int length = 0; >> xmlIndentTreeOutput = 1; //Format the output with extra white >> space. TODO: Is there a better way than this global variable? >> xmlDocDumpFormatMemoryEnc(pDocOutput, &buffer, &length, 0, 0); > >> My result string is beginning with '<?xml version="1.0" >> encoding="UTF-8"?>\n', not what I want. Same stylesheet (available at >> http://www.xml.lt/static/files/xml2json.xsl) and xsltproc or >> libxslt_tutorial.c from the libxslt website works fine. >> >> I must be doing something wrong. Guidance? > > Hi Al, > > I don't know about C, but quite often when xsl:output isn't respected, > that means the XSLT serializer isn't in charge because you're outputting > the result to a document object - not to a buffer or a string. If you > want the XSLT serializer to be in charge, you must write to a buffer. > But I don't know how that translates to the C API. > > In Perl, there are a couple of options: > > * output_string(result) > * output_as_bytes(result) > * output_as_chars(result) > * output_fh(result, fh) > * output_file(result, filename) > > What can be done in Perl definitely can be done in C. > > Hope this helps. > > Michael Ludwig > _______________________________________________ > xslt mailing list, project page http://xmlsoft.org/XSLT/ > [email protected] > http://mail.gnome.org/mailman/listinfo/xslt > -- Al Pacifico Seattle, WA _______________________________________________ xslt mailing list, project page http://xmlsoft.org/XSLT/ [email protected] http://mail.gnome.org/mailman/listinfo/xslt
