You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Bradley Wagner <br...@hannonhill.com> on 2008/11/21 16:46:13 UTC
Re: Doctype never being created from in 2.7.1 with JDOM?
I don't know that this ever worked in Xalan, but I guess I'm still
confused as to why it shouldn't. The SaxHandler has an internal JDOM
document which certainly has the ability to store information about a
DocType. Is this a limitation of SAX perhaps? I couldn't find any
events in ContentHandler or LexicalHandler that looked like they
specifically pertained to DocTypes, but maybe I was missing something.
- Bradley
On Sep 16, 2008, at 12:25 PM, Brian Minchau wrote:
> 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 serialization.
>
> Try a StreamResult rather than a SAXResult. Does the doctype make it
> through then?
>
> - Brian
>
> <graycol.gif>"Syl Turner" <sy...@hannonhill.com>
>
>
> "Syl Turner" <sy...@hannonhill.com>
> 09/16/2008 09:59 AM
>
> <ecblank.gif>
> To
> <ecblank.gif>
> xalan-j-users@xml.apache.org
> <ecblank.gif>
> cc
> <ecblank.gif>
> <ecblank.gif>
> Subject
> <ecblank.gif>
> Doctype never being created from <xsl:output> in 2.7.1 with JDOM?
> <ecblank.gif> <ecblank.gif>
>
> Hi all,
>
> I've been stuck on this for some time now, and perhaps someone here
> can help
>
> 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?
>
> Thanks!
> Syl
>
>
> 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\"
> xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template
> match=\"node() | @*\"><xsl:copy><xsl:apply-templates select=\"@* |
> node()\"/></xsl:copy></xsl:template><xsl:template
> match=\"p\"><xsl:copy-of select=\".\"/>
> yes.</xsl:template></xsl:stylesheet>";
>
> SAXHandler saxHandler = new SAXHandler();
>
> SAXSource xmlSource = new SAXSource(new InputSource(new
> StringReader(xmlDoc)));
> SAXSource xsltSource = new SAXSource(new InputSource(new
> StringReader(xslText)));
>
> TransformerFactory factory = new
> org.apache.xalan.processor.TransformerFactoryImpl();
> SAXTransformerFactory saxFactory = (SAXTransformerFactory)
> factory;
>
> TransformerHandler handler =
> saxFactory.newTransformerHandler(xsltSource);
> Transformer transformer = handler.getTransformer();
>
> SAXResult result = new SAXResult();
>
> result.setHandler((ContentHandler) saxHandler);
> result.setLexicalHandler((LexicalHandler) saxHandler);
>
> handler.setResult(result);
>
> 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\">",
> dom.getDoctype());
>
> }
> }
>
Re: Doctype never being created from in 2.7.1 with JDOM?
Posted by Brian Minchau <mi...@ca.ibm.com>.
Hi Bradley.
Which SaxHandler is that? Internal JDOM?
I don't know much about JDOM, but that isn't part of Xalan is it? I don't
know much about JDOM, but my recollection is that that it uses a lot of
memory.
- Brian
Bradley Wagner
<bradley.wagner@h
annonhill.com> To
xalan-j-users@xml.apache.org
11/21/2008 10:46 cc
AM
Subject
Re: Doctype never being created
from <xsl:output> in 2.7.1 with
JDOM?
I don't know that this ever worked in Xalan, but I guess I'm still confused
as to why it shouldn't. The SaxHandler has an internal JDOM document which
certainly has the ability to store information about a DocType. Is this a
limitation of SAX perhaps? I couldn't find any events in ContentHandler or
LexicalHandler that looked like they specifically pertained to DocTypes,
but maybe I was missing something.
- Bradley
On Sep 16, 2008, at 12:25 PM, Brian Minchau wrote:
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 serialization.
Try a StreamResult rather than a SAXResult. Does the doctype make it
through then?
- Brian
<graycol.gif>"Syl Turner" <sy...@hannonhill.com>
"Syl Turner"
<
syl.turner@h
annonhill.co <ecblank.gif>
m> To
<ecblank.gif>
xalan-j-users@xml.apache.
09/16/2008 org
09:59 AM <ecblank.gif>
cc
<ecblank.gif>
<ecblank.gif>
Subject
<ecblank.gif>
Doctype never being
created from <xsl:output>
in 2.7.1 with JDOM?
<ecblank.gif>
<ecblank.gif>
Hi all,
I've been stuck on this for some time now, and perhaps someone here
can help
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?
Thanks!
Syl
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\"
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template
match=\"node() | @*\"><xsl:copy><xsl:apply-templates select=\"@* |
node()\"/></xsl:copy></xsl:template><xsl:template
match=\"p\"><xsl:copy-of select=\".\"/>
yes.</xsl:template></xsl:stylesheet>";
SAXHandler saxHandler = new SAXHandler();
SAXSource xmlSource = new SAXSource(new InputSource(new
StringReader(xmlDoc)));
SAXSource xsltSource = new SAXSource(new InputSource(new
StringReader(xslText)));
TransformerFactory factory = new
org.apache.xalan.processor.TransformerFactoryImpl();
SAXTransformerFactory saxFactory = (SAXTransformerFactory)
factory;
TransformerHandler handler =
saxFactory.newTransformerHandler(xsltSource);
Transformer transformer = handler.getTransformer();
SAXResult result = new SAXResult();
result.setHandler((ContentHandler) saxHandler);
result.setLexicalHandler((LexicalHandler) saxHandler);
handler.setResult(result);
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\">",
dom.getDoctype());
}
}