Solved

xsl to format xml news

Posted on 2013-05-28
5
302 Views
Last Modified: 2013-05-29
Dear all,
Could you please help to write xsl to format news feed from http://www.itp.net/arabic/rss/?tid=2


thanks
0
Comment
Question by:ethar1
  • 3
  • 2
5 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 39203245
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
 

Author Comment

by:ethar1
ID: 39204238
excellent , this is exactly what I need...
Just could you please tell me how to select top 5 items (news ) only?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39204292
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
 

Author Comment

by:ethar1
ID: 39205874
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39205930
welcome
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now