Google Search Appliance XSLT header modification - google-search-appliance

I want to modify the XSLT in order to change home page header of the Google Search Appliance. I am unable to see my changes. I have done the following
included proxyreload=1 query parameter
Changed the home_page_header template to include my Hello world section.
<xsl:template name="home_page_header">
<input type="hidden" name="security_token" id="token">
<xsl:attribute name="value">
<xsl:value-of select="/GSP/SECURITY_TOKEN"/>
</xsl:attribute>
</input>
<table border="0" cellpadding="0" cellspacing="0">
<xsl:if test="$show_logo != '0'">
<tr>
<td rowspan="3" valign="top">
<xsl:call-template name="logo"/>
<xsl:call-template name="nbsp3"/>
</td>
</tr>
</xsl:if>
<xsl:if test="$show_top_search_box != '0'">
<tr>
<td valign="middle">
<xsl:call-template name="search_box">
<xsl:with-param name="type" select="'home'"/>
</xsl:call-template>
</td>
</tr>
</xsl:if>
</table>
<table>
<tr>
<td>Hello World</td>
</tr>
</table>
</xsl:template>
Any thoughts ?

Related

Sorting using xsl:sort

I have XML file (some service documentation) looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<apis>
<api min="" max="">
<resource name="C">
<description>C from beggining to the end</description>
</resource>
</api>
<api min="2.2" max="">
<resource name="B">
<description>B from 2.2 to the end</description>
</resource>
<resource name="A">
<description>A from 2.2 to the end</description>
</resource>
</api>
</apis>
And XSL file to transform XML into html:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="api-version" select="2.2"></xsl:param>
<xsl:template match="apis">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table border="1">
<th colspan="2">
<xsl:text>Doc for API: </xsl:text>
<xsl:value-of select="$api-version"/>
</th>
<xsl:call-template name="handleApis"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template name="handleApis">
<xsl:for-each select="api[(#min='' or #min<=$api-version) and (#max='' or #max>$api-version)]">
<xsl:for-each select="resource">
<xsl:call-template name="handleResource"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template name="handleResource">
<tr>
<td>
<xsl:value-of select="#name"/>
</td>
<td>
<xsl:value-of select="description"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
And now I want to sort results by resource atribute name.
I have tried to put
<xsl:sort select="#name" order="ascending"/>
inside for-each for resource nodes but like You know it won't sort resources between different api nodes and results is
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table border="1">
<th colspan="2">Doc for API: 2.2</th>
<tr>
<td>C</td>
<td>C from beggining to the end</td>
</tr>
<tr>
<td>A</td>
<td>A from 2.2 to the end</td>
</tr>
<tr>
<td>B</td>
<td>B from 2.2 to the end</td>
</tr>
</table>
</body>
</html>
Adding
<xsl:sort select="resource/#name" order="ascending"/>
inside for-each for api nodes also can't work because sort need only one item in select atrribute.
There is some way do sort this to get order A, B, C in output?
How about simply:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="api-version" select="2.2"/>
<xsl:template match="/apis">
<html>
<head/>
<body>
<table border="1">
<th colspan="2">
<xsl:text>Doc for API: </xsl:text>
<xsl:value-of select="$api-version"/>
</th>
<xsl:apply-templates select="api[(#min='' or #min <= $api-version) and (#max='' or #max > $api-version)]/resource">
<xsl:sort select="#name"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="resource">
<tr>
<td>
<xsl:value-of select="#name"/>
</td>
<td>
<xsl:value-of select="description"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>

Internal Onebox show more than 3 content

