display xml document in a portlet
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > WebSphere > WebSphere Portal Server > display xml document in a portlet




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    display xml document in a portlet  
Natya


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-26-07 06:22 PM

Hello,

I have an xml document which I am trying to display in my portlet but it get
s displayed as a single long string of all the values included and its not u
sing the xsl included in the xml file. I'm attaching the screenshot of the p
ortlet.
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>







[ Post a follow-up to this message ]



    Re: display xml document in a portlet  
Natya


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-27-07 12:21 AM





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

}
.......................................................................






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:06 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register