Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

e.g. of dynamically creating XML and translating with XSL

Posted on 2002-03-26
4
Medium Priority
?
170 Views
Last Modified: 2013-11-23
Hi,

In a servlet I currently create an XML file, translate it using XSL and output the result back to the browser.

Rather than create a physical file I want to just stream it.

I need an example of doing this to use as a guide for my app.  I am using JAXP, so please also do this for your example.

Thanks,

Matt
0
Comment
Question by:MatthewL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
userquin earned 600 total points
ID: 6899680
Hi:

This example works fine using XALAN 2.2 instead JAXP:

Transformer transformer =
       TransformerFactory.newInstance().newTransformer(
         new SAXSource(XMLReaderFactory.createXMLReader(), new InputSource(new ByteArrayInputStream(xsl_data))));
     transformer.transform(
       new SAXSource(XMLReaderFactory.createXMLReader(), new InputSource(new ByteArrayInputStream(xml_data))),
       new StreamResult(out));

You can create your XML on the fly, use getBytes method from it string format.

"out" can be a ByteArrayOutputStream. Then put content-type to your JSP via response.setContentType and then write out.getBytes() to the user.

Bye.

J.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7923687
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ'd and pts removed
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 
LVL 1

Author Comment

by:MatthewL
ID: 7925924
Hi,

I had left it open, hoping that an answer with the JAXP parser would come.  I do appreciate userguin's answer though so points should go there.

Thanks,

Matt
0
 
LVL 2

Expert Comment

by:userquin
ID: 7942687
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question