Помогите с шаблоном для групп и элементов ИС

#
Помогите с шаблоном для групп и элементов ИС
Помогите пожалуйста доработать xsl-шаблон (на основе шаблона Новости и Статьи/СписокЭлементовИнфосистемы).

Что мы имеем:
1. В списке групп под каждой группой выводятся все элменты этой группы;
2. Эти элементы учитываются в переменной count_items в xsl, создавая ненужную постраничную навигацию;
3. Список групп не разбивается на страницы.

Как должно быть:
1. В списке групп под каждой группой выводится 4 элемента из этой группы;
2. Эти элементы под группами не учитываются в переменной count_items в xsl;
3. Число элементов на странице в настройках динамической страницы определяет не только число элементов ис,
но и кол-во групп (например, в настройках указано 4 элемента на стриницу,
в группе 1 подгруппа и 5 элементов - выведется 1 подгруппа и 3 элемента).

Вывожу так (на основе Типовой дин страницы Информационные системы/Информационная система):

$rez = $InformationSystem->GetInformationFromPath($InformationSystem_id);
$external_propertys['ТекущаяГР'] = $rez['group'];
$property['xml_show_group_type'] = 'all';
// Разрешаем передачу в XML свойств групп
$property['xml_show_group_property'] = true;

/* Отображаем информационную систему */
$InformationSystem->ShowInformationSystem($InformationSystem_id,false, $xsl_list, $InformationResult['items_on_page'], $InformationResult['items_begin'], $external_propertys, $property);


Сам шаблон:


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <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:template match="/">
      <xsl:apply-templates select="/document"/>
   </xsl:template>
   
   <xsl:template match="/document">
      
      <!-- Получаем ID родительской группы и записываем в переменную $parent_group_id -->
      <xsl:variable name="parent_group_id" select="blocks/parent_group_id"/>
<xsl:variable name="current_gr_id" select="/document/ТекущаяГР"/>

      <!-- Если в находимся корне - выводим название информационной системы -->
      <xsl:if test="blocks/parent_group_id = 0">
         <h1 class="title">
            <xsl:value-of disable-output-escaping="yes" select="blocks/name"/>
         </h1>
         
         <!-- Описание выводится при отсутствии фильтрации по тэгам -->
         <xsl:if test="count(blocks/selected_tags/tag) = 0 and blocks/items/current_page = 0">
            <xsl:value-of disable-output-escaping="yes" select="blocks/description"/>
         </xsl:if>
      </xsl:if>
      
      <!-- Если в находимся в группе - выводим название группы -->
      <xsl:if test="blocks/parent_group_id != 0">
         <h1 class="title">
            <xsl:value-of disable-output-escaping="yes" select=".//group[@id=$parent_group_id]/name"/>
         </h1>
         
         <!-- Описание выводим только на первой странице -->
         <xsl:if test="blocks/items/current_page = 0">
            <xsl:value-of disable-output-escaping="yes" select=".//group[@id=$parent_group_id]/description"/>
         </xsl:if>
         
      </xsl:if>
      
      <!-- Обработка выбранных тэгов -->
      <xsl:if test="count(blocks/selected_tags/tag) = 1">
      <h2>Метка &#8212; <strong><xsl:value-of select="blocks/selected_tags/tag/tag_name" disable-output-escaping="yes" /></strong>.</h2>
         <p><xsl:value-of select="blocks/selected_tags/tag/tag_description" disable-output-escaping="yes" /></p>
      </xsl:if>
      
      <!-- Отображение подгрупп данной группы, только если подгруппы есть и не идет фильтра по меткам -->
      <xsl:if test="count(blocks/selected_tags/tag) = 0 and count(.//group[@parent_id=$parent_group_id]) &gt; 0">
         <table id="is_groups" width="100%" border="0" cellspacing="0" cellpadding="0">
            <xsl:apply-templates select=".//group[@parent_id=$current_gr_id]" mode="groups"/>
         </table>
      </xsl:if>
                  
      <!-- Отображение записи информационной системы -->
<table id="is_items" width="100%" border="0" cellspacing="0" cellpadding="0">
      <xsl:apply-templates select="blocks/items/item[item_status=1 and @group_id=$current_gr_id]"/>
