[jdom-interest] JDOMResult silently absorbs document fragments (was: Re: [jdom-interest] Question about JDOMResult and usage with XMLReader)

Elliotte Rusty Harold elharo at metalab.unc.edu
Mon Aug 19 07:19:19 PDT 2002

>1. DOMResult can indeed return a DocumentFrangment but I do not 
>agree with you for SAXResult: It is configured with a ContentHandler 
>and the javadoc for ContentHandler states: "Receive notification of 
>the logical content of *a* document".
>So it seems SAXResults should not accept document fragments (and 
>JDOMResult extends SAXResult). What is the SAX event flow fired by 
>an XSLT processor when reporting a document fragment? For example, 
>are start/endDocument fired in case of document fragments?

This may be a point of friction between SAX and XSLT. I don't think 
this is clearly defined. However, in practice, SAXResult will fire 
events at the content handler, even if that gives you a sequence of 
events without a root.

>2. How would JDOMResult decide what the result actually is: If the 
>transformation returns a list of nodes, no problem; but if a single 
>element is returned, should it return a Document or an Element? Is 
>there something in the XSLT spec to help distinguish between these 2 

I think that no XSLT transform ever returns a document node. The 
result tree it returns may contain various types of nodes. It 
probably makes the most sense to have all XSLT results return a List 
of node objects, whether that list is empty, contains a single 
Element, or contains multiple nodes. I suggest we never return a 
Document or an Element; instead we always a return a List.

The programmer who knows what the stylesheet is supposed to generate 
can then process that list appropriately for their local environment. 
However, we simply do not have enough information to make that 
decision in advance. We do not know what will and will not be in the 
list. XSLT transforms can and do produce  document fragments and 
nothing at all. Right now we're simply punting on those cases. The 
current design of JDOMResult is not compatible with XSLT.

| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
|          XML in a  Nutshell, 2nd Edition (O'Reilly, 2002)          |
|              http://www.cafeconleche.org/books/xian2/              |
|  http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/  |
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |

More information about the jdom-interest mailing list