Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing <p></p> tags from rss feed by xsl 1

Status
Not open for further replies.

owen88

Programmer
Apr 24, 2008
5
Hi! Ive spent the last 2 days trying to find this out and cant get anywhere. I am consuming an rss feed on my site. The problem is that the feed has to many <p> tags and id like to remove them all.
the xsl sheet ;

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:eek:utput method="html" indent="yes"/>
<xsl:param name="TITLE"/>
<xsl:strip-space elements="description" />

<xsl:template match="rss">
<!-- Do not show channel image -->
<xsl:for-each select="channel/item">

<xsl:if test="position() &lt; 6">


<strong><a href="{link}" target="_new"><xsl:value-of select="title"/></a></strong>

<!-- only display markup for description if it's present -->
<xsl:value-of select="description" disable-output-escaping="yes"/>



</xsl:if>
</xsl:for-each>
</xsl:template>

<xsl:template match="description">

<xsl:value-of select="."/>


</xsl:template>

</xsl:stylesheet>


please help!!!!!!
 
From what shown, the template matching "description" is never called. And that the line xsl:value-of outputing description node would be understood as concatinating text within it, so p-tags, if any, would play no role, even if p-tag is rendered as html see it. Hence, what posted is not substantialting the problem as I see it.
 
Hi, thank you very much for your quick reply, as you can see from the following link the latest forum posts section on the top right is being rendered with <p> tags between the title and description, i would like to remove these as i dont want any breaks between the title and descriptions. Is there any way i could do this?
 
But any p-tag should have been introduced by the xsl document and the document as sketched in the first post shows no sign of it. They are not there without the intervention of xsl if that's the technology standing in the middle of rss and html.
 
Again, thank you for your reply,

the following is the rss feed file

<?xml version="1.0"?><rss version="2.0"><channel><title>Boats &amp; Yachting</title><link> Website</description><language>en-US</language><copyright>Copyright 2008 by BMA Ltd</copyright><webMaster>admin@bma.com.mt</webMaster><item><title>Re: hsdkfsd sdjfsdfsd fsjdlfsdf fajdlfhsdj</title><description>&lt;p&gt;hgfhfghhfghfdfghfg&lt;/p&gt;</description><link> 22 Apr 2008 14:17:55 GMT</pubDate><guid> sdjfsdfsd fsjdlfsdf fajdlfhsdj</title><description>&lt;p&gt;gfdl;gjfdgdf gdfskl;gsdfg fdgkfdlgnfdg fdgkhnfd&lt;/p&gt;</description><link> 22 Apr 2008 14:15:56 GMT</pubDate><guid>
as you can see there are &lt;p&gt; in the feed which i would like to remove, is this possible. Sorry im new to all of this. Thanks again
 
As p-tags are embedded in the text, you sure have to do more. With xslt 1.0, you need some to use some recurrence in some named template as a kind of function. It replaces a string particle by some other particle. In this case, you replace both &lt;p&gt; and &lt;/p&gt; by empty string. That named template is well-known and everybody takes profits everybody else as long as it is handy. It is not difficult to construct one onself, neither.

With such a replacement, you again need to re-introduce some line break. Herein-below, I use <br />. This is a possible version.
[tt]
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[ignore][/ignore]">
<xsl:eek:utput method="html" indent="yes"/>
<xsl:param name="TITLE"/>
<xsl:strip-space elements="description" />

<xsl:template match="rss">
<!-- Do not show channel image -->
<xsl:for-each select="channel/item">
<xsl:if test="position() &lt; 6">
<strong><a href="{link}" target="_new"><xsl:value-of select="title"/></a></strong>
[blue]<br />[/blue]
<xsl:apply-templates select="description" />
[blue]<br />[/blue]
</xsl:if>
</xsl:for-each>
</xsl:template>

<xsl:template match="description">
<!--
<xsl:value-of select="."/>
-->
<xsl:variable name="s_in" select="." />
<xsl:variable name="s_temp">
<xsl:call-template name="replace-substring">
<xsl:with-param name="value" select="$s_in" />
<xsl:with-param name="from" select="'&lt;/p&gt;'" />
<xsl:with-param name="to" select="''" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="s_out">
<xsl:call-template name="replace-substring">
<xsl:with-param name="value" select="$s_temp" />
<xsl:with-param name="from" select="'&lt;p&gt;'" />
<xsl:with-param name="to" select="''" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$s_out" />
</xsl:template>

<!-- get one replace string template anywhere handy -->
<xsl:template name="replace-substring">
<xsl:param name="value" />
<xsl:param name="from" />
<xsl:param name="to" />
<xsl:choose>
<xsl:when test="contains($value,$from)">
<xsl:value-of select="substring-before($value,$from)" />
<xsl:value-of select="$to" />
<xsl:call-template name="replace-substring">
<xsl:with-param name="value" select="substring-after($value,$from)" />
<xsl:with-param name="from" select="$from" />
<xsl:with-param name="to" select="$to" />
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$value" />
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>
[/tt]
Then you would be about set.
 
Thank you sooooo much, if theres anything i can ever help you with please let me know, im an asp.net 2.0 developer(c#) and also work with dot net nuke. Thank you very mcuh for your time
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top