</table>

      <!-- Строка ссылок на другие страницы информационной системы -->
      <xsl:if test="ОтображатьСсылкиНаСледующиеСтраницы=1">
         <p>
            <!-- Ссылка, для которой дописываются суффиксы page-XX/ -->
            <xsl:variable name="link">
               <xsl:value-of select="/document/blocks/url"/>
               <xsl:if test="$parent_group_id != 0">
                  <xsl:value-of select="/document/blocks//group[@id = $parent_group_id]/fullpath"/>
               </xsl:if>
            </xsl:variable>
            
            <xsl:if test="blocks/items/count_items &gt; 0 and blocks/items/items_on_page &gt; 0">
               
               <xsl:variable name="count_pages" select="ceiling(blocks/items/count_items div blocks/items/items_on_page)"/>
               
               <xsl:variable name="visible_pages" select="5"/>
               
               <xsl:variable name="real_visible_pages"><xsl:choose>
                     <xsl:when test="$count_pages &lt; $visible_pages"><xsl:value-of select="$count_pages"/></xsl:when>
                     <xsl:otherwise><xsl:value-of select="$visible_pages"/></xsl:otherwise>
               </xsl:choose></xsl:variable>
               
               <!-- Считаем количество выводимых ссылок перед текущим элементом -->
               <xsl:variable name="pre_count_page"><xsl:choose>
                     <xsl:when test="blocks/items/current_page  - (floor($real_visible_pages div 2)) &lt; 0">
                        <xsl:value-of select="blocks/items/current_page"/>
                     </xsl:when>
                     <xsl:when test="($count_pages  - blocks/items/current_page - 1) &lt; floor($real_visible_pages div 2)">
                        <xsl:value-of select="$real_visible_pages - ($count_pages  - blocks/items/current_page - 1) - 1"/>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:choose>
                           <xsl:when test="round($real_visible_pages div 2) = $real_visible_pages div 2">
                              <xsl:value-of select="floor($real_visible_pages div 2) - 1"/>
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:value-of select="floor($real_visible_pages div 2)"/>
                           </xsl:otherwise>
                        </xsl:choose>
                     </xsl:otherwise>
               </xsl:choose></xsl:variable>
               
               <!-- Считаем количество выводимых ссылок после текущего элемента -->
               <xsl:variable name="post_count_page"><xsl:choose>
                     <xsl:when test="0 &gt; blocks/items/current_page - (floor($real_visible_pages div 2) - 1)">
                        <xsl:value-of select="$real_visible_pages - blocks/items/current_page - 1"/>
                     </xsl:when>
                     <xsl:when test="($count_pages  - blocks/items/current_page - 1) &lt; floor($real_visible_pages div 2)">
                        <xsl:value-of select="$real_visible_pages - $pre_count_page - 1"/>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:value-of select="$real_visible_pages - $pre_count_page - 1"/>
                     </xsl:otherwise>
               </xsl:choose></xsl:variable>
               
               <xsl:variable name="i"><xsl:choose>
                     <xsl:when test="blocks/items/current_page + 1 = $count_pages"><xsl:value-of select="blocks/items/current_page - $real_visible_pages + 1"/></xsl:when>
                     <xsl:when test="blocks/items/current_page - $pre_count_page &gt; 0"><xsl:value-of select="blocks/items/current_page - $pre_count_page"/></xsl:when>
                     <xsl:otherwise>0</xsl:otherwise>
               </xsl:choose></xsl:variable>
               
               <p>
                  <xsl:call-template name="for">
                     <xsl:with-param name="items_on_page" select="blocks/items/items_on_page"/>
                     <xsl:with-param name="current_page" select="blocks/items/current_page"/>
                     <xsl:with-param name="count_items" select="blocks/items/count_items"/>
                     <xsl:with-param name="i" select="$i"/>
                     <xsl:with-param name="post_count_page" select="$post_count_page"/>
                     <xsl:with-param name="pre_count_page" select="$pre_count_page"/>
                     <xsl:with-param name="visible_pages" select="$real_visible_pages"/>
                  </xsl:call-template>
               </p>
               <div style="clear: both"></div>
            </xsl:if>
            
         </p>
      </xsl:if>
      
      <xsl:if test="count(blocks/properties_groups_dir) and blocks/parent_group_id != 0">
         <div style="margin: 10px 0px;">
            <h2>Атрибуты группы инфоэлементов</h2>
            
            <xsl:if test="count(blocks/group[@id = //blocks/parent_group_id]/propertys/property[@parent_id = 0])">
               <table border="0">
                  <xsl:apply-templates select="blocks/group[@id = //blocks/parent_group_id]/propertys/property[@parent_id = 0]"/>
               </table>
            </xsl:if>
            
            <xsl:apply-templates select="blocks/properties_groups_dir"/>
         </div>
      </xsl:if>
      
      <div style="clear: both"></div>
      
      
   </xsl:template>
   
   <!-- Вывод строки со значением свойства -->
   <xsl:template match="property">
      <tr>
         <td style="padding: 5px" bgcolor="#eeeeee">
            <b><xsl:value-of select="name"/></b>
         </td>
         <td style="padding: 5px" bgcolor="#eeeeee">
            <xsl:choose>
               <xsl:when test="type = 1">
                  <a href="{file_path}">Скачать файл</a>
               </xsl:when>
               <xsl:when test="type = 7">
                  <xsl:choose>
                     <xsl:when test="value = 1">
                        <input type="checkbox" checked="" disabled="" />
                     </xsl:when>
                     <xsl:otherwise>
                        <input type="checkbox" disabled="" />
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:value-of disable-output-escaping="yes" select="value"/>
               </xsl:otherwise>
            </xsl:choose>
         </td>
      </tr>
   </xsl:template>
   
   <!-- Шаблон выводит рекурсивно ссылки на группы инф. элемента -->
   <xsl:template match="group" mode="goup_path">
      <xsl:variable name="parent_id" select="@parent_id"/>
      
      <xsl:apply-templates select="//group[@id=$parent_id]" mode="goup_path"/>
      
      <xsl:if test="@parent_id=0">
         <a href="{/document/blocks/url}">
            <xsl:value-of disable-output-escaping="yes" select="/document/blocks/name"/>
         </a>
      </xsl:if>
      
      <span class="path_arrow">&#x2192;</span>
      
      <a href="{/document/blocks/url}{fullpath}">
         <xsl:value-of disable-output-escaping="yes" select="name"/>
      </a>
   </xsl:template>
   
   
   <!-- Шаблон выводит группы свойств для группы инфосистемы -->
   <xsl:template match="properties_groups_dir">
      
   <p><b><xsl:value-of select="information_propertys_groups_dir_name"/></b></p>
      
      <xsl:variable name="dir_id" select="@id"/>
      
      <xsl:if test="count(//blocks/group[@id = //blocks/parent_group_id]/propertys/property[@parent_id = $dir_id])">
         <table border="0">
            <xsl:apply-templates select="//blocks/group[@id = //blocks/parent_group_id]/propertys/property[@parent_id = $dir_id]"/>
         </table>
      </xsl:if>
      
      <xsl:if test="count(properties_groups_dir)">
         <blockquote>
            <xsl:apply-templates select="properties_groups_dir"/>
         </blockquote>
      </xsl:if>
   </xsl:template>
   
   <!-- Шаблон выводит ссылки подгруппы информационного элемента -->
   <xsl:template match="group" mode="groups">
      <tr valign="top"><td>
            <xsl:if test="small_image!=''">
               <a href="{/document/blocks/url}{fullpath}" target="_blank"  title="{item_name}">
                  <img src="{small_image}" title="{item_name}" alt="{item_name}" />
               </a>
            </xsl:if>
         </td>
         <td width="100%">
            <div style="margin:0 0 0 5px;">
               <h2>
                  <a href="{/document/blocks/url}{fullpath}"  title="{item_name}">
                     <xsl:value-of disable-output-escaping="yes" select="name"/>
                  </a>
               </h2>
               <div style="padding:5px 0 0 25px;">
               
               <!-- Пункт 1 -->
                  <xsl:variable name="group_id" select="@id"/>
                  <xsl:apply-templates select="/document/blocks/items/item[@group_id=$group_id]" mode="sub"/>
               <!-- Конец Пункт 1 -->

               
                  <xsl:if test="count_all_items!=0">
                  <a href="{/document/blocks/url}{fullpath}"  title="{item_name}" class="items_all_link">
                     все товары данной группы
                  </a>
                  <a href="{/document/blocks/url}{fullpath}"  title="{item_name}" class="items_all_link1">
                     /<span style="color:#e7313e;"><xsl:value-of select="count_all_items"/></span>/
                  </a>
                  </xsl:if>
            </div></div>
      </td></tr>
   </xsl:template>
   
   
   <!-- Шаблон вывода элементов под группами -->
   <xsl:template match="blocks/items/item" mode="sub">
      <p><a href="{item_path}">
         <xsl:value-of disable-output-escaping="yes" select="item_name"/>
      </a></p>
   </xsl:template>

   
   
   
   <!-- Шаблон вывода информационного элемента -->
   <xsl:template match="blocks/items/item">

