<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409116&amp;view=findpost&amp;p=3676137</guid>
        <pubDate>Tue, 05 Jul 2016 07:02:08 +0000</pubDate>
        <title>XSLT Преобразование</title>
        <link>https://forum.sources.ru/index.php?showtopic=409116&amp;view=findpost&amp;p=3676137</link>
        <description><![CDATA[Mcross: Приветствую&#33;<br>
Имеется XML <br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&#60;shop id=&quot;1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;shop_group id=&quot;1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;0&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_group id=&quot;11&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;1&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/shop_group&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_group id=&quot;12&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;1&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/shop_group&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_group id=&quot;13&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;1&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/shop_group&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/shop_group&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;shop_group id=&quot;2&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_id&#62;1&#60;/shop_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;0&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_group id=&quot;21&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;2&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/shop_group&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_group id=&quot;22&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_id&#62;1&#60;/shop_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;2&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/shop_group&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_group id=&quot;23&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_id&#62;1&#60;/shop_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;2&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/shop_group&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/shop_group&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;shop_group id=&quot;3&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_id&#62;1&#60;/shop_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;0&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_group id=&quot;31&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_id&#62;1&#60;/shop_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;3&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/shop_group&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_group id=&quot;32&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_id&#62;1&#60;/shop_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;3&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/shop_group&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_group id=&quot;33&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;shop_id&#62;1&#60;/shop_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;parent_id&#62;3&#60;/parent_id&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/shop_group&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/shop_group&#62; &nbsp; </div><div class="code_line">&#60;/shop&#62;</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
<br>
И XSL шаблон <br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&#60;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&#62;</div><div class="code_line">&#60;!DOCTYPE xsl:stylesheet&#62;</div><div class="code_line">&#60;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &#60;xsl:output xmlns=&quot;http://www.w3.org/TR/xhtml1/strict&quot; doctype-public=&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; encoding=&quot;utf-8&quot; indent=&quot;yes&quot; method=&quot;html&quot; omit-xml-declaration=&quot;no&quot; version=&quot;1.0&quot; media-type=&quot;text/xml&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; &#60;!-- МагазинГруппыТоваровНаГлавной --&#62;</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; &#60;xsl:template match=&quot;/&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;/shop&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &#60;/xsl:template&#62;</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; &#60;xsl:variable name=&quot;n&quot; select=&quot;number(3)&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; &#60;!-- Шаблон для магазина --&#62;</div><div class="code_line">&nbsp;&nbsp; &#60;xsl:template match=&quot;/shop&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div class=&quot;group_list_m&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;shop_group[position() mod $n = 1]&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;div class=&quot;clear&quot;&#62;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &#60;/xsl:template&#62;</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; &#60;!-- Шаблон для групп товара --&#62;</div><div class="code_line">&nbsp;&nbsp; &#60;xsl:template match=&quot;shop_group&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div class=&quot;sub-main&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &#60;xsl:for-each select=&quot;. | following-sibling::shop_group[position() &lt; $n]&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;div id=&quot;group_{shop_group/@id}&quot; class=&quot;group_list_item&quot; data-visible=&quot;none&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .....</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;!-- Если есть подгруппы --&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;div style=&quot;display: none;&quot; id=&quot;sub-level-1&quot; class=&quot;sub_group_{shop_group/@id} sub-level-1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#60;xsl:apply-templates select=&quot;shop_group&quot; mode=&quot;subgroup&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/div&#62; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &#60;/xsl:for-each&#62; &nbsp; &nbsp; &nbsp; &nbsp; </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &#60;/xsl:template&#62;</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; &#60;!-- Шаблон для групп товара --&#62;</div><div class="code_line">&nbsp;&nbsp; &#60;xsl:template match=&quot;shop_group&quot; mode=&quot;subgroup&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &#60;div class=&quot;sub_group_{shop_group/@id} sub-level-2&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;shop_group&quot; mode=&quot;subgroup-2&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &#60;/xsl:template&#62;</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; &#60;xsl:template match=&quot;shop_group&quot; mode=&quot;subgroup-2&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div class=&quot;sub_li_list-2&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &#60;xsl:if test=&quot;position() != 1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:attribute name=&quot;class&quot;&#62;sub_li_list-2 bordered-top&#60;/xsl:attribute&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &#60;/xsl:if&#62; &nbsp; &nbsp; &nbsp; &nbsp; </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &#60;!-- Если есть подгруппы --&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &#60;xsl:if test=&quot;shop_group&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;!-- выводим подгруппы 3 уровня --&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:if test=&quot;count(ancestor::*) &lt; 3&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#60;div class=&quot;sub_group_list_2&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;shop_group&quot; mode=&quot;subgroup-2&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/xsl:if&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &#60;/xsl:if&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &#60;/xsl:template&#62;</div><div class="code_line">&#60;/xsl:stylesheet&#62;</div></ol></div></div></div></div> <br>
<br>
Который преобразует это все в <br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&#60;div class=&quot;group_list_m&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &#60;div class=&quot;sub-main&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;group_1&quot; class=&quot;group_list_item&quot; data-visible=&quot;none&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;sub-level-1&quot; class=&quot;sub_group_1 sub-level-1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;group_2&quot; class=&quot;group_list_item&quot; data-visible=&quot;none&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;sub-level-1&quot; class=&quot;sub_group_2 sub-level-1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;group_3&quot; class=&quot;group_list_item&quot; data-visible=&quot;none&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;sub-level-1&quot; class=&quot;sub_group_3 sub-level-1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &#60;/div&#62; &nbsp;</div><div class="code_line">&#60;/div&#62;</div></ol></div></div></div></div><br>
<br>
Теперь суть вопроса, необходимо выводить сначала группы, а после них их подгруппы.<br>
в таком виде :<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&nbsp;&nbsp; &#60;div class=&quot;sub-main&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;group_1&quot; class=&quot;group_list_item&quot; data-visible=&quot;none&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;group_2&quot; class=&quot;group_list_item&quot; data-visible=&quot;none&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;group_3&quot; class=&quot;group_list_item&quot; data-visible=&quot;none&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;sub-level-1&quot; class=&quot;sub_group_1 sub-level-1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62; &nbsp; </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;sub-level-1&quot; class=&quot;sub_group_2 sub-level-1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;div id=&quot;sub-level-1&quot; class=&quot;sub_group_3 sub-level-1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/div&#62; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &#60;/div&#62;</div></ol></div></div></div></div><br>
<br>
Подскажите пожалуйста, как это сделать?]]></description>
        <author>Mcross</author>
        <category>XML, XSL, XSLT</category>
      </item>
	
      </channel>
      </rss>
	