我正在尝试在 XSLT 中制作一个词频计数器。我希望它使用停用词。我开始阅读 Michael Kay 的书。但我很难让停用词发挥作用。
此代码适用于任何源 XML 文件。
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="stopwords" select="'a about an are as at be by for from how I in is it of on or that the this to was what when where who will with'"/>
<wordcount>
<xsl:for-each-group group-by="." select="
for $w in //text()/tokenize(., '\W+')[not(.=$stopwords)] return $w">
<word word="{current-grouping-key()}" frequency="{count(current-group())}"/>
</xsl:for-each-group>
</wordcount>
</xsl:template>
</xsl:stylesheet>
我认为这not(.=$stopwords)
是我的问题所在。但我不知道该怎么办。
此外,我将提示如何从外部文件加载停用词。