XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 17th, 2004, 04:36 PM
vithal_raja vithal_raja is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 vithal_raja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 40 sec
Reputation Power: 0
Exclamation problem with xslt

hi
i'm using a small java servlet that would take rss feeds(right now 2) as inputs and produce html page when given a xsl file.....

the servlet prgm is something like this

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.net.URL;

import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;

/*
* This sample applies the todo.xsl stylesheet to the
* todo.xml XML document, and returns the transformation
* output (HTML) to the client browser.
*
* IMPORTANT: For this to work, you must place todo.xsl and todo.xml
* in the servlet root directory for documents.
*
*/

public class exp extends HttpServlet {

public void init(ServletConfig config) throws ServletException
{
super.init(config);
}

public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
// Output goes in the response stream.
// The servlet returns HTML.
response.setContentType("text/html");

PrintWriter out = response.getWriter();

try
{
TransformerFactory tFactory = TransformerFactory.newInstance();
// Get the XML input document and the stylesheet.

//Source xmlSource = new StreamSource(new URL("http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml").openStream());
Source xmlSource1 = new StreamSource(new URL("http://www.rediff.com/rss/usrss.xml").openStream());
Source xmlSource2 = new StreamSource(new URL("http://www.rediff.com/rss/newsrss.xml").openStream());
Source xslSource = new StreamSource(new URL("http://www.cs.odu.edu/~vsripada/cs695/classwork/xslt/getrss.xsl").openStream());
Source xslSource1 = new StreamSource(new URL("http://www.cs.odu.edu/~vsripada/cs695/classwork/xslt/getrss1.xsl").openStream());

// Generate the transformer.
Transformer transformer = tFactory.newTransformer(xslSource);
Transformer transformer1 = tFactory.newTransformer(xslSource1);

// Perform the transformation, sending the output to the response.
// transformer.transform(xmlSource, new StreamResult(out));
transformer.transform(xmlSource1, new StreamResult(out));
transformer1.transform(xmlSource2, new StreamResult(out));
}
catch (Exception e)
{
out.write(e.getMessage());
e.printStackTrace(out);
}

// out.println("<html><head></head><body><h1>Test</h1></body></html>");
out.close();
}

}

the prgm is running fine but i want to make some changes in the xsl file .....the xsl file is parsing the rss file and presents user ...the working version of the program is avilable at

URL


the xsl file source is

<!-- getRSS.xsl: retrieve RSS feed(s) and convert to HTML. -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dc="http://purl.org/dc/elements/1.1/" version="1.0">

<xslutput method="html"/>

<xsl:template match="/">
<html><head><title>Today's Headlines</title></head>
<style><xsl:comment>

p { font-size: 8pt;
font-family: arial,helvetica; }

h1 { font-size: 12pt;
font-family: arial,helvetica;
font-weight: bold; }

a:link { color:blue;
font-weight: bold;
text-decoration: none; }

a:visited { font-weight: bold;
color: darkblue;
text-decoration: none; }

</xsl:comment></style>
<body>
<form method='get' action="TempClient">
<input type="text" name="code" size="5"/>
<input type="submit" value="Get Temp"/>
</form>
<xsl:apply-templates/>
</body></html>
</xsl:template>


<xsl:template match="channel">
<xsl:apply-templates select="document(@src)"/>
</xsl:template>


<!-- Named template outputs HTML a element with href link and RSS
description as title to show up in mouseOver message. -->
<xsl:template name="a-element">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:apply-templates select="*[local-name()='link']"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:apply-templates select="*[local-name()='description']"/>
</xsl:attribute>
<xsl:value-of select="*[local-name()='title']"/>
</xsl:element>
</xsl:template>


<!-- Output RSS channel name as HTML a link inside of h1 element. -->
<xsl:template match="*[local-name()='channel']">
<xsl:element name="h1">
<xsl:call-template name="a-element"/>
</xsl:element>
<!-- Following line for RSS .091 -->
<xsl:apply-templates select="*[local-name()='item']"/>
</xsl:template>


<!-- Output RSS item as HTML a link inside of p element. -->
<xsl:template match="*[local-name()='item']">
<xsl:element name="p">
<xsl:call-template name="a-element"/>
<xsl:text> </xsl:text>
<xsl:if test="dc:date"> <!-- Show date if available -->
<xsl:text>( </xsl:text>
<xsl:value-of select="dc:date"/>
<xsl:text>) </xsl:text>
</xsl:if>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

i would like to modify the style sheet so that i can present to user in a tabular or in some good format.....i've problem adding table here in the style sheet .....

anykind of help appreciated.....

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > problem with xslt


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway