Re: [xslt] How I can detect processing errors ?

Vladimir Grebenschikov said:
> On ср, 2004-03-03 at 05:49 -0500, Daniel Veillard wrote:
>>   No sensible analysis can be done with the data you provided.
>> Please read
> Ok, more details (all files in attachments):
> Part of program: (see attachment for full)
>    doc = xmlParseFile(argv[i]);
>    res = xsltApplyStylesheet(cur, doc, params);
>    if (!res) errx(-1, "fail to do xsltApplyStylesheet()");
>    rc = xsltSaveResultToString((xmlChar **)&buf, &size, res, cur);
>    warnx("xsltSaveResultToString() returns %d, size = %d, ptr =
> %lx",
> rc, size, buf);
> So it is not possible to detect this error on transformation stage.
>> Daniel
> --
> Vladimir B. Grebenschikov
> SWsoft Inc.

Ah, one should never say "not possible".  The problem that you have
is that you are calling upon the libxslt library at the highest
level with "xsltApplyStylesheet".  The application of the stylesheet
certainly had problems, but those were at a lower level (at the
level of "transformation context"), and there is no way to detect
those errors after the transformation context has been completed and
deleted.  The high level result of the errors is, in fact, an "empty
document", and the variable 'res' points to this structure, i.e. is
not null.

So, what can you do about this?  Well, instead of using
xsltApplyStylesheet, try using xsltApplyStylesheetUser.  To use this
function, you create your own transformation context and then apply
the stylesheet using that context.  When the function returns, you
can examine the results within the context and act appropriately. 
More specifically, replace your current

   res = xsltApplyStylesheet(cur, doc, params);
   if (!res) errx(-1, "fail to do xsltApplyStylesheet()");

with the sequence

xsltTransformContextPtr ctxt;
   ctxt = xsltNewTransformContext(cur, doc);
   res = xsltApplyStylesheetUser(cur, doc, params, NULL,
                     stderr, ctxt);
   if ((ctxt->state == XSLT_STATE_ERROR) ||
       (ctxt->state == XSLT_STATE_STOPPED))
           errx(-1, "fail to do xsltApplyStylesheet()");

and you should get what you are asking for.

Good luck,


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