<?xml version="1.0" encoding="windows-1251"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">
<xsl:output method="html" indent="yes" encoding="windows-1251"/>

  
<!-- Если данный файл обрабатывается из Yandex.Software, -->
<!-- следующие параметры будут переписаны обработчиком   -->
<xsl:param name="script"></xsl:param>
<xsl:param name="images">i/</xsl:param>

<!-- Определим для удобства часто используемые переменные -->
<xsl:variable name="page" select="string(/yandexsearch/request/page)"/>
<xsl:variable name="reqid" select="string(/yandexsearch/response/reqid)"/>
<xsl:variable name="query" select="string(/yandexsearch/request/query)"/>

<!-- Формирование строки с группировкой -->
<xsl:variable name="grouping">mode=<xsl:value-of select="/yandexsearch/request/groupings/groupby/@mode"/>.attr=<xsl:value-of select="/yandexsearch/request/groupings/groupby/@attr"/>.groups-on-page=<xsl:value-of select="/yandexsearch/request/groupings/groupby/@groups-on-page"/>.docs-in-group=<xsl:value-of select="/yandexsearch/request/groupings/groupby/@docs-in-group"/>.curcateg=<xsl:value-of select="/yandexsearch/request/groupings/groupby/@curcateg"/></xsl:variable>

<xsl:variable name="grouping_esc">mode%3D<xsl:value-of select="/yandexsearch/request/groupings/groupby/@mode"/>.attr%3D<xsl:value-of select="/yandexsearch/request/groupings/groupby/@attr"/>.groups-on-page%3D<xsl:value-of select="/yandexsearch/request/groupings/groupby/@groups-on-page"/>.docs-in-group%3D<xsl:value-of select="/yandexsearch/request/groupings/groupby/@docs-in-group"/>.curcateg%3D<xsl:value-of select="/yandexsearch/request/groupings/groupby/@curcateg"/></xsl:variable>

<!-- Этот элемент не должен производить какой-либо вывод -->
<xsl:template match="request" />

<xsl:template name="printoption">
    <xsl:param name="optvalue" select="''"/>
    <xsl:param name="optcurrent" select="''"/>
    <xsl:param name="optname" select="''"/>
    <xsl:choose>
        <xsl:when test="$optvalue = $optcurrent">
            <option value="{$optvalue}" selected="selected"><xsl:value-of select="$optname"/></option>
        </xsl:when>
        <xsl:otherwise>
            <option value="{$optvalue}"><xsl:value-of select="$optname"/></option>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="printcheck">
    <xsl:param name="value" select="''"/>
    <xsl:param name="current" select="''"/>
    <xsl:param name="name" select="''"/>
    <xsl:choose>
        <xsl:when test="$value = $current">
           <input type="checkbox" name="{$name}" value="{$value}" checked="checked" />
        </xsl:when>
        <xsl:otherwise>
           <input type="checkbox" name="{$name}" value="{$value}" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="printradio">
    <xsl:param name="value" select="0"/>
    <xsl:param name="current" select="0"/>
    <xsl:param name="name" select="''"/>
    <xsl:choose>
        <xsl:when test="$value = $current">
           <input type="radio" name="{$name}" value="{$value}" checked="checked" />
        </xsl:when>
        <xsl:otherwise>
           <input type="radio" name="{$name}" value="{$value}" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>


<xsl:template match="querystring/param" mode="input">
<input type="hidden" name="{@name}" value="{text()}"/>
</xsl:template>

<xsl:template match="groupings" mode="input">
<xsl:text disable-output-escaping="yes">&lt;input type="hidden" name="groupby" value="</xsl:text><xsl:value-of select="$grouping" disable-output-escaping="yes"/><xsl:text>"/&gt;</xsl:text>
</xsl:template>

<!-- Здесь рисуем шапку, подвал и форму запроса -->
<xsl:template match="response">
<div class='sec_links'>
 <table cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
	<tr>
		<td>
			<!--<img src="{$images}x.gif" width="100%" height="1" border="0" vspace="10" style="background: #aaaaaa"/><br/>-->
      
			<!--<b>Результаты поиска: <em><xsl:value-of select="$query"/>&#160;(<xsl:value-of select="(found[@priority='all'])"/>)</em></b><br/>-->
			<!--<strong>Статистика слов:</strong>&#160;<xsl:value-of select="wordstat"/><br/><br/>-->
		   <xsl:apply-templates select="error"/>
          <xsl:apply-templates select="results"/>
      
  	<br/>
		</td>
	</tr>

</table>
</div>
<br/>
<!-- date sections -->
<!-- / date sections  -->

<!-- / footer -->

</xsl:template>

<xsl:template match="results">
    <xsl:apply-templates select="grouping"/>
</xsl:template>

<xsl:template name="pagelink">
    <xsl:param name="pagenum" select="0"/>
    <xsl:param name="curpage" select="0"/>
    <span id="pages_links">
    <xsl:if test="$pagenum&gt;0">&#160;&#160;</xsl:if>
    <xsl:choose>
        <xsl:when test="$pagenum = $curpage">
            <strong><xsl:value-of select="$pagenum+1"/></strong>
        </xsl:when>
        <xsl:otherwise>
            <!-- <a href="/search/?query={$query}&amp;groupby={$grouping_esc}&amp;page={$pagenum}"> -->
			<a href="/search/page/{$pagenum}.html?q={$query}"><xsl:value-of select="$pagenum+1"/></a>
        </xsl:otherwise>
    </xsl:choose>
	</span>
