[
Lists Home |
Date Index |
Thread Index
]
I don't think either of these is JAXP or the XSLT processor's fault.
First of all, the DTD shouldn't be included in the result, because an
identity transform in XSLT does not preserve DTDs (since they're not a part
of the XPath data model).
Secondly, the missing namespace *is* a problem, but I suspect that's due to
the DOMImlementation, rather than the Transformer object per se. I've run
into this problem before, and I can't say I remember what the solution was.
Someone expert in DOM should probably chime in here. You may need to set
some flag regarding namespaces.
Finally, a more interesting question (for me) regards ID attributes. I
recall seeing that SAXON's implementation of the JAXP identity transformer
preserves the ID information in the result if the result is a DOMResult. In
other words, the id() function still works on a source tree that has
undergone a SAXON JAXP identity transform. This, of course, doesn't happen
if you try an explicit XSLT identity transform. A copied element does not
include its ID (this represents a huge bug in XSLT 1.0, but I digress).
Evan
> -----Original Message-----
> From: Elliotte Rusty Harold [mailto:elharo@metalab.unc.edu]
> Sent: Friday, January 04, 2002 10:33 AM
> To: xml-dev@lists.xml.org
> Cc: xml-interest@java.sun.com
> Subject: [xml-dev] JAXP's ID Transform failing to include namespace
> declaration attributes
>
>
> I've hit an unclear spot in the JAXP specification regarding the
> behavior of ID transforms. I think one thing should be happening and
> I know something else is happening but I'm not absolutely clear on
> whether or not I'm right. Clarification would be appreciated.
>
> Suppose we want to use DOM and JAXP to produce the following
> document or its
> equivalent, modulo white space and other insignificancies:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
> "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
> <svg xmlns="http://www.w3.org/2000/svg"/>
>
> I claim the following code should do the trick, given that impl is a
> DOMImplementation object:
>
> // Create the document
> DocumentType svgDOCTYPE = impl.createDocumentType(
> "svg", "-//W3C//DTD SVG 1.0//EN",
> "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"
> );
> Document doc = impl.createDocument(
> "http://www.w3.org/2000/svg", "svg", svgDOCTYPE);
>
> // Serialize the document onto System.out
> TransformerFactory xformFactory
> = TransformerFactory.newInstance();
> Transformer idTransform = xformFactory.newTransformer();
> Source input = new DOMSource(doc);
> Result output = new StreamResult(System.out);
> idTransform.transform(input, output);
>
> However, what this in fact produces is
>
> <?xml version="1.0" encoding="UTF-8"?>
> <svg/>
>
> There are two problems here:
>
> 1. The namespace is lost on the svg element.
> 2. The DOCTYPE declaration is lost.
>
> The details are a little implementation dependent. SAXON and Xalan-J
> both give these results. However, Gnu JAXP can mask it because it has
> a bug that cancels out this bug.
>
> I think both of these are problems with the idTransform. According to
> the JAXP specification, p. 62, "If all that is desired is the simple
> identity transformation of a source to a result, then
> TransformerFactory90 provides a newTransformer()93 method with no
> arguments. This method creates a Transformer that effectively copies
> the source to the result. This method may be used to create a DOM
> from SAX events or to create an XML or HTML stream from a DOM or SAX
> events."
>
> This is less than perfectly clear on issues like whether it should
> insert namespace attributes as necessary or include the DOCTYPE
> declaration. However, I think that what's actually output really doesn't
> strike me as a copy of the source to the result because a lot of
> significant information has been lost.
>
> Yes, I know that I could add the xmlns attribute, at least, manually.
> However, I think this should be closer to the default behavior of
> XMLSerializer where namespace declaration attributes are inserted
> automatically in the stream as necessary.
> --
>
> +-----------------------+------------------------+-------------------+
> | Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
> +-----------------------+------------------------+-------------------+
> | The XML Bible, 2nd Edition (Hungry Minds, 2001) |
> | http://www.ibiblio.org/xml/books/bible2/ |
> | http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/ |
> +----------------------------------+---------------------------------+
> | Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
> | Read Cafe con Leche for XML News: http://www.ibiblio.org/xml/ |
> +----------------------------------+---------------------------------+
>
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
>
> The list archives are at http://lists.xml.org/archives/xml-dev/
>
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>
>
|