在验证XML数据库时,我想到了以下想法:我应该用Google过滤所有单词。那些点击量少于100次的词在某种程度上是可疑的。
但是,如何使用 XSLT 实现此目的呢?我成功地隔离了每一个字。但是我怎样才能获得这些单词中每个单词的谷歌点击次数呢?我绝对不知道,https://developers.google.com/根本没有帮助。
(我们谈论的是大约4000字。我不认为谷歌服务器会因为4000个请求而崩溃。
从理论上讲,如果您能找到一种方法以XML格式从Google获取点击次数,则可以基于这种想法进行转换(而不是验证)。它只需要有趣地使用 document()
函数。
假设我有一个XML文档,并且只想输出某些具有超过1000次谷歌点击的元素。我们将假设我们要根据文档中的<term>
元素进行限制,并从身份转换开始。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Interesting code starts here: -->
<xsl:template match="term">
<!-- you need to find out what this is -->
<xsl:variable name="google" select="'www.google.com/funkyXMLAPI?search='"/>
<xsl:variable name="term" select="."/>
<xsl:variable name="uri" select="concat($goog,$term)"/>
<!-- Again, you'll need to findout what the path to the number of hits is -->
<xsl:variable name="hits" select="document($uri)//path/to/numberOfHits"/>
<!-- If there are more than 1000 hits, then copy it across -->
<xsl:if test="$hits > 1000">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
同样,这一切都是基于存在一个以可预测的XML格式返回信息的Google搜索API的想法。