2011-03-10 73 views
3

出於各種原因,我真的希望能夠在我們的Google Mini搜索結果中顯示文件名作爲結果標題,而不是缺省設置。我能夠用在Google Search Appliance中更改結果標題

<span class="l"> 
    <xsl:value-of select="$stripped_url"/> 
</span> 

剩下的是什麼需要的是更換

<!-- *** Result Title (including PDF tag and hyperlink) *** --> 
... 
<span class="l"> 
    <xsl:choose> 
     <xsl:when test="T"> 
     <xsl:call-template name="reformat_keyword"> 
      <xsl:with-param name="orig_string" select="T"/> 
     </xsl:call-template> 
     </xsl:when> 
     <xsl:otherwise><xsl:value-of select="$stripped_url"/></xsl:otherwise> 
    </xsl:choose> 
</span> 

幾乎做到這一點:

  1. 用空格替換%20的
  2. 修剪網址,以便僅留下結束文件名
  3. 從末尾修剪文件擴展名

我該如何做到這一點?

回答

2

我想通了。很多代碼和函數已經存在,我只需要知道我在找什麼,然後稍微修改一下結果。

返回文檔的文件名:

<span class="l"> 
    <xsl:variable name="document_title"> 
     <xsl:call-template name="last_substring_after"> 
      <xsl:with-param name="string" select="substring-after(
                $temp_url, 
                '/')"/> 
      <xsl:with-param name="separator" select="'/'"/> 
      <xsl:with-param name="fallback" select="'UNKNOWN'"/> 
     </xsl:call-template> 
    </xsl:variable> 

用空格替換%20的:

<xsl:call-template name="replace_string"> 
     <xsl:with-param name="find" select="'%20'"/> 
     <xsl:with-param name="replace" select="' '"/> 
     <xsl:with-param name="string" select="$document_title"/> 
    </xsl:call-template> 
</span> 
0

此外,文件擴展名可以使用一個額外的查找刪除/替換變量。

<xsl:variable name="document_title_remove_extension"> 
    <xsl:call-template name="replace_string"> 
     <xsl:with-param name="find" select="'.pdf'"/> 
     <xsl:with-param name="replace" select="''"/> 
     <xsl:with-param name="string" select="$document_title"/> 
    </xsl:call-template> 
    </xsl:variable> 
    <xsl:call-template name="replace_string"> 
     <xsl:with-param name="find" select="'%20'"/> 
     <xsl:with-param name="replace" select="' '"/> 
     <xsl:with-param name="string" select="$document_title_remove_extension"/> 
    </xsl:call-template> 
</span> 
相關問題