[jdom-interest] JDOMSource for Element
laurent.bihanic at atosorigin.com
Mon Mar 26 01:47:16 PST 2001
The problem here is that we need to feed the XSLT processor with an XML document.
Creating the document is not a problem (new Document (elt);) but this modifies
the element itself: It knows it is the root of a document. This would be
acceptable is the JDOMSource could reset the element's state once the
transformation is over but it can't: A TRaX source is not notified when a
The other solution would be to clone the element but that's too expensive.
If you want to apply a transformation onto an element, a simple (but ugly) way
to do is:
// 1. Wrap the element into a document
Document doc = new Document(elt);
// 2. Apply transformation
transformer.transform(new JDOMSource(doc), ...);
// 3. Detach element
Please note that this code may not work in the future: It works with the
current version of JDOM because the method setDocument() in Element does not
care nor check about the parent element. The JavaDoc does not say whether this
is the desired behavior.
Kesav Kumar wrote:
> No.of times it is necessary that we need to apply XSL to a part of the whole
> document. If we modify the JDOMSource to take the Element instead of
> Document we can pass any portion of the Document to apply xsl
> Kesav Kumar
> Software Engineer
> Voquette, Inc.
> 650 356 3740
> mailto:kesavk at voquette.com
> Voquette...Delivering Sound Information
More information about the jdom-interest