V
V
Vanes Ri_Lax2015-10-14 08:21:59
XSL & XSLT
Vanes Ri_Lax, 2015-10-14 08:21:59

How to compose an XSL template correctly?

Hello,
I have the following structure:

1 инф группа 1
  1.1 инф группа 2
2 инф группа 3
  2.1 инф группа 4
  2.2 инф группа 5
    2.2.1 инф группа 6
3 инф группа 7

As a result, I got this 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>

The question is, how do I correctly compose the XSL template so that I can go over all the nested groups?
How much will be invested is not known in advance.
Each parent group has a subgroups_count field that stores the number of child subgroups.
I'm not strong in XSL, please tell me how this can be implemented.
Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Fov, 2018-11-04
@Roman-Fov

The question is, how do I correctly compose the XSL template so that I can go over all the nested groups?

<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>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question