Hi there,
I'd appreciate your input/help on the following:
I am having issues with the example in the Cookbook which refers to transforming
XML via an XSL stylesheet. The code breaks on this line of code:
Transformer transformer = factory.newTransformer(new StreamSource(new
File("H:\\XML\\Stylesheet.xsl")));
At gnu.xml.aelfred2.SAXDriver.getLineNumber(SAXDriver.java:1165)
The follwing is the code as well as the stacktrace which shows a
NullPointerException.
I am also including the stylesheet as well as the source XML document for
your information.
import java.io.File;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import org.dom4j.Document;
import org.dom4j.io.DocumentResult;
import org.dom4j.io.DocumentSource;
/**
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class XMLDocumentTransformer {
public static Document styleDocument(
Document document
) throws Exception {
// load the transformer using JAXP
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(new
File("H:\\XML\\Stylesheet.xsl")));
// now lets style the given document
DocumentSource source = new DocumentSource( document );
DocumentResult result = new DocumentResult();
transformer.transform( source, result );
// return the transformed document
Document transformedDoc = result.getDocument();
return transformedDoc;
}
}
Stack Trace
java.lang.NullPointerException
at gnu.xml.aelfred2.SAXDriver.getLineNumber(SAXDriver.java:1165)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parseTopLevel(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parsePattern(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Template.parseContents(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.parseOwnChildren(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.parseContents(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.createAST(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(Unknown
Source)
at
org.arp.xml.XMLDocumentTransformer.styleDocument(XMLDocumentTransformer.java:35)
at org.arp.xml.FileExporter.writeFile(FileExporter.java:25)
at org.arp.xml.XMLParsingInvoker.invokeParser(XMLParsingInvoker.java:43)
at org.arp.xml.XMLParsingInvoker.main(XMLParsingInvoker.java:25)
Stylesheet
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v4.2 -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Source XML Document
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
dom4j-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-user