[jdom-interest] JDOMSource for Element
Laurent Bihanic
laurent.bihanic at atosorigin.com
Mon Mar 26 01:47:16 PST 2001
Hi,
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
transformation happened.
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
doc.setRootElement(null);
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.
Laurent
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
> transformation.
>
> Kesav Kumar
> Software Engineer
> Voquette, Inc.
> 650 356 3740
> mailto:kesavk at voquette.com
> http://www.voquette.com
> Voquette...Delivering Sound Information
>
More information about the jdom-interest
mailing list