I am trying to show content more than 3 for internal provider for onebox on GSA 7.4 version. By default it shows up 3 only. There is a setting "Maximum number of OneBox results per search" is a not working. Is there any other way or may be by editing xml or xslt to show more than 3 content?
Any suggestion would be greatly appreciated!!
Thanks in Advance!!
Enclsoed please find my code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="projects">
<xsl:variable name="URLReplace">
<xsl:value-of select="replace(title/urlLink,'search','GSASearchResults.aspx')"/>
</xsl:variable>
<table border="0" cellpadding="1" cellspacing="0">
<tbody>
<tr>
<td valign="top" width="99%">
<xsl:for-each select="MODULE_RESULT">
<font size="-1">
<a>
<xsl:attribute name="href">
<xsl:value-of select="U"/>
</xsl:attribute>
<xsl:value-of select="Title"/>
</a>
</font>
<br/>
</xsl:for-each>
</td>
</tr>
<tr>
<td colspan="2">
<nobr>
<a>
<xsl:attribute name="href">
<!--<xsl:value-of select="title/urlLink"/>-->
<xsl:value-of select="$URLReplace"/>
<!--<xsl:value-of select="concat('GSASearchResults.aspx',substring-after(//title/urlLink,'search'))"></xsl:value-of>-->
</xsl:attribute>
<b>
<!--<xsl:value-of select="title/urlText"/>-->
<xsl:value-of select="/GSP/PARAM[#name='q']/#original_value"/>
Click for More.. <!--<xsl:value-of select="$qurl"/>-->
</b>
</a>
</nobr>
</td>
</tr>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>

XSL Picture in table

I do read the relevant posts, but my code is still not working. I just want to add a avatar (png) to the players in my table.
My HTML:
<root version="2.0">
<game>
<players>
<nickname>thebeast</nickname>
<avatar><img src="/img/thebeast.png" height="30" width="30"></img></avatar>
<sum>220</sum>
</players>
<players>
<nickname>snowman</nickname>
<avatar><img src="/img/snowman.png" height="30" width="30"></img</avatar>
<sum>360</sum>
</players>
</game>
</root>
My table in xsl:
<table align = "center" border="transparent">
<tr><th>Nr.</th><th>Nickname</th><th>Collected <br/>Points</th></tr>
<xsl:for-each select = "//players">
<xsl:sort select = "sum" data-type="number" order="descending"/>
<tr>
<td><xsl:number value = "position()" format = "1."/></td>
<td><xsl:value-of select = "nickname"/></td>
<td><xsl:value-of select = "sum"/></td>
<td>
<img>
<xsl:attribute name="src">
<xsl:value-of select="/img" />
</xsl:attribute>
</img>
</td>
</tr>
</xsl:for-each>
</table>
Instead of:
<img>
<xsl:attribute name="src">
<xsl:value-of select="/img" />
</xsl:attribute>
</img>
try:
<img>
<xsl:attribute name="src">
<xsl:value-of select="avatar/img/#src" />
</xsl:attribute>
</img>
or, in short:
<img src="{avatar/img/#src}"></img>
Or, if you want to preserve the dimensions:
<xsl:copy-of select="avatar/img"/>

XSL sort by title

