Solved

help with tutorial

Posted on 2004-03-24
7
262 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
7 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 25 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 25 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…

825 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