This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Java code example of transforming via SAX with JAXP 1.1?
- From: AXRAMAKR at UP dot COM
- To: xsl-list at lists dot mulberrytech dot com
- Cc: owner-xsl-list at lists dot mulberrytech dot com, xsl-list at lists dot mulberrytech dot com
- Date: Wed, 19 Jun 2002 13:30:05 -0500
- Subject: Re: [xsl] Java code example of transforming via SAX with JAXP 1.1?
- Reply-to: xsl-list at lists dot mulberrytech dot com
try{
TransformerFactory tFactory =
TransformerFactory.newInstance();
String stylesheet = "test.xsl";
String sourceId = "testXML.xml";
File pricesHTML = new File("pricesHTML.html");
FileOutputStream os = new FileOutputStream(pricesHTML);
Transformer transformer =
tFactory.newTransformer(new StreamSource(stylesheet));
transformer.transform(
new StreamSource(sourceId), new StreamResult(os));
}
catch (Exception e)
{
}
Thanks,
Akila Ramakrishnan
(314) 768 5809
axramakr@up.com
"James Fuller"
<james.fuller@o-idev.com> To: <xsl-list@lists.mulberrytech.com>
Sent by: cc:
owner-xsl-list@lists.mulbe Subject: Re: [xsl] Java code example of transforming via
rrytech.com SAX with JAXP 1.1?
06/19/02 01:14 PM
Please respond to xsl-list
import javax.xml.transform.*;
import javax.xml.transform.sax.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import javax.xml.parsers.*;
public static void transform2result(String strXML, String strXSL, Response
response)
throws TransformerException, TransformerConfigurationException
{
try{
File source = new File(strXML);
File style = new File(strXSL);
TransformerFactory factory = TransformerFactory.newInstance();
// Set the error listener of the factory
PrintErrorListener factoryerror = new PrintErrorListener();
factoryerror.response = response;
Transformer t = factory.newTransformer(new
StreamSource(style));
transformerror.response = response;
t.setErrorListener(transformerror);
t.transform(new StreamSource(source),new
StreamResult(System.out));
}catch(Exception e){
}
}
a bit OT this,
something like this will do, notice I am piping the output to System.out u
can write to a file
also u may need to setup ErrorListeners to handle error processing.
cheers, jim fuller
----- Original Message -----
From: "Richard Bondi" <rbondi@ergito.com>
To: <XSL-List@lists.mulberrytech.com>
Sent: Wednesday, June 19, 2002 6:50 PM
Subject: [xsl] Java code example of transforming via SAX with JAXP 1.1?
> Could someone please send me a java example of how to transform some xml
> that is being parsed via a JAXP 1.1. SAXParser? Just something simple
that
> parses test.xml, transforms it with test.xsl, and outputs it to
System.out
> or to a Result object.
>
>
> FYI: I've tried to figure this out from two O'Reilly Books, "Java & XSLT"
> and "Java & XML". The latter doesn't cover it, and the former only covers
> how to transform by leaving JAXP, i.e. by getting an XMLReader (not to
> mention an inexplicable 7 page digression on how to parse comma-separated
> files that frustratingly occurs in the middle of this).
>
> Please email directly to me as well as to the list.
>
> Many thanks,
> Richard Bondi
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list