public
Created

Manipulate XSLTsearch

  • Download Gist
SearchResults.xslt
XSLT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
exclude-result-prefixes="msxml umbraco.library PS.XSLTsearch">
<xsl:import href="XSLTsearch.xslt"/>
 
<xsl:template match="/" priority="2">
<xsl:variable name="searchResults">
<xsl:call-template name="search">
<xsl:with-param name="items" select="$currentPage/ancestor-or-self::*[@level = 1]"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="results" select="msxml:node-set($searchResults)"/>
 
<xsl:apply-templates select="$results/div" />
 
</xsl:template>
 
<xsl:template match="div[@id = 'xsltsearch']">
<xsl:apply-templates select="p[@id = 'xsltsearch_summary']"/>
<xsl:apply-templates select="div[@class = 'xsltsearch_form']"/>
<xsl:apply-templates select="div[@id = 'xsltsearch_results']"/>
<xsl:apply-templates select="p[@id = 'xsltsearch_navigation']"/>
</xsl:template>
 
<xsl:template match="p[@id = 'xsltsearch_summary']">
<p>
<xsl:text>Your search for </xsl:text>
<strong>
"<xsl:value-of select="strong[1]"/>"
</strong>
<xsl:text> returned </xsl:text>
<strong>
<xsl:value-of select="strong[2]"/>
</strong>
<xsl:text> results.</xsl:text>
</p>
</xsl:template>
 
<xsl:template match="div[@class = 'xsltsearch_form']">
<p>Haven't found what you were looking for?</p>
<form action="{umbraco.library:NiceUrl($currentPage/@id)}" method="get">
<input type="text" name="search" value="{$search}" />
<input type="submit" value="Search" />
</form>
</xsl:template>
 
<xsl:template match="div[@id = 'xsltsearch_results']">
<div class="results">
<xsl:apply-templates />
</div>
</xsl:template>
 
<xsl:template match="div[@class = 'xsltsearch_result']">
<div class="result">
<h3>
<xsl:value-of select="p[@class = 'xsltsearch_result_title']"/>
</h3>
<p>
<xsl:value-of select="p[@class = 'xsltsearch_result_description']/span[@class = 'xsltsearch_description']" disable-output-escaping="yes"/>
<xsl:text> </xsl:text>
<a href="{p[@class = 'xsltsearch_result_title']/a[@class = 'xsltsearch_title']/@href}">More...</a>
</p>
</div>
</xsl:template>
 
<xsl:template match="p[@id = 'xsltsearch_navigation']">
<div class="pagination">
 
<xsl:choose>
<xsl:when test="a[text() = '1']">
<a href="{a[text() = '1']/@href}">&lt;&lt; First</a>
</xsl:when>
<xsl:otherwise>
<span>&lt;&lt; First</span>
</xsl:otherwise>
</xsl:choose>
 
<xsl:choose>
<xsl:when test="a[@id = 'previous' and @class = 'disabled']">
<span>
<xsl:value-of select="a[@id = 'previous']/text()" disable-output-escaping="yes"/>
</span>
</xsl:when>
<xsl:when test="a[@id = 'previous']">
<a href="{a[@id = 'previous']/@href}">
<xsl:value-of select="a[@id = 'previous']/text()" disable-output-escaping="yes"/>
</a>
</xsl:when>
</xsl:choose>
 
<div class="pagenumbers">
<xsl:for-each select="a[not(@id)] | strong">
<a>
<xsl:if test="self::strong">
<xsl:attribute name="class">active</xsl:attribute>
</xsl:if>
<xsl:if test="normalize-space(@href)">
<xsl:attribute name="href">
<xsl:value-of select="@href"/>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="text()"/>
</a>
<xsl:if test="position() != last()">
<xsl:text><![CDATA[ | ]]></xsl:text>
</xsl:if>
</xsl:for-each>
</div>
 
<xsl:choose>
<xsl:when test="a[@id = 'next' and @class = 'disabled']">
<span>
<xsl:value-of select="a[@id = 'next']/text()" disable-output-escaping="yes"/>
</span>
</xsl:when>
<xsl:when test="a[@id = 'next']">
<a href="{a[@id = 'next']/@href}">
<xsl:value-of select="a[@id = 'next']/text()" disable-output-escaping="yes"/>
</a>
</xsl:when>
</xsl:choose>
 
<xsl:choose>
<xsl:when test="a[not(@id) and not(following-sibling::strong)]">
<a href="{a[not(@id)][last()]/@href}">Last &gt;&gt;</a>
</xsl:when>
<xsl:otherwise>
<span>Last &gt;&gt;</span>
</xsl:otherwise>
</xsl:choose>
 
</div>
</xsl:template>
 
</xsl:stylesheet>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.