Exception using Java and XSLT to parse XHTML input file

Posted on 2006-05-01
Last Modified: 2013-12-16
I am using the following application:

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;

public class Transform {

     * Performs an XSLT transformation, sending the results
     * to System.out.
    public static void main(String[] args) {
        if (args.length != 3) {
                "Usage: java Transform [xmlfile] [xsltfile]");

        File xmlFile = new File(args[0]);
        File xsltFile = new File(args[1]);
        File xmlDest = new File(args[2]);

        // JAXP reads data using the Source interface
        Source xmlSource = new StreamSource(xmlFile);
        Source xsltSource = new StreamSource(xsltFile);

        // the factory pattern supports different XSLT processors
        TransformerFactory transFact =
        Transformer trans = transFact.newTransformer(xsltSource);
        trans.transform(xmlSource, new StreamResult(xmlDest));
      catch (TransformerException e2) {
           System.out.println("Transformer Exception cause = " + e2);    
      catch (Exception e) {
           System.out.println("Exception ==== " + e);  

to parse an XHTML input file with a DOCTYPE tag as the first tag as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

I call the application from the command line as follows:
java Transform input.xml stylesheet.xsl output.xml

It throws the following exception:
ERROR:  'Connection timed out: connect'
ERROR:  ' Connection timed out: connect'
Transformer Exception cause = javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: Connection timed out: connect

Please help,
Question by:gdkinney_2
    1 Comment
    LVL 60

    Accepted Solution

    Hi Dave,

    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "">

    do you need validation, or is wellformedness checking OK?
    Does the machine you are using for this validation have a clear internet connection?

    The thing is, since the public reference is likely unknown to the parser
    the parser will try to find the system reference,
    which is on the W3C website
    (browsers do it differently, XML parsers will try to catch the DTD)

    now finding the DTD is not an issue, resolving all the referenced DTD modules might be an issue
       "-//W3C//ENTITIES Latin 1 for XHTML//EN"

    If you really need validation,
    I suggest you keep a local copy of the DTD, with all the modules paths set correctly

    Since you just want to do a transform,
    it is likely that you don't need validation
    so you might be better off removing the first two lines (DOCTYPE)

    If you can't remove the DOCTYPE from the file(s) easily,
    try to find a way to switch off validation, I don't know how to do that in a java transform


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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).

    Suggested Solutions

    Title # Comments Views Activity
    Conditional Formatting 4 22
    XML template problem 4 52
    Problem to get function 52 67
    Question to locate the problem 18 26
    When deciding to adopt any help desk solutions many factors should be explored before taking decisions. This will change from business to another but in general there are some kind of rule of thumb. Here are some quick tips: Do we need only ticket…
    Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
    The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Open Page or Post…
    The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now