0

Apologies as i know this question has been asked before but i've tried doing what was said with still no luck. I am getting this error everytime:

java.lang.NullPointerException
at test.XSLTransformer.main(XSLTransformer.java:35)
ERROR:  'Could not compile stylesheet'
FATAL ERROR:  'java.lang.NullPointerException'
           :null
Exception in thread "main" javax.xml.transform.TransformerConfigurationException: java.lang.NullPointerException
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:988)
    at test.XSLTransformer.main(XSLTransformer.java:35)
// ...
import jdk.nashorn.internal.runtime.regexp.JoniRegExp;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;
import java.net.URISyntaxException;
import java.util.Scanner;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
// ...

public class XSLTransformer {

    public static void main(String[] args) throws IOException, URISyntaxException, TransformerException {


            File xmlFile = new File("D:\\FastFlow.IntegrationDb-Data.xml"); // source file
            File  resultFile = new File ("D:\\staffnumbers.xml"); // result file
            File  xslFile = new File ("D:\\CanonicalSectionTmpltTOPMNF.xsl"); // template file


        TransformerFactory factory = TransformerFactory.newInstance(); // this is the line that throws the exception
        Source xslInput = new StreamSource(xslFile);
        Templates xsl = factory.newTemplates(xslInput);

        Transformer transformer = factory.newTransformer(xslInput);

        Source xmlInput = new StreamSource(xmlFile);
        Result result = new StreamResult(resultFile);
        transformer.transform(xmlInput,result);


        System.out.println(result.toString());

    }
} ```

Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
  • `XSLTransformer.java:35` means line 35 – Scary Wombat Feb 13 '20 at 02:14
  • It is not clear how your XSLT code looks but you have tagged the question as XSLT 2.0 while the classes in the stack trace, like `com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl`, suggest you are using the built-in Xalan XSLT 1.0 processor. So perhaps Xalan just can't compile your XSLT code as it is not XSLT 1 but rather XSLT 2, for which in the Java world you would need to use Saxon 9 (or I think in the IBM Websphere world, a package specific to that environment). – Martin Honnen Feb 13 '20 at 07:20

0 Answers0