For a variety of reasons, I'd really like to be able to show the file name as the result title in our Google Mini's search results, rather than what the default is. I'm able to almost do this by replacing
<!-- *** 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>
with
<span class="l">
<xsl:value-of select="$stripped_url"/>
</span>
What's left required is to:
- Replace the %20's with spaces
- Trim the url so only the end file name is left
- Trim the file extension from the end
How can I accomplish this?
I figured it out. A lot of the code and functions already existed, I just had to know what I was looking for and then massage the results a bit.
Return the file name of the document:
<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>
Replace the %20's with spaces:
<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>
In addition, the file extension can be removed with an extra find/replace variable.
<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>
精彩评论