Re: [xslt] How can I tell the type of output I receive?



David Hyatt said:
> I am very close to having a basic transform working in Safari.  I am
> using the following function:
>
> xsltSaveResultTo
>
> And I have collected the output from this call.  The problem is that
> I
> now need to do three different things with this output depending on
> whether it's HTML, XML/XHTML, or text.  I notice from looking at the
> source that xsltSaveResultTo has a lot of logic for figuring out
> what
> the type of the output is before it actually does the serialization.
> Is there any way that I can get to this information, or is it not
> exposed yet?
>
> If it isn't exposed, could xsltSaveResultTo be enhanced in some way
> to
> provide some indicator of the type of the output?
>
> Thanks!
> dave
> (hyatt apple com)

Reading the code of xsltSaveResultTo, it appears to me that there is
actually very little logic involved.  Assuming that the variable
"result" is an xmlDocPtr pointing to the result of the
transformation and "style" is an xsltStylesheetPtr pointing to the
stylesheet, and further assuming everything has already been
verified/validated when xsltSaveResultTo was called, then:

-----------
const xmlChar *myMethod;

    XSLT_GET_IMPORT_PTR(myMethod, style, method)
    if ((myMethod == NULL) && (result->type == XML_HTML_DOCUMENT_NODE))
        myMethod = (const xmlChar *) "html";
-----------

gives you what you are asking for - a string which says
    "html"  - it's HTML
    "text"   - it's TEXT
    "xhtml"- it's XHTML
    anything else, including NULL, is XML

The macro XSLT_GET_IMPORT_PTR is only needed to take care of the
proper cascading of imported stylesheets; if it's guaranteed there
are no imports, then style->method could be directly accessed.

HTH

Bill



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