Apply XSL to XML (Java)

I have my XML in a StringBuffer variable.
Example,
StringBuffer sb = new StringBuffer();
sb = sb.append("<node1><node2><node2><node3></node3></node1>") ;

This application is deployed on Tomcat. Inside the web application, I have my XSl.
Can someone please let me know how can I apply this XSL to the above xml, so that I get the HTML result in a variable (which I'll send to the JSP to be displayed)
angela_smithAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pellepCommented:
Try this and play around with it.
StringBuffer sb = new StringBuffer();
sb = sb.append("<node1><node2><node2><node3></node3></node1>") ;
String xslt = ""; // ADD YOUR XSLT;
StreamSource xmlSource = new StreamSource(new StringReader(sb.toString()));
StreamSource xsltSource = new StreamSource(new StringReader(xslt));
 
StringWriter swResult = new StringWriter();
StreamResult result = new StreamResult(swResult);
 
 
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
 
Document domDoc = builder.parse(new InputSource(new StringReader(sb.toString()));
 
Transformer t = TransformerFactory.newInstance().newTransformer(xsltSource);
 
t.transform(xmlSource, result);
String html = swResult.toString();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
angela_smithAuthor Commented:
Thank you

>>String xslt = ""; // ADD YOUR XSLT;

I have path to my XSLT which is on the Server. How do I get it's contents into this variable?
0
CEHJCommented:
Try
StreamSource xsltSource = new StreamSource(new FileReader(xslt)); // 'xslt' is the path to your xsl file

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.