Solved

xsl to format xml news

Posted on 2013-05-28
5
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
Arrow Electronics was searching for a KVM  (Keyboard/Video/Mouse) switch that could display on one single monitor the current status of all units being tested on the rack.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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