Topic: xslt problem (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=21427" title="Pages that link to Topic: xslt problem (Page 1 of 1)" rel="nofollow" >Topic: xslt problem <span class="small">(Page 1 of 1)</span>\

 
utaguy
Obsessive-Compulsive (I) Inmate

From:
Insane since: Apr 2004

posted posted 04-18-2004 00:45

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:....../getrss.xsl").openStream());
Source xslSource1 = new StreamSource(new URL("http://..../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 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 .....also can i include java script in the xsl fle.....

anykind of help appreciated.....
vicky



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu