Skip to Content
0
Former Member
Feb 27, 2004 at 11:48 AM

Error in transforming XML using Java

127 Views

Hi,

I am trying to transform a simple xml file using java.

Following is the code i am using

TransformerFactory factory = TransformerFactory.newInstance();

Transformer transformer = null;

Templates template = null;

StreamSource xmlSource = null;

StreamSource xslSource = null;

StreamResult result = null;

String msg = new String();

boolean support = false;

try {

xmlSource = new StreamSource("c:/abc.xml");

xslSource = new StreamSource("c:/abc.xsl");

File f = new File("c:/log/copy.xml");

result = new StreamResult(f);

template = factory.newTemplates(xmlSource);

transformer = template.newTransformer();

transformer.transform(xmlSource, result);

} catch (Exception ex) {

msg = ex.getMessage();

}

But it returns "Exceptionclass javax.xml.transform.TransformerConfigurationExceptionoccurred

Could not load stylesheet. javax.xml.transform.TransformerException: Unsupported Result object."

XML file i am using is as follows

<?xml version="1.0" encoding="ISO-8859-1"?>

<?xml-stylesheet type="text/xsl" href="c:\abc.xsl"?>

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

XSLT is

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:transform version="1.0"

xmlns: xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<html>

<body>

<h2>My CD Collection</h2>

<table border="1">

<tr bgcolor="#9acd32">

<th align="left">Title</th>

<th align="left">Artist</th>

</tr>

<xsl:for-each select="catalog/cd">

<tr>

<td><xsl:value-of select="title"/></td>

<td><xsl:value-of select="artist"/></td>

</tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

</xsl:transform>

Can anyone tell me what could be the reason of this error.

Thanks,

Komal.