Solved

help with tutorial

Posted on 2004-03-24
7
267 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 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Facing this issue for maven proxy setting 2 39
Tagging and Merging on Branch 1 66
ArrayList Adding/settign data 3 33
Java array 10 84
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

734 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