xml-xalan-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Minchau <minc...@ca.ibm.com>
Subject Re: Doctype never being created from <xsl:output> in 2.7.1 with JDOM?
Date Tue, 16 Sep 2008 16:25:59 GMT

Has this worked with earlier versions of Xalan-J?

The xsl:output element applies when serializing to a stream of bytes. But
you are serializing to a DOM. I suspect some, if not all of the xsl:output
attributes are ignored here.

For example, if you have <xsl:output indent='yes'
omit-xml-declaration='yes'  />, and serialize to a DOM,.... then what? The
DOM is not going to remember that, ... it is just a DOM with no concept of

Try a StreamResult rather than a SAXResult.  Does the doctype make it
through then?

- Brian

             "Syl Turner"                                                  
             nhill.com>                                                 To 
             09/16/2008 09:59                                           cc 
                                       Doctype never being created from    
                                       <xsl:output> in 2.7.1 with JDOM?    

Hi all,

I've been stuck on this for some time now, and perhaps someone here can

I have my XSLT stylesheet using <xsl:output> to set the doctype of an
XML document that doesn't have one.  For some reason, that doctype is
not being created in Xalan 2.7.1.  In 2.6, we had it making the
doctype, but ignoring comments (which turned out to be an issue with
endDTD never being used).

I created a JUnit test that removes any of our application's code and
strictly using Xalan with JDOM.  I've pasted the code below.

The Doctype of the transformed document is always null.

I'm thinking this has to do with JDOM and Xalan.

Any ideas, suggestions, etc?


import java.io.StringReader;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;

import org.jdom.Document;
import org.jdom.input.SAXHandler;
import org.jdom.output.DOMOutputter;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.ext.LexicalHandler;

import junit.framework.TestCase;

public class Test extends TestCase
    public void testDoctypeCreation() throws Exception

        String xmlDoc = "<html><!--This is the first
comment--><p>Buddies</p><!--This is the second comment--></html>";
        String xslText = "<xsl:stylesheet version=\"1.0\"
match=\"node() | @*\"><xsl:copy><xsl:apply-templates select=\"@* |
match=\"p\"><xsl:copy-of select=\".\"/>

        SAXHandler saxHandler = new SAXHandler();

        SAXSource xmlSource = new SAXSource(new InputSource(new
        SAXSource xsltSource = new SAXSource(new InputSource(new

        TransformerFactory factory = new
        SAXTransformerFactory saxFactory = (SAXTransformerFactory) factory;

        TransformerHandler handler =
        Transformer transformer = handler.getTransformer();

        SAXResult result = new SAXResult();

        result.setHandler((ContentHandler) saxHandler);
        result.setLexicalHandler((LexicalHandler) saxHandler);


        transformer.transform(xmlSource, result);

        Document transformed = saxHandler.getDocument();

        DOMOutputter output = new DOMOutputter();
        org.w3c.dom.Document dom = output.output(transformed);
        assertEquals("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">",


View raw message