How to resolve javax.xml.transform.TransformerConfigurationException

I am trying to convert an xml file to html using xsl stylesheets. See code below. I tried many ways to solve the problem, but somehow I can’t. If I open the xml file, I can see the desired result, but why can't I see the same through programming?

Error message: ERROR: "Jaxpone.xsl" FATAL ERROR: "Failed to compile stylesheet" javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet at com.sun.org.apache.xalan.internal.xsltc.trax .TransformerFactoryImpl.newTemplates (TransformerFactoryImpl.java:885) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer (TransformerFactoryImpl.java:671) in crawler.JAXPExamples.basic.basic.basic ) on crawler.JAXPExamples.main (JAXPExamples.java:40)

Please see the code below 

packet scanner;

 import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import org.xml.sax.SAXException; public class JAXPExamples { public static void main(String argv[]) throws TransformerException, TransformerConfigurationException, IOException, SAXException, ParserConfigurationException, FileNotFoundException { try { URL xmlURL = new URL("file://Jaxpone.xml"); String xmlID = xmlURL.toString(); URL xslURL = new URL("file://Jaxpone.xsl"); String xslID = xslURL.toString(); // System.out.println("--- basic ---"); basic(xmlID, xslID); System.out.println(); } catch(Exception err) { err.printStackTrace(); } } public static void basic(String xmlID, String xslID) throws TransformerException, TransformerConfigurationException { TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer transformer = tfactory.newTransformer(new StreamSource(xslID)); StreamSource source = new StreamSource(xmlID); transformer.transform(source, new StreamResult(System.out)); } } 

XSLT File Code

 <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="title"> <h2><b><xsl:value-of select="."/></b></h2><br /> </xsl:template> <xsl:template match="pub_date"> <h5><xsl:value-of select="."/></h5><br /> </xsl:template> <xsl:template match="section"> <p><b><xsl:value-of select="."/></b></p><br /> </xsl:template> <xsl:template match="author"> <p><b><xsl:value-of select="."/></b></p><br /> </xsl:template> <xsl:template match="link"> <p><xsl:value-of select="."/></p><br /> </xsl:template> <xsl:template match="description"> <p><xsl:value-of select="."/></p><br /> </xsl:template> <xsl:template match="body"> <p><xsl:value-of select="."/></p><br /> </xsl:template> <xsl:template match="/"> <html> <body> <xsl:apply-templates/> </body> </html> </xsl:template> </xsl:stylesheet> 
+4
source share
1 answer

A TransformerConfigurationException usually means there is an error in your stylesheet. Actual errors will be sent to your ErrorListener. You did not provide ErrorListener to switch to the default ErrorListener, which is likely to write messages to the console or to some kind of log file.

Try running the stylesheet directly from the command line or from the IDE until you know that the code is correct.

+2
source

Source: https://habr.com/ru/post/1492025/


All Articles