Listing 1 The main search template
<xsl:template name="showSearch">
<xsl:variable name="work" select=
"document(concat($filesDirectory,'/',$xmlfile))"/>
<xsl:if test="$searchString!=''">
<span class="normtext"><b>
Found <xsl:value-of select="count($work/book/descendant::
*[contains(translate(text(),$ucletters,$lcletters),
translate($searchString,$ucletters,$lcletters)) and
name()=$searchType])"/> page matches for <i>'
<xsl:value-of select="$searchString"/>'</i><br/></b></span>
<xsl:apply-templates select="$work/book/descendant::*
[contains(translate(normalize-space(text()),$ucletters,
$lcletters),translate($searchString,$ucletters,
$lcletters)) and name()=$searchType]" mode="search"/>
</xsl:if>
</xsl:template>
Listing 2 Templates for displaying the results
<xsl:template match="para" mode="search">
<xsl:variable name="StringReplaced">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="text()"/>
</xsl:call-template>
</xsl:variable>
<p class="normtext">
<xsl:apply-templates select="child::*" mode="search"/>
<xsl:value-of select="$StringReplaced"
disable-output-escaping="yes"/> <BR/>
<xsl:if test="$topic=''">
(page: <a href="index.jsp?page={../@id}&ch=
{../../@id}"><xsl:value-of select="../@label"/></a>)
</xsl:if>
</p>
</xsl:template>
<xsl:template match="TITLE" mode="search">
<xsl:variable name="StringReplaced">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:variable>
<i><xsl:value-of select="$StringReplaced"
disable-output-escaping="yes"/></i> (Book) /
<xsl:apply-templates select="../AUTHOR"/>
<br/>
</xsl:template>
<xsl:template match="AUTHOR" mode="search">
<xsl:value-of select="."/> (Author)
</xsl:template>
Listing 3 Accepting parameters
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"
<xsl:param name="filesDirectory"></xsl:param>
<xsl:param name="xmlfile">test2.xml</xsl:param>
<xsl:param name="searchString"/>
<xsl:param name="searchType">para</xsl:param>
<!-- load the document, use with param to call
showSearch template -->
<xsl:template match="/">
<xsl:call-template name="showSearch"/>
</xsl:template>
</xsl:stylesheet>
Listing 4 XSL variable declarations / match the root
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" xmlns=
"http://www.w3.org/TR/REC-html40" version="1.0">
<xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz
</xsl:variable>
<xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ
</xsl:variable>
<xsl:variable name="myNewString"><xsl:value-of select="concat
('<font class=foundText ><b>' , $searchString ,
'</b></font>')"/></xsl:variable>
Listing 5 XSL replace-string template
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before
($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text"
select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select=
"$searchString"/>
<xsl:with-param name="with" select=
"$myNewString"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>