Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XSL Transform of a Node object

843834May 22 2009 — edited May 25 2009
Does anyone know the best way to cast/convert a Node object properly (can't cast it directly as a SAXSource or DOMSource .. .or even via InputSource) so that you can do an xslTransform on it? In the code below, I'd want the Node cast appropriately where SOURCE is in the transform. That is my input ... a Node object, and I want to apply XSL to it.

TIA!
		String out;

		TransformerFactory tFactory = TransformerFactory.newInstance();
		StreamSource theXSL = new StreamSource(Constants.xslNodeTransform);
		Templates template;
		Transformer xslTrans;
		try {
			template = tFactory.newTemplates(theXSL);
			xslTrans = tFactory.newTransformer(theXSL);
		} catch (TransformerConfigurationException tce) {
                       // handle exception
		}

		ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
		Result res = new StreamResult(byteStream);

		try {
			xslTrans.transform(_SOURCE_ res);
		} catch (TransformerException te) {
			// handle exception
		}
		out = byteStream.toString();
Edited by: java5on on May 22, 2009 12:40 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 22 2009
Added on May 22 2009
4 comments
154 views