【问题标题】:How to remove html tags in summary field from the results of GSA?如何从 GSA 的结果中删除摘要字段中的 html 标签?
【发布时间】:2015-01-28 10:24:53
【问题描述】:
使用 JAPI-GSA,我在每个摘要中收到来自结果 GSA 的 html 标记。
作为
"summary": "... Ce tarif n'est pas valable pour les enfants voyageant seuls (UM). Tarif le
plus bas, Autres tarifs, Vol aller : Paris - Kuala Lumpur . ... "
如何从摘要中删除这些标签。
提示:我需要修改 XSLT
【问题讨论】:
标签:
google-search-appliance
【解决方案1】:
GSA 抛出的原始搜索结果是 XML 格式的。在此 XML 输出中,sn-ps 在一定数量的字符之后包含标记。您无法编辑 XML 输出,但就像您暗示的那样,您可以修改 XSLT。
在 XSLT 文件中,添加以下模板:
<!-- **********************************************************************
REMOVE BR LINE-BREAKS FROM SNIPPETS
********************************************************************** -->
<xsl:template name="remove_br">
<xsl:param name="orig_string"/>
<xsl:variable name="removed_br">
<xsl:call-template name="replace_string">
<xsl:with-param name="find"><br></xsl:with-param>
<xsl:with-param name="replace"> </xsl:with-param>
<xsl:with-param name="string" select="$orig_string"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of disable-output-escaping='yes' select="$removed_br"/>
</xsl:template>
此模板查找标签并用空格替换它们。添加此模板后,找到正在创建 sn-p 框的部分并将其替换为以下代码 sn-p:
<!-- *** Snippet Box *** -->
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="s">
<xsl:if test="$show_res_snippet != '0' and string-length(S) and
$only_apps != '1'">
<xsl:variable name="snippet">
<xsl:call-template name="remove_br">
<xsl:with-param name="orig_string" select="S"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="reformat_keyword">
<xsl:with-param name="orig_string" select="$snippet"/>
</xsl:call-template>
</xsl:if>
此代码调用您之前添加的模板并生成一个 sn-p,其中标签被替换为空格。