Created
February 21, 2012 21:26
-
-
Save leekelleher/1879072 to your computer and use it in GitHub Desktop.
Manipulate XSLTsearch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE xsl:stylesheet [ | |
<!ENTITY nbsp " "> | |
]> | |
<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}"><< First</a> | |
</xsl:when> | |
<xsl:otherwise> | |
<span><< 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 >></a> | |
</xsl:when> | |
<xsl:otherwise> | |
<span>Last >></span> | |
</xsl:otherwise> | |
</xsl:choose> | |
</div> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment