Re: [xslt] Embedded Stylesheets

Oh, and ignore all the obvious leaks in my function. I will fix them later. ;)


On Aug 13, 2004, at 4:22 PM, David Hyatt wrote:

Now that I have simple transforms using external stylesheets working in Safari, I'm trying to make embedded stylesheets work. The example I'm working with is one from Mozilla. Here it is:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
<xsl:stylesheet version="1.0" id="stylesheet" xmlns:xsl="";>
<xsl:output method="html"/>
<xsl:template match="xsl:stylesheet"/>
<xsl:template match="child">
<head><title>title of embedded stylesheet</title></head>
<xsl:template match="grandchild">
<h1>Transformation was <xsl:apply-templates/></h1>

When I feed this content to libxml to parse, however, I get the following error:

file:///Users/hyatt/Documents/xslexample2.xml:1: parser error : Extra content at the end of the document

If I change the "text/xsl" MIME type to "text/css", the error disappears. libxml basically fails to parse, and so I'm unable to then run the code that would have tried to apply the stylesheet to the doc (by using xsltLoadStylesheetPI to extract a stylesheet that I could then apply to the xmlDoc).

Any ideas why this fails in libxml?

Here is my function in Safari (for the curious):

DocumentImpl* XSLTProcessorImpl::transformDocument(DocumentImpl* doc)
    xsltStylesheetPtr sheet = NULL;
    if (!m_embedded) {
        if (!m_stylesheet || !m_stylesheet->document())
            return 0;
        sheet = xsltParseStylesheetDoc(m_stylesheet->document());
        if (!sheet)
            return 0;

// Create an XMLParserContext and then build up an xmlDocPtr
xmlParserCtxtPtr parser = xmlCreatePushParserCtxt(NULL, NULL, NULL, 0, doc->URL().ascii());
const QChar BOM(0xFEFF);
const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char *>(&BOM);
xmlSwitchEncoding(parser, BOMHighByte == 0xFF ? XML_CHAR_ENCODING_UTF16LE : XML_CHAR_ENCODING_UTF16BE);
reinterpret_cast<const char *>(doc->transformSource().unicode()),
doc->transformSource().length() * sizeof(QChar), 1);
xmlDocPtr sourceDoc = parser->myDoc;
if (!sourceDoc || !parser->wellFormed)
return 0; <------ THE FAILURE HAPPENS HERE

if (m_embedded) {
// Attempt to obtain the stylesheet from within our parsed source document.
sheet = xsltLoadStylesheetPI(sourceDoc);
if (!sheet)
return 0;

    xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, NULL);
    DocumentImpl* result = documentFromXMLDocPtr(resultDoc, sheet);
    if (m_stylesheet)
    return result;

(hyatt apple com)
xslt mailing list, project page
xslt gnome org

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