Как правильно составить XSL шаблон?

Здравствуйте,
у меня такая структура:
1 инф группа 1
	1.1 инф группа 2
2 инф группа 3
	2.1 инф группа 4
	2.2 инф группа 5
		2.2.1 инф группа 6
3 инф группа 7

В итоге у меня получилась вот такая XML:
<informationsystem id="31">
	<informationsystem_dir_id>0</informationsystem_dir_id>
	<structure_id>166</structure_id>
	<site_id>6</site_id>
	<name>Тестовая</name>
	<description></description>
	<items_sorting_direction>0</items_sorting_direction>
	<items_sorting_field>0</items_sorting_field>
	<groups_sorting_direction>0</groups_sorting_direction>
	<groups_sorting_field>0</groups_sorting_field>
	<image_large_max_width>300</image_large_max_width>
	<image_large_max_height>300</image_large_max_height>
	<image_small_max_width>70</image_small_max_width>
	<image_small_max_height>70</image_small_max_height>
	<siteuser_group_id>0</siteuser_group_id>
	<use_captcha>1</use_captcha>
	<watermark_file></watermark_file>
	<watermark_default_use_large_image>0</watermark_default_use_large_image>
	<watermark_default_use_small_image>0</watermark_default_use_small_image>
	<watermark_default_position_x>50%</watermark_default_position_x>
	<watermark_default_position_y>100%</watermark_default_position_y>
	<user_id>19</user_id>
	<items_on_page>10</items_on_page>
	<format_date>%d.%m.%Y</format_date>
	<format_datetime>%d.%m.%Y %H:%M:%S</format_datetime>
	<url_type>1</url_type>
	<typograph_default_items>0</typograph_default_items>
	<typograph_default_groups>0</typograph_default_groups>
	<apply_tags_automatically>1</apply_tags_automatically>
	<change_filename>1</change_filename>
	<apply_keywords_automatically>1</apply_keywords_automatically>
	<group_image_large_max_width>300</group_image_large_max_width>
	<group_image_large_max_height>300</group_image_large_max_height>
	<group_image_small_max_width>70</group_image_small_max_width>
	<group_image_small_max_height>70</group_image_small_max_height>
	<preserve_aspect_ratio>1</preserve_aspect_ratio>
	<preserve_aspect_ratio_small>1</preserve_aspect_ratio_small>
	<preserve_aspect_ratio_group>1</preserve_aspect_ratio_group>
	<preserve_aspect_ratio_group_small>1</preserve_aspect_ratio_group_small>
	<url>/for-tests/</url>
	<captcha_id>19372</captcha_id>
	<items_count>0</items_count>
	<items_total_count>0</items_total_count>
	<subgroups_count>3</subgroups_count>
	<subgroups_total_count>7</subgroups_total_count>
	<siteuser_id>0</siteuser_id>
	<group>0</group>
	<page>0</page>
	<part>0</part>
	<limit>99</limit>
	<total>0</total>
	<informationsystem_group id="16">
		<informationsystem_id>31</informationsystem_id>
		<siteuser_id>0</siteuser_id>
		<parent_id>0</parent_id>
		<top_parent_id>0</top_parent_id>
		<name>Тест 1</name>
		<description></description>
		<sorting>0</sorting>
		<path>test-1</path>
		<image_large></image_large>
		<image_small></image_small>
		<indexing>1</indexing>
		<subgroups_count>1</subgroups_count>
		<subgroups_total_count>1</subgroups_total_count>
		<items_count>0</items_count>
		<items_total_count>0</items_total_count>
		<seo_title></seo_title>
		<seo_description></seo_description>
		<seo_keywords></seo_keywords>
		<siteuser_group_id>-1</siteuser_group_id>
		<active>1</active>
		<user_id>19</user_id>
		<sns_type_id>0</sns_type_id>
		<url>/for-tests/test-1/</url>
		<dir>/upload/information_system_31/0/1/6/group_16/</dir>
		<informationsystem_group id="21">
			<informationsystem_id>31</informationsystem_id>
			<siteuser_id>0</siteuser_id>
			<parent_id>16</parent_id>
			<top_parent_id>0</top_parent_id>
			<name>Тест 2</name>
			<description></description>
			<sorting>0</sorting>
			<path>test-2</path>
			<image_large></image_large>
			<image_small></image_small>
			<indexing>1</indexing>
			<subgroups_count>0</subgroups_count>
			<subgroups_total_count>0</subgroups_total_count>
			<items_count>0</items_count>
			<items_total_count>0</items_total_count>
			<seo_title></seo_title>
			<seo_description></seo_description>
			<seo_keywords></seo_keywords>
			<siteuser_group_id>-1</siteuser_group_id>
			<active>1</active>
			<user_id>19</user_id>
			<sns_type_id>0</sns_type_id>
			<url>/for-tests/test-1/test-2/</url>
			<dir>/upload/information_system_31/0/2/1/group_21/</dir>
		</informationsystem_group>
	</informationsystem_group>
	<informationsystem_group id="26">
		<informationsystem_id>31</informationsystem_id>
		<siteuser_id>0</siteuser_id>
		<parent_id>0</parent_id>
		<top_parent_id>0</top_parent_id>
		<name>тест 3</name>
		<description></description>
		<sorting>0</sorting>
		<path>test-3</path>
		<image_large></image_large>
		<image_small></image_small>
		<indexing>1</indexing>
		<subgroups_count>3</subgroups_count>
		<subgroups_total_count>3</subgroups_total_count>
		<items_count>0</items_count>
		<items_total_count>0</items_total_count>
		<seo_title></seo_title>
		<seo_description></seo_description>
		<seo_keywords></seo_keywords>
		<siteuser_group_id>-1</siteuser_group_id>
		<active>1</active>
		<user_id>19</user_id>
		<sns_type_id>0</sns_type_id>
		<url>/for-tests/test-3/</url>
		<dir>/upload/information_system_31/0/2/6/group_26/</dir>
		<informationsystem_group id="31">
			<informationsystem_id>31</informationsystem_id>
			<siteuser_id>0</siteuser_id>
			<parent_id>26</parent_id>
			<top_parent_id>0</top_parent_id>
			<name>тест 4</name>
			<description></description>
			<sorting>0</sorting>
			<path>test-4</path>
			<image_large></image_large>
			<image_small></image_small>
			<indexing>1</indexing>
			<subgroups_count>0</subgroups_count>
			<subgroups_total_count>0</subgroups_total_count>
			<items_count>0</items_count>
			<items_total_count>0</items_total_count>
			<seo_title></seo_title>
			<seo_description></seo_description>
			<seo_keywords></seo_keywords>
			<siteuser_group_id>-1</siteuser_group_id>
			<active>1</active>
			<user_id>19</user_id>
			<sns_type_id>0</sns_type_id>
			<url>/for-tests/test-3/test-4/</url>
			<dir>/upload/information_system_31/0/3/1/group_31/</dir>
		</informationsystem_group>
		<informationsystem_group id="36">
			<informationsystem_id>31</informationsystem_id>
			<siteuser_id>0</siteuser_id>
			<parent_id>26</parent_id>
			<top_parent_id>0</top_parent_id>
			<name>тест 5</name>
			<description></description>
			<sorting>0</sorting>
			<path>test-5</path>
			<image_large></image_large>
			<image_small></image_small>
			<indexing>1</indexing>
			<subgroups_count>1</subgroups_count>
			<subgroups_total_count>1</subgroups_total_count>
			<items_count>0</items_count>
			<items_total_count>0</items_total_count>
			<seo_title></seo_title>
			<seo_description></seo_description>
			<seo_keywords></seo_keywords>
			<siteuser_group_id>-1</siteuser_group_id>
			<active>1</active>
			<user_id>19</user_id>
			<sns_type_id>0</sns_type_id>
			<url>/for-tests/test-3/test-5/</url>
			<dir>/upload/information_system_31/0/3/6/group_36/</dir>
			<informationsystem_group id="41">
				<informationsystem_id>31</informationsystem_id>
				<siteuser_id>0</siteuser_id>
				<parent_id>36</parent_id>
				<top_parent_id>0</top_parent_id>
				<name>тест 6</name>
				<description></description>
				<sorting>0</sorting>
				<path>test-6</path>
				<image_large></image_large>
				<image_small></image_small>
				<indexing>1</indexing>
				<subgroups_count>0</subgroups_count>
				<subgroups_total_count>0</subgroups_total_count>
				<items_count>0</items_count>
				<items_total_count>0</items_total_count>
				<seo_title></seo_title>
				<seo_description></seo_description>
				<seo_keywords></seo_keywords>
				<siteuser_group_id>-1</siteuser_group_id>
				<active>1</active>
				<user_id>19</user_id>
				<sns_type_id>0</sns_type_id>
				<url>/for-tests/test-3/test-5/test-6/</url>
				<dir>/upload/information_system_31/0/4/1/group_41/</dir>
			</informationsystem_group>
		</informationsystem_group>
	</informationsystem_group>
	<informationsystem_group id="46">
		<informationsystem_id>31</informationsystem_id>
		<siteuser_id>0</siteuser_id>
		<parent_id>0</parent_id>
		<top_parent_id>0</top_parent_id>
		<name>тест 7</name>
		<description></description>
		<sorting>0</sorting>
		<path>test-7</path>
		<image_large></image_large>
		<image_small></image_small>
		<indexing>1</indexing>
		<subgroups_count>0</subgroups_count>
		<subgroups_total_count>0</subgroups_total_count>
		<items_count>0</items_count>
		<items_total_count>0</items_total_count>
		<seo_title></seo_title>
		<seo_description></seo_description>
		<seo_keywords></seo_keywords>
		<siteuser_group_id>-1</siteuser_group_id>
		<active>1</active>
		<user_id>19</user_id>
		<sns_type_id>0</sns_type_id>
		<url>/for-tests/test-7/</url>
		<dir>/upload/information_system_31/0/4/6/group_46/</dir>
	</informationsystem_group>
</informationsystem>

Вопрос, как мне правильно составить XSL шаблон чтобы я мог пробежаться по всем вложенным группам?
Сколько будет вложений заранее неизвестно.
В каждой родительской группе есть поле subgroups_count, в котором хранится число дочерних подгрупп.
Я не силен в XSL, подскажите пожалуйста, как это можно реализовать.
Заранее большое спасибо!
  • Вопрос задан
  • 223 просмотра
Пригласить эксперта
Ответы на вопрос 1
@Roman-Fov
Вопрос, как мне правильно составить XSL шаблон чтобы я мог пробежаться по всем вложенным группам?


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" encoding="utf-8" version="1.0"/>

	<xsl:template match="/informationsystem">
		<xsl:if test="count(informationsystem_group) &gt; 0">
			<ul>
				<xsl:apply-templates select="//informationsystem_group"/>
			</ul>
		</xsl:if>
	</xsl:template>

	<xsl:template match="informationsystem_group">
		<li>
			<xsl:value-of select="name"/>
		</li>
	</xsl:template>
</xsl:stylesheet>
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы