xsl-list
[Top] [All Lists]

[xsl] Re: Filtering RSS feed with xsl based on presence of certain words in description

2009-02-04 14:18:43
Hi Michael and Wendell, here's the code I submitted originally. If 
I want to upgrade the xsl code below to xslt 2.0, what changes are 
required, apart from the version number in the second line? And where do I 
insert the part that Michael suggested below?

<xsl:variable name="keywords" as="xs:string*">
    <w>word1</w>
    <w>word2</w>
    <w>word3</w>
</xsl:variable>

<xsl:function name="f:matches-keyword" as="xs:boolean">
    <xsl:param name="in" as="xs:string"/>
    <xsl:sequence select="some $w in $keywords satisfies contains($in, $w)"/>
</xsl:function>

<xsl:template match="item[f:matches-keyword(description)]">
    .. process the item ..
</xsl:template>

<xsl:template match="item">
    .. do nothing ..
</xsl:template>

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html" encoding="ISO-8859-1" />
<xsl:template match="*">
<xsl:for-each select="//item">
<xsl:if test="contains(description, 'word1')
or contains(description, 'word2')
or contains(description, 'word3')
or contains(description, 'word4')
or contains(description, 'word5') <--- plus 20 or more other words -->
<xsl:if test="position()<10">
<p>
<strong><xsl:value-of select="title" /></strong>
<xsl:text disable-output-escaping="yes">&lt;br /&gt;</xsl:text>
<em>
<xsl:variable name="convertdate" select="pubDate" />
<xsl:variable name="pubday" select="substring($convertdate, 6,2)" />
<xsl:value-of select="$pubday" />
<xsl:text>/</xsl:text>
<xsl:variable name="pubmonth" select="substring($convertdate, 9,3)" />
<xsl:choose>
        <xsl:when test="$pubmonth='Jan'">01</xsl:when>
        <xsl:when test="$pubmonth='Feb'">02</xsl:when>
        <xsl:when test="$pubmonth='Mar'">03</xsl:when>
        <xsl:when test="$pubmonth='Apr'">04</xsl:when>
        <xsl:when test="$pubmonth='May'">05</xsl:when>
        <xsl:when test="$pubmonth='Jun'">06</xsl:when>
        <xsl:when test="$pubmonth='Jul'">07</xsl:when>
        <xsl:when test="$pubmonth='Aug'">08</xsl:when>
        <xsl:when test="$pubmonth='Sep'">09</xsl:when>
        <xsl:when test="$pubmonth='Oct'">10</xsl:when>
        <xsl:when test="$pubmonth='Nov'">11</xsl:when>
        <xsl:when test="$pubmonth='Dec'">12</xsl:when>
</xsl:choose>
<xsl:variable name="pubyear" select="substring($convertdate, 13,4)" />
<xsl:text>/</xsl:text>
<xsl:value-of select="$pubyear" />
</em>
<xsl:text disable-output-escaping="yes">&lt;br /&gt;</xsl:text>
<xsl:value-of select="description" disable-output-escaping="yes" />
<xsl:text> .. </xsl:text>
<a>
        <xsl:attribute name="href">
        <xsl:value-of select="link" />
        </xsl:attribute>
        <xsl:attribute name="title">full story</xsl:attribute>
        <xsl:text>full story</xsl:text>
</a>
</p>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


-- 
_______________________________________________
Surf the Web in a faster, safer and easier way:
Download Opera 9 at http://www.opera.com

Powered by Outblaze

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] Re: Filtering RSS feed with xsl based on presence of certain words in description, jo lemen <=