Skip to Content
avatar image
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 comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • 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 comment
    10|10000 characters needed characters exceeded

    • Hi Komal,

      It seems like a classloader problem. Make sure you do not have another xml parser or a jar containing javax.xml.* interfaces inside your EAR file (or with a reference).

      If this is not your case, please create a CSS message

      Best regards,

      Alexander