I don't see the solution and hope someone can help me. I want to sort the result by title. But I don't know where and how to put the sort into the XSL file.
Can somebody help me?
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="TotalResults" />
<xsl:template match="NumberOfResults" />
<xsl:template name="DisplayString">
<xsl:param name="str" />
<xsl:if test='string-length($str) > 0'>
<xsl:value-of select="$str" />
</xsl:if>
</xsl:template>
<xsl:template name="HitHighlighting">
<xsl:param name="hh" />
<xsl:apply-templates select="$hh"/>
</xsl:template>
<xsl:template name="ResultPreviewToolTip">
<xsl:param name="contentclass" />
<xsl:param name="picturethumbnailurl" />
<xsl:param name="url" />
<xsl:param name="title" />
<xsl:param name="hithighlightedsummary" />
<xsl:param name="description" />
<xsl:param name="version" />
<xsl:choose>
<xsl:when test="$contentclass[. = 'STS_ListItem_PictureLibrary'] and $picturethumbnailurl[. != '']">
<div>
<a href="{$url}" title="{$title}">
<img src="{$picturethumbnailurl}" alt="" />
</a>
</div>
</xsl:when>
<xsl:when test="contains( $url, 'jpg' ) or contains( $url, 'jpeg' ) or contains( $url, 'gif' ) or contains( $url, 'JPG' ) or contains( $url, 'JPEG' ) or contains( $url, 'GIF' )">
<div>
<img src="/_layouts/AssetUploader.aspx?Size=Medium&ImageUrl={$url}" alt="" />
</div>
</xsl:when>
<xsl:otherwise>
<div>
<xsl:choose>
<xsl:when test="$hithighlightedsummary[. != '']">
<b>Preview:</b>
<br/>
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="$hithighlightedsummary" />
</xsl:call-template>
</xsl:when>
<xsl:when test="$description[. != '']">
<b>Preview:</b>
<br/>
<xsl:value-of select="$description"/>
</xsl:when>
<xsl:otherwise>
No preview available
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="DisplayString">
<xsl:with-param name="str" select="$version" />
<xsl:with-param name="text" select="'Version: '" />
<xsl:with-param name="stringcolor" select="'#808080'" />
</xsl:call-template>
</div >
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="Result">
<xsl:variable name="tdClass">
<xsl:if test="(position() mod 2 = 0)">
<xsl:value-of select="'even'" />
</xsl:if>
<xsl:if test="(position() mod 2 = 1)">
<xsl:value-of select="'odd'" />
</xsl:if>
</xsl:variable>
<tr>
<td class="{$tdClass}">
<a href="#" class="tooltip">
<img>
<xsl:attribute name="src">
<xsl:value-of select="imageurl"/>
</xsl:attribute>
</img>
<span>
<xsl:call-template name="ResultPreviewToolTip">
<xsl:with-param name="contentclass" select="contentclass" />
<xsl:with-param name="description" select="description" />
<xsl:with-param name="hithighlightedsummary" select="hithighlightedsummary" />
<xsl:with-param name="picturethumbnailurl" select="picturethumbnailurl" />
<xsl:with-param name="title" select="title" />
<xsl:with-param name="url" select="url" />
<xsl:with-param name="version" select="version" />
</xsl:call-template>
</span>
</a>
</td>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="url" disable-output-escaping="yes" />
</xsl:attribute>
<xsl:value-of select="filename"/>
</a>
</td>
<td class="{$tdClass}">
<a>
<xsl:attribute name="href">
<xsl:value-of select="url" disable-output-escaping="yes" />
</xsl:attribute>
<xsl:choose>
<xsl:when test="doctitle != ''">
<xsl:value-of select="doctitle"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="title"/>
</xsl:otherwise>
</xsl:choose>
</a>
</td>
<td class="{$tdClass}">
<xsl:choose>
<xsl:when test="docauthor != ''">
<xsl:value-of select="docauthor"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="author"/>
</xsl:otherwise>
</xsl:choose>
</td>
<td class="{$tdClass}">
<xsl:value-of select="revisiondate" />
</td>
<td class="{$tdClass}">
<xsl:value-of select="doclanguage"/>
</td>
<td class="{$tdClass}">
<a>
<xsl:attribute name="href">
<xsl:value-of select="sitename" disable-output-escaping="yes" />
</xsl:attribute>
<img src="/_layouts/images/breadcrumbbutton.png" style="border-style: none" />
</a>
<xsl:call-template name="ShowVersionHistory" />
</td>
</tr>
</xsl:template>
<xsl:template name="ShowVersionHistory">
<!-- First, encode Url -->
<xsl:variable name="EncodedUrl">
<xsl:value-of disable-output-escaping="yes" select="ddwrt:UrlEncode(url)" />
</xsl:variable>
<!-- does only work for office docuemnts -->
<xsl:if test="string-length(serverredirectedurl) > 0">
<!-- get web url from office web app link -->
<xsl:variable name="WebUrl">
<xsl:value-of select="substring-before(serverredirectedurl, '_layouts')"/>
</xsl:variable>
<!-- create link -->
<xsl:variable name="FinalLink">
<xsl:value-of select="$WebUrl"/>
<xsl:text>_layouts/Versions.aspx?FileName=</xsl:text>
<xsl:value-of select="$EncodedUrl"/>
</xsl:variable>
<a href="{$FinalLink}" target="_blank" Title="Version History">
<img src="/_layouts/images/versions.gif" style="border-style: none" />
</a>
</xsl:if>
</xsl:template>
<xsl:template match="/">
<table class="searchresult">
<tr>
<th width="18"></th>
<th>Filename</th>
<th>Title</th>
<th>Author</th>
<th>Revision Date</th>
<th>Language</th>
<th>Actions</th>
</tr>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="TotalResults" />
<xsl:template match="NumberOfResults" />
<xsl:template name="DisplayString">
<xsl:param name="str" />
<xsl:if test='string-length($str) > 0'>
<xsl:value-of select="$str" />
</xsl:if>
</xsl:template>
<xsl:template name="HitHighlighting">
<xsl:param name="hh" />
<xsl:apply-templates select="$hh"/>
</xsl:template>
<xsl:template name="ResultPreviewToolTip">
<xsl:param name="contentclass" />
<xsl:param name="picturethumbnailurl" />
<xsl:param name="url" />
<xsl:param name="title" />
<xsl:param name="hithighlightedsummary" />
<xsl:param name="description" />
<xsl:param name="version" />
<xsl:choose>
<xsl:when test="$contentclass[. = 'STS_ListItem_PictureLibrary'] and $picturethumbnailurl[. != '']">
<div>
<a href="{$url}" title="{$title}">
<img src="{$picturethumbnailurl}" alt="" />
</a>
</div>
</xsl:when>
<xsl:when test="contains( $url, 'jpg' ) or contains( $url, 'jpeg' ) or contains( $url, 'gif' ) or contains( $url, 'JPG' ) or contains( $url, 'JPEG' ) or contains( $url, 'GIF' )">
<div>
<img src="/_layouts/AssetUploader.aspx?Size=Medium&ImageUrl={$url}" alt="" />
</div>
</xsl:when>
<xsl:otherwise>
<div>
<xsl:choose>
<xsl:when test="$hithighlightedsummary[. != '']">
<b>Preview:</b>
<br/>
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="$hithighlightedsummary" />
</xsl:call-template>
</xsl:when>
<xsl:when test="$description[. != '']">
<b>Preview:</b>
<br/>
<xsl:value-of select="$description"/>
</xsl:when>
<xsl:otherwise>
No preview available
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="DisplayString">
<xsl:with-param name="str" select="$version" />
<xsl:with-param name="text" select="'Version: '" />
<xsl:with-param name="stringcolor" select="'#808080'" />
</xsl:call-template>
</div >
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="Result">
<xsl:variable name="tdClass">
<xsl:if test="(position() mod 2 = 0)">
<xsl:value-of select="'even'" />
</xsl:if>
<xsl:if test="(position() mod 2 = 1)">
<xsl:value-of select="'odd'" />
</xsl:if>
</xsl:variable>
<tr>
<td class="{$tdClass}">
<a href="#" class="tooltip">
<img>
<xsl:attribute name="src">
<xsl:value-of select="imageurl"/>
</xsl:attribute>
</img>
<span>
<xsl:call-template name="ResultPreviewToolTip">
<xsl:with-param name="contentclass" select="contentclass" />
<xsl:with-param name="description" select="description" />
<xsl:with-param name="hithighlightedsummary" select="hithighlightedsummary" />
<xsl:with-param name="picturethumbnailurl" select="picturethumbnailurl" />
<xsl:with-param name="title" select="title" />
<xsl:with-param name="url" select="url" />
<xsl:with-param name="version" select="version" />
</xsl:call-template>
</span>
</a>
</td>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="url" disable-output-escaping="yes" />
</xsl:attribute>
<xsl:value-of select="filename"/>
</a>
</td>
<td class="{$tdClass}">
<a>
<xsl:attribute name="href">
<xsl:value-of select="url" disable-output-escaping="yes" />
</xsl:attribute>
<xsl:choose>
<xsl:when test="doctitle != ''">
<xsl:value-of select="doctitle"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="title"/>
</xsl:otherwise>
</xsl:choose>
</a>
</td>
<td class="{$tdClass}">
<xsl:choose>
<xsl:when test="docauthor != ''">
<xsl:value-of select="docauthor"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="author"/>
</xsl:otherwise>
</xsl:choose>
</td>
<td class="{$tdClass}">
<xsl:value-of select="revisiondate" />
</td>
<td class="{$tdClass}">
<xsl:value-of select="doclanguage"/>
</td>
<td class="{$tdClass}">
<a>
<xsl:attribute name="href">
<xsl:value-of select="sitename" disable-output-escaping="yes" />
</xsl:attribute>
<img src="/_layouts/images/breadcrumbbutton.png" style="border-style: none" />
</a>
<xsl:call-template name="ShowVersionHistory" />
</td>
</tr>
</xsl:template>
<xsl:template name="ShowVersionHistory">
<!-- First, encode Url -->
<xsl:variable name="EncodedUrl">
<xsl:value-of disable-output-escaping="yes" select="ddwrt:UrlEncode(url)" />
</xsl:variable>
<!-- does only work for office docuemnts -->
<xsl:if test="string-length(serverredirectedurl) > 0">
<!-- get web url from office web app link -->
<xsl:variable name="WebUrl">
<xsl:value-of select="substring-before(serverredirectedurl, '_layouts')"/>
</xsl:variable>
<!-- create link -->
<xsl:variable name="FinalLink">
<xsl:value-of select="$WebUrl"/>
<xsl:text>_layouts/Versions.aspx?FileName=</xsl:text>
<xsl:value-of select="$EncodedUrl"/>
</xsl:variable>
<a href="{$FinalLink}" target="_blank" Title="Version History">
<img src="/_layouts/images/versions.gif" style="border-style: none" />
</a>
</xsl:if>
</xsl:template>
<xsl:template match="/">
<table class="searchresult">
<tr>
<th width="18"></th>
<th>Filename</th>
<th>Title</th>
<th>Author</th>
<th>Revision Date</th>
<th>Language</th>
<th>Actions</th>
</tr>
<xsl:apply-templates />
</table>
</xsl:template>
</xsl:stylesheet>
You have to add <xsl:sort> (see: w3schools: xsl:sort Element).
It should be added to your xsl:apply-templates element (or if you would use xsl:for-each, then there).

