3

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:

  1. Replace the %20's with spaces
  2. Trim the url so only the end file name is left
  3. Trim the file extension from the end

How can I accomplish this?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Matt Hanson
  • 3,458
  • 7
  • 40
  • 61

2 Answers2

2

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>
Matt Hanson
  • 3,458
  • 7
  • 40
  • 61
0

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>
Mark Bosky
  • 129
  • 7