Solved

help with tutorial

Posted on 2004-03-24
7
269 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

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…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

707 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