How to make data remain after success validation?

I have jsp using struts bean tag library:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
</head>
<body>
<p><a class="colorGrey" href="Welcome.do">
<bean:message key="menu.label" />
</a> >><bean:message key="menu.link.addnews" /> </p>
<p><br>
</p>
<html:form action="/NewsSave">
<table width="100%" border="0">
<tr>
<td class="colorGrey" width="164" height="35">
<bean:message key="body.news.title" /> </td>
<td width="577">
<html:text property="newsTitle" size="40" value=""/> </td>
</tr>
<tr>
<td colspan="2">
<html:errors property="newstitle" />
</td>
</tr>
<tr>
<td class="colorGrey">
<bean:message key="body.news.date" /> </td>
<td>
<html:text property="newsDate" size="10" value=""/> </td>
</tr>
<tr>
<td height="21" colspan="2" valign="top">
<html:errors property="newsdate" />
</td>
</tr>
<tr>
<td class="colorGrey" height="61" valign="top">
<bean:message key="body.news.brief" /> </td>
<td valign="top">
<html:textarea property="brief" cols="40" rows="6" value=""/>
</td>
</tr>
<tr>
<td height="23" colspan="2" valign="top"><html:errors property="brief" /></td>
</tr>
<tr>
<td class="colorGrey" height="100" valign="top">
<bean:message key="body.news.content" />
</td>
<td valign="top">
<html:textarea property="content" cols="40" rows="12" value=""/>
</td>
</tr>
<tr>
<td height="23" colspan="2" valign="top">
<html:errors property="content" />
</td>
</tr>
</table>
<html:submit value="SAVE"/>
</html:form>
<form method="POST"
action="Link.do?method=newsList"
onsubmit="return confirm('<bean:message key="body.onsubmit.cancel" />')">
<input type="submit" value="CANCEL">
</form>
And I use validator plugin, which means that after receiving incorrect info it gives message bellow text field telling what's wrong. But problem is that everything disappear after submiting. So it no info in text or text-areatags. I know that it happens because of value="". But I have another page with the same fields for adding info, which should be clear from the beginning. And if I remove value="", the info from this fields will be displayed on that page after forwarding. So
What should I do to clear info from forms after forwarding to
another page?
How to make info remain after success validation?
As you mentioned, you should remove value="" as this is setting the fields to empty. If you want to clear the values then you should do this in the Action class in which your Form bean is populated.
If you are finding that your Form beans are retaining their values between requests then check that they are request scope: the scope attribute of the action element should be "request" in struts.config

Resources