Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

help with tutorial

Posted on 2004-03-24
7
Medium Priority
?
280 Views
Last Modified: 2010-03-31
Hi experts, ive been trying to use the tutorial below, im new to the topics in the tutorial below except java, all I need is to get the code in the link below running, i.e where to put what. Any help would be appreciated, thanks

http://javaalmanac.com/egs/javax.xml.transform/BasicXsl.html
0
Comment
Question by:Ronayne
[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
7 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 10669814
You just need to use that class and call its method:

BasicXsl.xsl(inFilename, outFilename, xslFilename);

Later on, you can make those file output streams into other kinds of streams (web-related ones for instance) but get that working first
0
 

Author Comment

by:Ronayne
ID: 10670245

but where do I call the method?, from a jsp file?, how do I reference it
0
 
LVL 3

Expert Comment

by:eicheled
ID: 10671132
Just build a simple class with a Main and place the call (as described by CEHJ) in there would probably be the easiest.

Alternatively, take that sample code and add a Main to it, and call it from there.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 10672856
Going on your earlier questions, you need to be calling it from a servlet as a bean. Change the streams into the appropriate ones for a web response and appropriate to getting the xsl as a stream server-side. As mentioned, getting working as an app first will help you with the stream logic.
0
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 10674155
Change the code as below, and call it from your jsp using:

<%
   BasicXsl.xsl("my.xml", out, "my.xsl")
%>


    import java.io.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
   
    public class BasicXsl {
        // This method applies the xslFilename to inFilename and writes
        // the output to outFilename.
        public static void xsl(String inFilename, Writer out, String xslFilename) {
            try {
                // Create transformer factory
                TransformerFactory factory = TransformerFactory.newInstance();
   
                // Use the factory to create a template containing the xsl file
                Templates template = factory.newTemplates(new StreamSource(
                    new FileInputStream(xslFilename)));
   
                // Use the template to create a transformer
                Transformer xformer = template.newTransformer();
   
                // Prepare the input and output files
                Source source = new StreamSource(new FileInputStream(inFilename));
                Result result = new StreamResult(out);
   
                // Apply the xsl file to the source file and write the result to the output file
                xformer.transform(source, result);
            } catch (FileNotFoundException e) {
            } catch (TransformerConfigurationException e) {
                // An error occurred in the XSL file
            } catch (TransformerException e) {
                // An error occurred while applying the XSL file
                // Get location of error in input file
                SourceLocator locator = e.getLocator();
                int col = locator.getColumnNumber();
                int line = locator.getLineNumber();
                String publicId = locator.getPublicId();
                String systemId = locator.getSystemId();
            }
        }
    }
0
 
LVL 92

Expert Comment

by:objects
ID: 10691143
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10695457
8-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

618 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