<xsl:if test="position() mod 2 != 0">
<xsl:text disable-output-escaping="yes">&lt;tr>&lt;tr valign="top"></xsl:text>
</xsl:if>
<td>
         <!-- Название -->
         <p style="font-weight:bold;">
            <a href="{item_path}">
               <xsl:value-of disable-output-escaping="yes" select="item_name"/>
            </a>
         </p>

      <div class="is_item_body">
         
         <!-- Изображение для информационного элемента (если есть) -->
         <xsl:if test="item_small_image!=''">
            <a href="{item_path}" class="news_title">
               <img src="{item_small_image}" alt="{item_name}" title="{item_name}" align="left"/>
            </a>
         </xsl:if>
         
         <xsl:value-of disable-output-escaping="yes" select="item_description"/>
<div style="clear:both;"></div>
      </div>
</td>
<xsl:if test="position() mod 2 = 0">
<xsl:text disable-output-escaping="yes">&lt;/tr>&lt;tr valign="top"></xsl:text>
</xsl:if>   
   </xsl:template>
   
   <!-- /// Метки для информационного элемента /// -->
   <xsl:template match="tags/tag">
      <a href="{/document/blocks/url}tag/{tag_path_name}/" class="tag">
         <xsl:value-of select="tag_name"/>
      </a>
