Скрыть пустые фильтры

#
Скрыть пустые фильтры
Доброе время суток. Убрал отсутствующие значения фильтра <xsl:if test="../../filter_counts/count[@id = $list_item_id]/node()">...</xsl:if> но не могу понять как не показывать фильтры в которых нет вообще значений. Я плохо понимаю xsl, так что может кто-то поможет ?


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:hostcms="http://www.hostcms.ru/"
   exclude-result-prefixes="hostcms">
   <xsl:output xmlns="http://www.w3.org/TR/xhtml1/strict" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" encoding="utf-8" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml"/>
   
   <xsl:decimal-format name="my" decimal-separator="," grouping-separator=" "/>
   
   <xsl:template match="/">
      <script type="text/javascript">
         <xsl:comment>
            <xsl:text disable-output-escaping="yes">
               <![CDATA[
               $(function() {
               var jForm = $('.filter').closest('form');
               mainFastFilter = new fastFilter(jForm);
               
               jForm.find(':input:not(:hidden):not(button)').on('change', function() {
               mainFastFilter.filterChanged($(this));
               });
               
               $('.filter-color').on('click', function(){
               var bg = $(this).css('background-color'),
               className = $(this).attr('class');
               
               if (className == 'filter-color')
               {
               $('.filter-color').each(function(index, value) {
               $(this).removeClass('active');
               });
               
               $(this).addClass('active');
               
               $('.color-input').remove();
               
               var property_id = $(this).data('id'),
               list_item_id = $(this).data('item-id');
               
               $(this).append('<input type="hidden" class="color-input" id="property_' + property_id + '_' + list_item_id +'" name="property_' + property_id + '" data-property="' + $(this).data('property') + '" data-value="' + $(this).data('value') + '" value="' + list_item_id + '"/>');
               }
               else
               {
               $('.filter-color').each(function(index, value) {
               $(this).removeClass('active');
               });
               
               $('.color-input').remove();
               }
               
               mainFastFilter.filterChanged($(this));
               });
               
               jForm.on('submit', function(e) {
               e.preventDefault();
               applyFilter();
               });
               });
               ]]>
            </xsl:text>
         </xsl:comment>
      </script>
      
      <xsl:apply-templates select="/shop"/>
   </xsl:template>
   
   <xsl:variable name="n" select="number(3)"/>
   
   <xsl:template match="/shop">
      
      <!-- Получаем ID родительской группы и записываем в переменную $group -->
      <xsl:variable name="group" select="group"/>
      
      <xsl:variable name="path">
         <xsl:choose>
            <xsl:when test="/shop//shop_group[@id=$group]/node()"><xsl:value-of select="/shop//shop_group[@id=$group]/url"/></xsl:when>
            <xsl:otherwise><xsl:value-of select="/shop/url"/></xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      
      <!-- дополнение пути для action, если выбрана метка -->
   <xsl:variable name="form_tag_url"><xsl:if test="count(tag) = 1">tag/<xsl:value-of select="tag/urlencode"/>/</xsl:if></xsl:variable>
      
      <form method="get" action="{$path}{$form_tag_url}">
         <div class="filter">
            <div class="property-list sidebar-list">
               <select class="form-control sorting-list-select" name="sorting" onchange="$(this).parents('form:first').submit()">
                  <!-- <select class="form-control sorting-list-select" name="sorting"> -->
                     <option value="0">Сортировать</option>
                     <option value="1">
                     <xsl:if test="sorting = 1"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
                        По цене (сначала дешевые)
                     </option>
                     <option value="2">
                     <xsl:if test="sorting = 2"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
                        По цене (сначала дорогие)
                     </option>
                     <option value="3">
                     <xsl:if test="sorting = 3"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
                        По названию
                     </option>
                  </select>
               </div>
               
               <div class="range-price-block sidebar-list">
                  <h3>Цена</h3>
                  
                  <div class="range-price-item">
                     <span>от</span>
                     <input name="price_from" size="5" type="text" value="{/shop/min_price}">
                        <xsl:if test="/shop/price_from != 0">
                           <xsl:attribute name="value"><xsl:value-of select="/shop/price_from"/></xsl:attribute>
                        </xsl:if>
                     </input>
                     
                     <span>до</span>
                     <input name="price_to" size="5" type="text" value="{/shop/max_price}">
                        <xsl:if test="/shop/price_to != 0">
                           <xsl:attribute name="value"><xsl:value-of select="/shop/price_to"/></xsl:attribute>
                        </xsl:if>
                     </input>
                     
                     <input name="price_from_original" value="{/shop/min_price}" hidden="hidden" />
                     <input name="price_to_original" value="{/shop/max_price}" hidden="hidden" />
                  </div>
                  
                  <div class="slider"></div>
               </div>
               
               <!-- <div class="priceFilter">
                  <xsl:text>Цена от: </xsl:text>
                  <input name="price_from" size="5" type="text" value="{/shop/min_price}">
                     <xsl:if test="/shop/price_from != 0">
                        <xsl:attribute name="value"><xsl:value-of select="/shop/price_from"/></xsl:attribute>
                     </xsl:if>
                  </input>
                  
                  <xsl:text>до: </xsl:text>
                  <input name="price_to" size="5" type="text" value="{/shop/max_price}">
                     <xsl:if test="/shop/price_to != 0">
                        <xsl:attribute name="value"><xsl:value-of select="/shop/price_to"/></xsl:attribute>
                     </xsl:if>
                  </input>
                  
                  <input name="price_from_original" value="{/shop/min_price}" hidden="hidden" />
                  <input name="price_to_original" value="{/shop/max_price}" hidden="hidden" />
               </div>
               
               <div class="slider"></div><br/>-->
               
               <div class="property-list sidebar-list">
                  <h3>Производитель</h3>
                  <select class="form-control sorting-list-select" name="producer_id">
                     <option value="0">...</option>
                     <xsl:apply-templates select="/shop/producers/shop_producer" />
                  </select>
               </div>
               
               <!-- <list_item id="840">
                  <list_id>191</list_id>
                  <parent_id>0</parent_id>
                  <value>Зеленый</value>
                  <sorting>0</sorting>
                  <description></description>
                  <icon>#53a93f</icon>
                  <active>1</active>
               </list_item> -->
               
               <xsl:if test="shop_item_properties//property[tag_name = 'colors']/node() and count(shop_item_properties//property[tag_name = 'colors']/list//list_item[icon != ''])">
                  <div class="property-list sidebar-list">
                     <h3><xsl:value-of select="shop_item_properties//property[tag_name = 'colors']/name"/></h3>
                     
                     <xsl:for-each select="shop_item_properties//property[tag_name = 'colors']/list/list_item[icon != '']">
                        <xsl:variable name="color"><xsl:value-of select="icon" /></xsl:variable>
                        <xsl:variable name="nodename">property_<xsl:value-of select="../../@id" /></xsl:variable>
                        <div class="filter-color" style="background-color: {$color}" data-id="{../../@id}" data-property="{../../tag_name}" data-value="{value}" data-item-id="{@id}">
                           <xsl:if test="/shop/*[name()=$nodename]/node() and /shop/*[name()=$nodename] = @id">
                              <xsl:attribute name="class">filter-color active</xsl:attribute>
                              
                              <input type="hidden" class="color-input" id="property_{../../@id}_{@id}" name="property_{../../@id}" data-property="{../../tag_name}" data-value="{value}" value="{@id}"/>
                           </xsl:if>
                        </div>
                     </xsl:for-each>
                  </div>
               </xsl:if>
               
               <!-- Фильтр по дополнительным свойствам товара: -->
               <xsl:if test="count(shop_item_properties//property[filter != 0 and (type = 0 or type = 1 or type = 3 or type = 4 or type = 7 or type = 11) and tag_name != 'colors'])">
                  <xsl:apply-templates select="shop_item_properties//property[filter != 0 and (type = 0 or type = 1 or type = 3 or type = 4 or type = 7 or type = 11) and tag_name != 'colors']" mode="propertyList"/>
               </xsl:if>
               
               <div class="sidebar-list">
                  <!-- <input name="filter" class="filter-apply full-width" value="Применить" type="submit"/> -->
                  <button class="filter-apply full-width">Применить</button>
               </div>
            </div>
         </form>
      </xsl:template>
      
      <xsl:template match="shop_producer">
         <xsl:variable name="name">
            <xsl:choose>
               <xsl:when test="/shop/filter_mode = 0">
                  <xsl:value-of select="name" />
               </xsl:when>
               <xsl:otherwise>
                  <xsl:value-of select="path" />
               </xsl:otherwise>
            </xsl:choose>
         </xsl:variable>
         
         <option value="{@id}" data-producer="{$name}">
            <xsl:if test="/shop/producer_id = @id">
               <xsl:attribute name="selected">selected</xsl:attribute>
            </xsl:if>
            
            <xsl:value-of select="name"/>
            
            <xsl:if test="count/node()">
            <xsl:text> (</xsl:text><xsl:value-of select="count"/><xsl:text>)</xsl:text>
            </xsl:if>
         </option>
      </xsl:template>
      
      <!-- Шаблон для фильтра по дополнительным свойствам -->
      <xsl:template match="property" mode="propertyList">
         <xsl:variable name="nodename">property_<xsl:value-of select="@id"/></xsl:variable>
         <xsl:variable name="nodename_from">property_<xsl:value-of select="@id"/>_from</xsl:variable>
         <xsl:variable name="nodename_to">property_<xsl:value-of select="@id"/>_to</xsl:variable>
         
         <div class="property-list sidebar-list filter-vi" data-toggle="collapse" data-target="#collapse-{@id}" aria-expanded="false" aria-controls="collapse-{@id}">
            <!-- Не флажок -->
            <xsl:if test="filter != 5">
               <h3><xsl:value-of select="name"/></h3>
            </xsl:if>
            <div id="collapse-{@id}" aria-expanded="false" class="collapse">
               <xsl:choose>
                  <!-- Отображаем поле ввода -->
                  <xsl:when test="filter = 1">
                     <br/>
                     <input type="text" name="property_{@id}" data-property="{tag_name}">
                        <xsl:if test="/shop/*[name()=$nodename] != ''">
                           <xsl:attribute name="value"><xsl:value-of select="/shop/*[name()=$nodename]"/></xsl:attribute>
                        </xsl:if>
                     </input>
                  </xsl:when>
                  <!-- Отображаем список -->
                  <xsl:when test="filter = 2">
                     <!-- <br/> -->
                     <select class="form-control property-list-select" name="property_{@id}">
                        <option value="0">...</option>
                        <xsl:apply-templates select="list/list_item"/>
                     </select>
                  </xsl:when>
                  <!-- Отображаем переключатели -->
                  <xsl:when test="filter = 3">
                     <br/>
                     <div class="propertyInput">
                        <input type="radio" name="property_{@id}" value="0" id="id_prop_radio_{@id}_0"></input>
                        <label for="id_prop_radio_{@id}_0">Любой вариант</label>
                        <xsl:apply-templates select="list/list_item"/>
                     </div>
                  </xsl:when>
                  <!-- Отображаем флажки -->
                  <xsl:when test="filter = 4">
                     <!-- <div class="propertyInput">
                        <xsl:apply-templates select="list/list_item"/>
                     </div>
                     <div style="display:none; text-align: center;">
                        ...
                     </div>-->
                     
                     <xsl:apply-templates select="list/list_item"/>
                  </xsl:when>
                  <!-- Отображаем флажок -->
                  <xsl:when test="filter = 5">
                     <input type="checkbox" name="property_{@id}" value="1" id="property_{@id}" style="padding-top:4px" data-property="{tag_name}">
                        <xsl:if test="/shop/*[name()=$nodename] != ''">
                           <xsl:attribute name="checked"><xsl:value-of select="/shop/*[name()=$nodename]"/></xsl:attribute>
                        </xsl:if>
                     </input>
                     <label for="property_{@id}">
                        <xsl:value-of select="name"/><xsl:text> </xsl:text>
                     </label>
                  </xsl:when>
                  <!-- Отображение полей "от и до" -->
                  <xsl:when test="filter = 6">
                     <div class="propertyInput">
                        <div>
                           <xsl:text>От </xsl:text>
                           <input name="property_{@id}_from" size="5" type="text" value="{min}" data-property="{tag_name}">
                              <xsl:if test="/shop/*[name()=$nodename_from] != 0">
                                 <xsl:attribute name="value"><xsl:value-of select="/shop/*[name()=$nodename_from]"/></xsl:attribute>
                              </xsl:if>
                           </input>
                           
                           <xsl:text>до </xsl:text>
                           <input name="property_{@id}_to" size="5" type="text" value="{max}" data-property="{tag_name}">
                              <xsl:if test="/shop/*[name()=$nodename_to] != 0">
                                 <xsl:attribute name="value"><xsl:value-of select="/shop/*[name()=$nodename_to]"/></xsl:attribute>
                              </xsl:if>
                           </input>
                           
                           <input name="property_{@id}_from_original" value="{min}" hidden="hidden" />
                           <input name="property_{@id}_to_original" value="{max}" hidden="hidden" />
                        </div>
                        <div class="slider"></div><br/>
                     </div>
                  </xsl:when>
                  <!-- Отображаем список с множественным выбором-->
                  <xsl:when test="filter = 7">
                     <br/>
                     <select name="property_{@id}[]" multiple="multiple">
                        <xsl:apply-templates select="list/list_item"/>
                     </select>
                  </xsl:when>
               </xsl:choose>
            </div>
         </div>
      </xsl:template>
      
      <xsl:template match="list/list_item">
         <xsl:variable name="list_item_id" select="@id"/>
         
         <xsl:variable name="value">
            <xsl:choose>
               <xsl:when test="/shop/filter_mode = 1 and path != ''">
                  <xsl:value-of select="path" />
               </xsl:when>
               <xsl:otherwise>
                  <xsl:value-of select="value" />
               </xsl:otherwise>
            </xsl:choose>
         </xsl:variable>
         
         <xsl:if test="../../filter_counts/count[@id = $list_item_id]/node()">
            <xsl:if test="../../filter = 2">
               <!-- Отображаем список -->
               <xsl:variable name="nodename">property_<xsl:value-of select="../../@id"/></xsl:variable>
               <option value="{@id}" data-property="{../../tag_name}" data-value="{$value}">
               <xsl:if test="/shop/*[name()=$nodename] = @id"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
                  <xsl:value-of select="value"/>
                  
                  <xsl:if test="../../filter_counts/count[@id = $list_item_id]/node()">
                  <xsl:text> (</xsl:text><xsl:value-of select="../../filter_counts/count[@id = $list_item_id]"/><xsl:text>)</xsl:text>
                  </xsl:if>
               </option>
            </xsl:if>
            <xsl:if test="../../filter = 3">
               <!-- Отображаем переключатели -->
               <xsl:variable name="nodename">property_<xsl:value-of select="../../@id"/></xsl:variable>
               <br/>
               <input type="radio" name="property_{../../@id}" value="{@id}" id="id_property_{../../@id}_{@id}" data-property="{../../tag_name}" data-value="{$value}">
                  <xsl:if test="/shop/*[name()=$nodename] = @id">
                     <xsl:attribute name="checked">checked</xsl:attribute>
                  </xsl:if>
                  <label for="id_property_{../../@id}_{@id}">
                     <xsl:value-of select="value"/>
                     
                     <xsl:if test="../../filter_counts/count[@id = $list_item_id]/node()">
                     <xsl:text> (</xsl:text><xsl:value-of select="../../filter_counts/count[@id = $list_item_id]"/><xsl:text>)</xsl:text>
                     </xsl:if>
                  </label>
               </input>
            </xsl:if>
            <xsl:if test="../../filter = 4">
               <!-- Отображаем флажки -->
               <xsl:variable name="nodename">property_<xsl:value-of select="../../@id"/></xsl:variable>
               <div class="property-inline-wrapper">
                  <div>
                     <label class="checkbox-inline" for="property_{../../@id}_{@id}">
                        <input type="checkbox" value="{@id}" name="property_{../../@id}[]" id="property_{../../@id}_{@id}" data-property="{../../tag_name}" data-value="{$value}">
                           <xsl:if test="/shop/*[name()=$nodename] = @id">
                              <xsl:attribute name="checked">checked</xsl:attribute>
                           </xsl:if>
                           <!-- <label for="property_{../../@id}_{@id}">
                              <xsl:value-of disable-output-escaping="yes" select="value"/>
                           </label>-->
                        </input>
                        <span>
                           <xsl:value-of select="value"/>
                        </span>
                     </label>
                  </div>
                  <xsl:if test="../../filter_counts/count[@id = $list_item_id]/node()">
                  <div class="filter-label"><span class="label label-danger"><xsl:value-of select="../../filter_counts/count[@id = $list_item_id]"/></span></div>
                  </xsl:if>
               </div>
               <!-- <br/> -->
            </xsl:if>
            <xsl:if test="../../filter = 7">
               <!-- Отображаем список -->
               <xsl:variable name="nodename">property_<xsl:value-of select="../../@id"/></xsl:variable>
               <option value="{@id}" data-property="{../../tag_name}" data-value="{$value}">
                  <xsl:if test="/shop/*[name()=$nodename] = @id">
                     <xsl:attribute name="selected">
                     </xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="value"/>
                  
                  <xsl:if test="../../filter_counts/count[@id = $list_item_id]/node()">
                  <xsl:text> (</xsl:text><xsl:value-of select="../../filter_counts/count[@id = $list_item_id]"/><xsl:text>)</xsl:text>
                  </xsl:if>
               </option>
            </xsl:if>
         </xsl:if>
      </xsl:template>
   </xsl:stylesheet>
#
Re: Скрыть пустые фильтры
И ещё один вопрос сразу, есть ли хук для пересчета найденных товаров по фильтру, а то у меня показывает к примеру форма лампы 1, а как нажимаю поиск, то 404 страница, ибо их не найдено вообще
#
Re: Скрыть пустые фильтры
Рекомендуем обратиться по данному вопросу в техническую поддержку https://www.hostcms.ru/support/
«Не выходи из комнаты, не совершай ошибку…»
Авторизация