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

Subject: Re: [xsl] Filtering RSS feed with xsl based on presence of certain words in description
From: ac <ac@xxxxxxxxxxxxx>
Date: Wed, 28 Jan 2009 11:03:45 -0500
Hi,

How about:

<xsl:variable name="keywords" select="('word1', 'word2', 'word3')"/>

<xsl:template match="item[description = $keywords]">
  .. process the item ..
</xsl:template>

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


Cheers, ac


I'm trying to filter an external rss feed using xls so that only those feed items that contain at least one of a list of words are selected. The code below does that, but I'm wondering if there isn't a more succint and easier to maintain way,

XSLT 1.0 isn't known for its succinctness.


In 2.0 I would do:

 <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>

Michael Kay
http://www.saxonica.com/

Current Thread