|
Home > Archive > WebSphere Portal Server > July 2007 > display xml document in a portlet
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
display xml document in a portlet
|
|
|
| Hello,
I have an xml document which I am trying to display in my portlet but it gets displayed as a single long string of all the values included and its not using the xsl included in the xml file. I'm attaching the screenshot of the portlet.
Any help please?
This is how my xml looks:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v2007 (http://www.altova.com) -->
<?xml-stylesheet type="text/xsl" href="cdcatalog.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>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
</catalog>
xsl file is :
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v2007 (http://www.altova.com) -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
<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:stylesheet>
| |
|
|
Java XML transformation works :-)
here is the code snippet:
In the doView method of the portlet class
........................................................................
public void doView(PortletRequest request, PortletResponse response) throws PortletException, IOException {
.....
// Source XML File
StreamSource xmlFile = new StreamSource(new File("xmlpath"));
// Source XSLT Stylesheet
StreamSource xsltFile = new StreamSource(new File("xslpath"));
// result html file path
File resultHTMLFile = new File(path+"resulthtmlpath");
if(resultHTMLFile.exists())
resultHTMLFile.delete();
StreamResult streamResult = new StreamResult(resultHTMLFile);
// Get XML, apply Transformation, save results
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xsltFile);
transformer.transform(xmlFile, streamResult);
getPortletConfig().getContext().include("resulthtmlpath", request, response);
}
........................................................................
|
|
|
|
|