[jdom-interest] JDOM and XSL
Alessandro Marcellini
amarcell at tiscalinet.it
Tue Feb 6 03:55:38 PST 2001
Hi,
I tested the code with Pipe, but it seems to have some problem when there is a lot
of data to transform. (A blocking situation occur ...)
So I used an Example (DOM2DOM) that comes with Xalan2 and hacked another code that
takes in
input a org.w3c.dom.Document Object (That you can build with org.jdom.DOMOutputter)
and put the output in an OutputStream.
Here is the code ...
I hope this help!
private void transform( org.w3c.dom.Document doc, File xslt, OutputStream out )
throws IOException, javax.xml.transform.TransformerException,
javax.xml.transform.TransformerConfigurationException, Exception
{
TransformerFactory tFactory = TransformerFactory.newInstance();
if(!tFactory.getFeature(DOMSource.FEATURE) ||
!tFactory.getFeature(DOMResult.FEATURE))
throw new Exception("trasform: DOM not supported");
// Process the stylesheet StreamSource and generate a Transformer.
Transformer transformer = tFactory.newTransformer(new StreamSource(xslt));
// Use the DOM Document to define a DOMSource object.
DOMSource domSource = new DOMSource(doc);
// Set the base URI for the DOMSource so any relative URIs it contains can
// be resolved.
domSource.setSystemId("file.xml");
// Create an empty DOMResult for the Result.
DOMResult domResult = new DOMResult();
// Perform the transformation, placing the output in the DOMResult.
transformer.transform(domSource, domResult);
//Instantiate an XML serializer and use it to serialize the output DOM to
System.out
// using a default output format.
Serializer serializer =
SerializerFactory.getSerializer(OutputProperties.getDefaultMethodProperties("xml"));
serializer.setOutputStream(out);
serializer.asDOMSerializer().serialize(domResult.getNode());
}
Marco.Mistroni at nokia.com wrote:
> hi all,
> i have just started playing with JDOM and i have one question:
> has anyone ever used JDOM along with XSL?? or, how can i use it???
> i read in one article at javaworld that jdom 1.0 will feature also XSL...but
> when
> the version 1.0 will be available as far as you know??
>
> thanx in advance and regards
> marco
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
More information about the jdom-interest
mailing list