Skip to Content
author's profile photo Former Member
Former Member

Error in transforming XML using Java

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.

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Feb 27, 2004 at 12:19 PM

    Could you tell me which product you are using and what system this happens in?

    Regards,

    Benny

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.