Link to home
Start Free TrialLog in
Avatar of gdkinney_2
gdkinney_2

asked on

Exception using Java and XSLT to parse XHTML input file

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;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;

public class Transform {

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

        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);
        //xmlSource.setSystemId("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
        Source xsltSource = new StreamSource(xsltFile);

        // the factory pattern supports different XSLT processors
        TransformerFactory transFact =
                TransformerFactory.newInstance();
        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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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:  'com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Connection timed out: connect'
Transformer Exception cause = javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Connection timed out: connect

Please help,
Dave
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Make sure you are connected to the Internet when you try
Avatar of gdkinney_2
gdkinney_2

ASKER

I am connected to the Internet.  I can get to the web from my browser.
Hi,

xml/xslt file,  If it starts with "http://", Xerces will try to open a HTTP connection to retrieve the content.

R.K
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial