МЕНЮ / Разное

Заметка создана: 14 января 2025 г.
Добавляем класс current
              <!--
                Выделяем текущую страницу добавлением к li класса current,
                если это текущая страница, либо у нее есть ребенок с атрибутом id, равным текущей группе.
                -->
                <xsl:if test="$current_structure_id = @id or count(.//structure[@id=$current_structure_id]) = 1">
                     <xsl:attribute name="class">current</xsl:attribute>
                </xsl:if>
Выделяем стилем вывод текущей позиции
                 <!-- Определяем стиль вывода ссылки -->
                     <xsl:variable name="link_style">
                          <xsl:choose>
                               <!-- Выделяем текущую страницу жирным (если это текущая страница, либо у нее есть ребенок с ID, равным текущей) -->
                <xsl:when test="current_structure_id=@id or count(.//structure[@id=$current_structure_id])=1">color: #fff</xsl:when>
                               <!-- Иначе обычный вывод с пустым стилем -->
                               <xsl:otherwise></xsl:otherwise>
                          </xsl:choose>
                     </xsl:variable> 
Применяем стили к первому и последнему элементу меню
<li>
                <xsl:choose>
                     <xsl:when test="show_link = 1">
                          <!-- Определяем адрес ссылки -->
                          <xsl:variable name="link">
                               <xsl:choose>
                                    <!-- Если внешняя ссылка -->
                                    <xsl:when test="is_external_link = 1">
                                         <xsl:value-of disable-output-escaping="yes" select="external_link"/>
                                    </xsl:when>
                                    <!-- Иначе если внутренняя ссылка -->
                                    <xsl:otherwise>
                                         <xsl:value-of disable-output-escaping="yes" select="link"/>
                                    </xsl:otherwise>
                               </xsl:choose>
                          </xsl:variable>
                          <!-- Ссылка на пункт меню -->
                          <a href="{$link}" title="{name}">
                               <!--
                               Выделяем текущую страницу добавлением к li класса first-current, last-current или current
                               если это текущая страница, либо у нее есть ребенок с атрибутом id, равным текущей.
                               -->
                               <xsl:choose>
                                    <xsl:when test="current_structure_id = @id or count(.//structure[@id=$current_structure_id]) = 1">
                                         <xsl:choose>
                                         <xsl:when test="position()=1"><xsl:attribute name="class">first-current</xsl:attribute></xsl:when>
                                         <xsl:when test="position()=last()"><xsl:attribute name="class">last-current</xsl:attribute></xsl:when>
                                         <xsl:otherwise><xsl:attribute name="class">current</xsl:attribute></xsl:otherwise>
                                         </xsl:choose>
                                    </xsl:when>
                                    <xsl:otherwise>
                                         <xsl:choose>
                                         <xsl:when test="position()=1"><xsl:attribute name="class">first</xsl:attribute></xsl:when>
                                         <xsl:when test="position()=last()"><xsl:attribute name="class">last</xsl:attribute></xsl:when>
                                              <xsl:otherwise></xsl:otherwise>
                                         </xsl:choose>
                                    </xsl:otherwise>
                               </xsl:choose>
                     <em><b><xsl:value-of disable-output-escaping="yes" select="name"/></b></em></a>
                     </xsl:when>
                     <!-- Если не показывать ссылку - выводим просто имя ссылки -->
                     <xsl:otherwise>
                     <em><b><xsl:value-of disable-output-escaping="yes" select="name"/></b></em>
                     </xsl:otherwise>
                </xsl:choose>
           </li>