Solved

help with tutorial

Posted on 2004-03-24
7
255 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
powerN  challenge 3 47
XML Paring  Error - Premature end of file. 7 56
Problem to start Neon 20 54
github account with ecipse 1 17
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now