V
V
Vanes Ri_Lax2015-10-13 08:58:02
PHP
Vanes Ri_Lax, 2015-10-13 08:58:02

Who worked with infogroups in hostcms?

Hello! I have an IP "news" in it there are information groups that have the following structure:
1 inf group 1
1.1 inf group 2
2 inf group 3
2.1 inf group 4
2.2 inf group 5
2.2.1 inf group 6
3 inf group 7
How I have to compose an xsl template in such a way that I get the following structure:

<ul>
    <li>инф группа 1</li>
    <li>
       <ul>
           <li>инф группа 2</li>
        </ul>
    </li>
    <li>инф группа 3</li>
    <li>
       <ul>
           <li>инф группа 4</li>
            <li>инф группа 5</li>
            <li>
               <ul>
                   <li>инф группа 6</li>
                </ul>
            </li>
        </ul>
    </li>
    <li>инф группа 7</li>
</ul>

Please help, I've been scratching my head over this for a week now.

Answer the question

In order to leave comments, you need to log in

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

XML:

<informationsystem>
<informationsystem_group>
  <name>name1</name>
  <informationsystem_group>
    <name>name2</name>
    <informationsystem_group>
      <name>name3</name>
    </informationsystem_group>
  </informationsystem_group>
</informationsystem_group>
<informationsystem_group>
  <name>name4</name>
  <informationsystem_group>
    <name>name5</name>
  </informationsystem_group>
  <informationsystem_group>
    <name>name6</name>
  </informationsystem_group>
  <informationsystem_group>
    <name>name7</name>
  </informationsystem_group>
  <informationsystem_group>
    <name>name8</name>
  </informationsystem_group>
</informationsystem_group>
<informationsystem_group>
  <name>name9</name>
  <informationsystem_group>
    <name>name10</name>
  </informationsystem_group>
  <informationsystem_group>
    <name>name11</name>
  </informationsystem_group>
</informationsystem_group>
</informationsystem>

XSLt:
<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:if test="count(informationsystem_group) &gt; 0">
      <li>
        <ul>
          <xsl:apply-templates select="informationsystem_group"/>
        </ul>
      </li>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

result:
<ul>
   <li>name1</li>
   <li>
      <ul>
         <li>name2</li>
         <li>
            <ul>
               <li>name3</li>
            </ul>
         </li>
      </ul>
   </li>
   <li>name4</li>
   <li>
      <ul>
         <li>name5</li>
         <li>name6</li>
         <li>name7</li>
         <li>name8</li>
      </ul>
   </li>
   <li>name9</li>
   <li>
      <ul>
         <li>name10</li>
         <li>name11</li>
      </ul>
   </li>
</ul>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question