I'm a novice at XSLT and working on getting a Google Search Appliance setup at my organization. I'm trying to rewrite a URL so it will be displayed properly on the search results. The following script provided from Google's support performs the task perfectly with a single URL in the XSLT stylesheet. When asked if they had an example of how to rewrite multiple URLs they mentioned that custom XLST development is beyond the scope of their support.
Here is what I'm working with:
<!--
**********************************************************************
A single result (do not customize)
**********************************************************************
--> <xsl:template match="R">
Inside this section, look for the definition of the $stripped_url
variable (line 1788):
<xsl:variable name="stripped_url" select="substring-after(U, '://')"/>
As a basic example of how to perform the URL rewrite functionality
which you requested, you might replace this line with the following
code:
<xsl:variable name="rewrite_from"
select="'<xsl:variable name="rewrite_to"
select="'<xsl:variable name="rewritten_url">
<xsl:choose>
<xsl:when test="(substring-before(U, $rewrite_from) = '')
and contains(U, $rewrite_from)">
<xsl:value-of
select="concat($rewrite_to, substring-after(U,
$rewrite_from))"/>
</xsl:when>
<xsl
therwise>
<xsl:value-of select="U"/>
</xsl
therwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="stripped_url"
select="substring-after($rewritten_url, '://')"/>
Also, you would need to replace this code (lines 1832-1834):
<xsl:text disable-output-escaping='yes'><a href="</xsl:text>
<xsl:value-of disable-output-escaping='yes' select="U"/> <xsl:text
disable-output-escaping='yes'>"></xsl:text>
with the following code to use the rewritten URL:
<xsl:text disable-output-escaping='yes'><a href="</xsl:text>
<xsl:value-of disable-output-escaping='yes' select="$rewritten_url"/>
<xsl:text disable-output-escaping='yes'>"></xsl:text> "
Here is what I'm working with:
<!--
**********************************************************************
A single result (do not customize)
**********************************************************************
--> <xsl:template match="R">
Inside this section, look for the definition of the $stripped_url
variable (line 1788):
<xsl:variable name="stripped_url" select="substring-after(U, '://')"/>
As a basic example of how to perform the URL rewrite functionality
which you requested, you might replace this line with the following
code:
<xsl:variable name="rewrite_from"
select="'<xsl:variable name="rewrite_to"
select="'<xsl:variable name="rewritten_url">
<xsl:choose>
<xsl:when test="(substring-before(U, $rewrite_from) = '')
and contains(U, $rewrite_from)">
<xsl:value-of
select="concat($rewrite_to, substring-after(U,
$rewrite_from))"/>
</xsl:when>
<xsl
<xsl:value-of select="U"/>
</xsl
</xsl:choose>
</xsl:variable>
<xsl:variable name="stripped_url"
select="substring-after($rewritten_url, '://')"/>
Also, you would need to replace this code (lines 1832-1834):
<xsl:text disable-output-escaping='yes'><a href="</xsl:text>
<xsl:value-of disable-output-escaping='yes' select="U"/> <xsl:text
disable-output-escaping='yes'>"></xsl:text>
with the following code to use the rewritten URL:
<xsl:text disable-output-escaping='yes'><a href="</xsl:text>
<xsl:value-of disable-output-escaping='yes' select="$rewritten_url"/>
<xsl:text disable-output-escaping='yes'>"></xsl:text> "