</xsl:template>
 
<xsl:template name="pagelinks">
	<xsl:param name="pagemin" select="0"/>
    <xsl:param name="pagemax" select="0"/>
    <xsl:param name="pagenum" select="0"/>
    <xsl:param name="curpage" select="0"/>
    <xsl:call-template name="pagelink">
        <xsl:with-param name="pagenum" select="$pagenum"/>
        <xsl:with-param name="curpage" select="$curpage"/>
    </xsl:call-template>
    <xsl:if test="$pagenum&lt;$pagemax">
        <xsl:call-template name="pagelinks">
            <xsl:with-param name="pagenum" select="$pagenum + 1"/>
            <xsl:with-param name="pagemax" select="$pagemax"/>
            <xsl:with-param name="pagemin" select="$pagemin"/>
            <xsl:with-param name="curpage" select="$curpage"/>
        </xsl:call-template>
    </xsl:if>
	
</xsl:template>

<xsl:template match="error">

    <xsl:if test="string-length(.)&gt;0">
     <center><p><b><xsl:value-of select="."/></b></p></center>
    </xsl:if>

</xsl:template>
  
<xsl:template match="grouping">
    <xsl:variable name="curpage" select="number(page)"/>
    <xsl:variable name="groupcount" select="number(found[@priority='all'])"/>
    <xsl:variable name="first" select="number(page/@first)"/>
    <xsl:variable name="last" select="number(page/@last)"/>
    <xsl:variable name="pagemax" select="ceiling($groupcount div @groups-on-page)-1"/>
    <xsl:variable name="pagemin">
        <xsl:choose>
          <xsl:when test="number($curpage)-5&gt;0"><xsl:value-of select="number($curpage)-5"/></xsl:when>
          <xsl:otherwise><xsl:value-of select="0"/></xsl:otherwise>
       </xsl:choose>
    </xsl:variable>
    
    	
    <ol start="{$first}">
        <xsl:apply-templates select="group"/>
    </ol>
    <br clear="all"/>
    <!--Сортировать по:-->
    <xsl:choose>
					<xsl:when test="../sortby = 'tm' "><!--<a href="{$script}?query={$query}">релевантности</a>&#160;|&#160;<b>дате</b>--></xsl:when>
					<xsl:otherwise><!--<b>релевантности</b>&#160;|&#160;<a href="{$script}?query={$query}&amp;groupby={$grouping_esc}&amp;sortby=tm">дате</a>--></xsl:otherwise>
				</xsl:choose>
				<!--<br/>-->
    
    <span>
    <font id="result"><b>Страницы:</b></font>&#160;&#160;
    <xsl:if test="$curpage&gt;0">
        <span id="pages_links"><a href="/search/page/{number($curpage)-1}.html?q={$query}">Предыдущая</a>&#160;&#160;</span>
    </xsl:if>
    <xsl:call-template name="pagelinks">
	
        <xsl:with-param name="curpage" select="$curpage"/>
        <xsl:with-param name="pagemin" select="$pagemin"/>
        <xsl:with-param name="pagenum" select="$pagemin"/>
        <xsl:with-param name="pagemax">
            <xsl:choose>
              <xsl:when test="$pagemax&gt;number($curpage)+5"><xsl:value-of select="number($curpage)+5"/></xsl:when>
              <xsl:otherwise><xsl:value-of select="$pagemax"/></xsl:otherwise>
			  
           </xsl:choose>
        </xsl:with-param>
	
   </xsl:call-template>
   <xsl:if test="$last&lt;$groupcount">
      <span id="pages_links">&#160;&#160;<a href="/search/page/{number($curpage)+1}.html?q={$query}">Следующая</a></span>
   </xsl:if></span><br/><font id="pages_stat">(всего: <xsl:value-of select="$groupcount"/> записей)</font><br/><br/>
   Поиск реализован на основе <a href="http://xml.yandex.ru/">Яндекс.XML</a>
</xsl:template>

<xsl:template match="group">
    <li><xsl:apply-templates select="doc"/></li>
</xsl:template>

<xsl:template match="doc">
	
    <p>
    <a href="{url}" ><xsl:apply-templates select="title"/></a><br/>
    <!-- <xsl:apply-templates select="headline"/> -->
    <xsl:apply-templates select="passages"/>
    </p>
    
</xsl:template>


<xsl:template match="passages">
    <xsl:apply-templates select="passage"/>
</xsl:template>

<xsl:template match="passage">
    <span style='font-size: 94%;  margin:0;'> <!--***--> <xsl:apply-templates/> </span><br/>
</xsl:template>

<xsl:template match="headline">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="hldoc">
    <xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>

<xsl:template match="hlword">
<b><xsl:value-of select="." disable-output-escaping="yes"/></b>
<xsl:if test="following-sibling::*"><xsl:text> </xsl:text></xsl:if>
</xsl:template>


<xsl:template match="statistics">
<A NAME="YANDEX_BOTTOM"></A>
</xsl:template>

</xsl:stylesheet>
