Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

xsl to format xml news

Dear all,
Could you please help to write xsl to format news feed from http://www.itp.net/arabic/rss/?tid=2


thanks
0
ethar1
Asked:
ethar1
  • 3
  • 2
1 Solution
 
Geert BormansCommented:
If you looking for hiring a developer to do this, contact me through the information found on my profile page

If you want a solution from this forum. At least let us now what you mean by formatting.
Do you need to make HTML from these pages?

Then this could be a first step

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:atom="http://www.w3.org/2005/Atom"
    version="1.0">
    
    <xsl:template match="/rss">
        <html>
            <head/>
            <body>
                <xsl:apply-templates select="channel"/>
            </body>
        </html>
    </xsl:template>
    
    <xsl:template match="channel">
        <h1><a href="{link}"><xsl:value-of select="title"/></a></h1>
        <xsl:apply-templates select="item"/>
    </xsl:template>
    
    <xsl:template match="item">
        <h3><a href="{link}"><xsl:value-of select="title"/></a></h3>
        <p><xsl:value-of select="pubDate"/></p>
        <p><xsl:apply-templates select="description"/></p>
        <xsl:if test="enclosure[contains(@type, 'image')]">
            <img src="{enclosure/url}"/>
        </xsl:if>
    </xsl:template>
    
    <xsl:template match="description">
        <xsl:value-of select="." disable-output-escaping="yes"/>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0
 
ethar1Author Commented:
excellent , this is exactly what I need...
Just could you please tell me how to select top 5 items (news ) only?
0
 
Geert BormansCommented:
if you change line 17
<xsl:apply-templates select="item"/>

into

<xsl:apply-templates select="item[position() &lt;= 5]"/>

you will get the top 5 only
0
 
ethar1Author Commented:
Thanks you very much...

How can remove any html tag from the description element?
I add another question for you ...
Please response.
http://www.experts-exchange.com/Hardware/Components/Q_28142256.html
0
 
Geert BormansCommented:
welcome
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now