<xsl:if test="position() != last()"><xsl:text>, </xsl:text></xsl:if></xsl:template>
   
   <!-- Цикл для вывода строк ссылок -->
   <xsl:template name="for">
      
      <xsl:param name="items_on_page"/>
      <xsl:param name="current_page"/>
      <xsl:param name="pre_count_page"/>
      <xsl:param name="post_count_page"/>
      <xsl:param name="i" select="0"/>
      <xsl:param name="count_items"/>
      <xsl:param name="visible_pages"/>
      
      <xsl:variable name="n" select="ceiling($count_items div $items_on_page)"/>
      
      <xsl:variable name="start_page"><xsl:choose>
            <xsl:when test="$current_page + 1 = $n"><xsl:value-of select="$current_page - $visible_pages + 1"/></xsl:when>
            <xsl:when test="$current_page - $pre_count_page &gt; 0"><xsl:value-of select="$current_page - $pre_count_page"/></xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
      </xsl:choose></xsl:variable>
      
      <xsl:if test="$count_items &gt; $items_on_page">
         <span class="ctrl">
            &#8592; Ctrl
         </span>
      </xsl:if>
      
      <xsl:if test="$count_items &gt; $items_on_page">
         <span class="ctrl">
            Ctrl &#8594;
         </span>
      </xsl:if>
      
      <xsl:if test="$count_items &gt; $items_on_page and ($current_page + $post_count_page + 1) &gt; $i">
         <!-- Заносим в переменную $parent_group_id идентификатор текущей группы -->
         <xsl:variable name="parent_group_id" select="/document/blocks/parent_group_id"/>
         <xsl:variable name="current_gr_id" select="/document/ТекущаяГР"/>
         <!-- Путь для тэга -->
         <xsl:variable name="tag_path">
            <xsl:choose>
               <!-- Если не нулевой уровень -->
               <xsl:when test="count(/document/blocks/selected_tags/tag) != 0">tag/<xsl:value-of select="/document/blocks/selected_tags/tag/tag_path_name"/>/</xsl:when>
               <!-- Иначе если нулевой уровень - просто ссылка на страницу со списком элементов -->
               <xsl:otherwise></xsl:otherwise>
            </xsl:choose>
         </xsl:variable>
         
         <!-- Определяем группу для формирования адреса ссылки -->
         <xsl:variable name="group_link">
            <xsl:choose>
               <!-- Если группа не корневая (!=0) -->
               <xsl:when test="$current_gr_id != 0">
                  <xsl:value-of select="/document/blocks//group[@id=$current_gr_id]/fullpath"/>
               </xsl:when>
               <!-- Иначе если нулевой уровень - просто ссылка на страницу со списком элементов -->
               <xsl:otherwise></xsl:otherwise>
            </xsl:choose>
         </xsl:variable>
         
         <!-- Определяем адрес ссылки -->
         <xsl:variable name="number_link">
            <xsl:choose>
               <!-- Если не нулевой уровень -->
               <xsl:when test="$i != 0">page-<xsl:value-of select="$i + 1"/>/</xsl:when>
               <!-- Иначе если нулевой уровень - просто ссылка на страницу со списком элементов -->
               <xsl:otherwise></xsl:otherwise>
            </xsl:choose>
         </xsl:variable>
         
         <!-- Выводим ссылку на первую страницу -->
         <xsl:if test="$current_page - $pre_count_page &gt; 0 and $i = $start_page">
            <a href="{/document/blocks/url}{$group_link}{$tag_path}" class="page_link" style="text-decoration: none;">&#x2190;</a>
            <a href="{/document/blocks/url}{$group_link}" class="page_link" style="text-decoration: none;">&#x2190;</a>
         </xsl:if>
         
         <!-- Ставим ссылку на страницу-->
         <xsl:if test="$i != $current_page">
            <xsl:if test="($current_page - $pre_count_page) &lt;= $i and $i &lt; $n">
               <!-- Выводим ссылки на видимые страницы -->
               <a href="{/document/blocks/url}{$group_link}{$tag_path}{$number_link}" class="page_link">
                  <xsl:value-of select="$i + 1"/>
               </a>
            </xsl:if>
            
            <!-- Выводим ссылку на последнюю страницу -->
            <xsl:if test="$i+1 &gt;= ($current_page + $post_count_page + 1) and $n &gt; ($current_page + 1 + $post_count_page)">
               <!-- Выводим ссылку на последнюю страницу -->
               <a href="{/document/blocks/url}{$group_link}{$tag_path}page-{$n}/" class="page_link" style="text-decoration: none;">&#x2192;</a>
            </xsl:if>
         </xsl:if>
         
         <!-- Ссылка на предыдущую страницу для Ctrl + влево -->
         <xsl:if test="$current_page != 0 and $i = $current_page">
            <xsl:variable name="prev_number_link">
               <xsl:choose>
                  <!-- Если не нулевой уровень -->
                  <xsl:when test="($current_page - 1) != 0">page-<xsl:value-of select="$i"/>/</xsl:when>
                  <!-- Иначе если нулевой уровень - просто ссылка на страницу со списком элементов -->
                  <xsl:otherwise></xsl:otherwise>
               </xsl:choose>
            </xsl:variable>
            
            <a href="{/document/blocks/url}{$group_link}{$tag_path}{$prev_number_link}" id="id_prev"></a>
         </xsl:if>
         
         <!-- Ссылка на следующую страницу для Ctrl + вправо -->
         <xsl:if test="($n - 1) > $current_page and $i = $current_page">
            <a href="{/document/blocks/url}{$group_link}{$tag_path}page-{$current_page+2}/" id="id_next"></a>
         </xsl:if>
         
         <!-- Не ставим ссылку на страницу-->
         <xsl:if test="$i = $current_page">
            <span class="current">
               <xsl:value-of select="$i+1"/>
            </span>
         </xsl:if>
         
         <!-- Рекурсивный вызов шаблона. НЕОБХОДИМО ПЕРЕДАВАТЬ ВСЕ НЕОБХОДИМЫЕ ПАРАМЕТРЫ! -->
         <xsl:call-template name="for">
            <xsl:with-param name="i" select="$i + 1"/>
            <xsl:with-param name="items_on_page" select="$items_on_page"/>
            <xsl:with-param name="current_page" select="$current_page"/>
            <xsl:with-param name="count_items" select="$count_items"/>
            <xsl:with-param name="pre_count_page" select="$pre_count_page"/>
            <xsl:with-param name="post_count_page" select="$post_count_page"/>
            <xsl:with-param name="visible_pages" select="$visible_pages"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>
   
   <!-- Склонение после числительных -->
   <xsl:template name="declension">
      
      <xsl:param name="number" select="number"/>
      
      <!-- Именительный падеж -->
      <xsl:variable name="nominative">
         <xsl:text>комментарий</xsl:text>
      </xsl:variable>
      
      <!-- Родительный падеж, единственное число -->
      <xsl:variable name="genitive_singular">
         <xsl:text>комментария</xsl:text>
      </xsl:variable>
      
      
      <xsl:variable name="genitive_plural">
         <xsl:text>комментариев</xsl:text>
      </xsl:variable>
      
      <xsl:variable name="last_digit">
         <xsl:value-of select="$number mod 10"/>
      </xsl:variable>
      
      <xsl:variable name="last_two_digits">
         <xsl:value-of select="$number mod 100"/>
      </xsl:variable>
      
      <xsl:choose>
         <xsl:when test="$last_digit = 1 and $last_two_digits != 11">
            <xsl:value-of select="$nominative"/>
         </xsl:when>
         <xsl:when test="$last_digit = 2 and $last_two_digits != 12
            or $last_digit = 3 and $last_two_digits != 13
            or $last_digit = 4 and $last_two_digits != 14">
            <xsl:value-of select="$genitive_singular"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="$genitive_plural"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
</xsl:stylesheet>
iq-site
Авторизация