This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: How can I filter stoppwords
- To: xsl-list at mulberrytech dot com
- Subject: Re: How can I filter stoppwords
- From: Eric van der Vlist <vdv at dyomedea dot com>
- Date: Mon, 28 Aug 2000 16:33:26 +0200
- References: <F53F34A9BCCAD311BD69080009FA7FDB459BAD@GRAY>
- Reply-To: xsl-list at mulberrytech dot com
If you really want to do it with XSLT ;=) ...
--------------XML-----------
<?xml version='1.0' encoding='ISO-8859-1'?>
<xmlfile>
<book>
<title>The Ants</title>
<id>1234</id>
</book>
<book>
<title>Lifestyle</title>
<id>1235</id>
</book>
<book>
<title>Being a Dog Is a Full-Time Job</title>
<id>1236</id>
</book>
</xmlfile>
--------------/XML-----------
through
--------------XSL-----------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sw="mailto:vdv@dyomedea.com">
<sw:stop>
<word>the</word>
<word>a</word>
<word>is</word>
</sw:stop>
<xsl:template match="/">
<result>
<xsl:apply-templates select="/xmlfile/book/title"/>
</result>
</xsl:template>
<xsl:template match="title">
<before><xsl:value-of select="."/></before>
<after><xsl:call-template name="strip-stop">
<xsl:with-param name="string"
select="concat(translate(normalize-space(),
'AZERTYUIOPQSDFGHJKLMWXCVBN', 'azertyuiopqsdfghjklmwxcvbn'), ' ')"/>
</xsl:call-template></after>
</xsl:template>
<xsl:template name="strip-stop">
<xsl:param name="string"/>
<xsl:variable name="before" select="substring-before($string, ' ')"/>
<xsl:variable name="after" select="substring-after($string, ' ')"/>
<xsl:if
test="count(document('')/xsl:stylesheet/sw:stop[word=$before])=0">
<xsl:value-of select="concat($before, ' ')"/>
</xsl:if>
<xsl:if test="$after!=''">
<xsl:call-template name="strip-stop">
<xsl:with-param name="string" select="$after"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
--------------/XSL-----------
gives
--------------XML-----------
<?xml version="1.0" encoding="utf-8"?>
<result xmlns:sw="mailto:vdv@dyomedea.com">
<before>The Ants</before><after>ants </after>
<before>Lifestyle</before><after>lifestyle </after>
<before>Being a Dog Is a Full-Time Job</before><after>being dog
full-time job </after>
</result>
--------------/XML-----------
Despite the fact that XPath has no 'to lower' function and that you need
to use translate instead, the trick here is the way to access the nodes
of the stylesheet itself though document("")...
Hope this helps.
Eric
"Sellmer-Brüls, Barbara" wrote:
>
> Hi,
>
> I need to filter stopp words from book titles.
>
> Example:
> <xmlfile>
> <book>
> <title>The Ants</title>
> <id>1234</id>
> </book>
> <book>
> <title>Lifestyle</title>
> <id>1235</id>
> </book>
> </xmlfile>
>
> I tried to do it with <xsl:value-of select="substring-after(title,'The')"/>
> I was successfull as regards to "The Ants", but in all cases where there
> exists no stopp word, the substring function returns an empty string.
>
> Does anybody know another way to filter stopp words?
> How do you XSL-create a sort criterion?
> How can I tell the what-so-ever-function that there is not only one stopp
> word, but a list of such words to be stripped from the beginning (!!!) of
> titles.
>
> Thanks a lot.
> Barbara
> ---
> Barbara Sellmer-Bruels
> Klopotek & Partner GmbH - Berlin
> E-Commerce
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
--
------------------------------------------------------------------------
Eric van der Vlist Dyomedea http://dyomedea.com
http://xmlfr.org http://4xt.org http://ducotede.com
------------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list