Выделение пункта меню (группа информ системы)
Все, разобралась... Дело было не в этом. Если кому интересно — вот рабочий шаблон для меню с подуровнями:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output xmlns="http://www.w3.org/TR/xhtml1/strict" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" encoding="utf-8" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml"/>
<!-- ЛевоеМеню -->
<xsl:template match="/document">
<xsl:if test="count(structure[show=1]) > 0">
<ul>
<!-- Выбираем узлы структуры первого уровня -->
<xsl:apply-templates select="structure[show=1]"/>
</ul>
</xsl:if>
</xsl:template>
<xsl:template match="structure">
<!-- Запишем в константу ID структуры, данные для которой будут выводиться пользователю -->
<xsl:variable name="current_structure_id">
<xsl:choose>
<xsl:when test="/document/item/node()">item_<xsl:value-of select="/document/item"/></xsl:when>
<xsl:when test="/document/group/node()">group_<xsl:value-of select="/document/group"/></xsl:when>
<xsl:otherwise>
<xsl:value-of select="structure/current_structure_id"/>
</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}">
<!--
Выделяем текущую страницу добавлением к <a> стиля font-weight: bold,
если это текущая страница, либо у нее есть ребенок с атрибутом id, равным текущей uheggt.
-->
<xsl:if test="$current_structure_id = @id">
<xsl:attribute name="style">font-weight: bold</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</a>
</xsl:when>
<!-- Если не показывать ссылку - выводим просто имя ссылки -->
<xsl:otherwise>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</xsl:otherwise>
</xsl:choose>
<!-- Выбираем подузлы структуры -->
<xsl:if test="count(structure[show=1]) > 0">
<ul>
<!-- Выбираем узлы структуры -->
<xsl:apply-templates select="structure[show=1]" mode="submenu"/>
</ul>
</xsl:if>
</li>
</xsl:template>
<xsl:template match="structure" mode="submenu">
<!-- Запишем в константу ID структуры, данные для которой будут выводиться пользователю -->
<xsl:variable name="current_structure_id">
<xsl:choose>
<xsl:when test="/document/item/node()">item_<xsl:value-of select="/document/item"/></xsl:when>
<xsl:when test="/document/group/node()">group_<xsl:value-of select="/document/group"/></xsl:when>
<xsl:otherwise>
<xsl:value-of select="structure/current_structure_id"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<li>
<!-- Показывать ссылку, или нет -->
<xsl:if 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}">
<!--
Выделяем текущую страницу добавлением к <a> стиля font-weight: bold,
если это текущая страница, либо у нее есть ребенок с атрибутом id, равным текущей uheggt.
-->
<xsl:if test="$current_structure_id = @id">
<xsl:attribute name="style">font-weight: bold</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</a>
</xsl:if>
<xsl:if test="count(structure[show = 1]) > 0">
<ul>
<xsl:apply-templates select="structure[show=1]" mode="submenu"/>
</ul>
</xsl:if>
<!-- Если не показывать ссылку - выводим просто имя ссылки -->
<xsl:if test="show_link=0">
<xsl:value-of disable-output-escaping="yes" select="name"/>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output xmlns="http://www.w3.org/TR/xhtml1/strict" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" encoding="utf-8" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml"/>
<!-- ЛевоеМеню -->
<xsl:template match="/document">
<xsl:if test="count(structure[show=1]) > 0">
<ul>
<!-- Выбираем узлы структуры первого уровня -->
<xsl:apply-templates select="structure[show=1]"/>
</ul>
</xsl:if>
</xsl:template>
<xsl:template match="structure">
<!-- Запишем в константу ID структуры, данные для которой будут выводиться пользователю -->
<xsl:variable name="current_structure_id">
<xsl:choose>
<xsl:when test="/document/item/node()">item_<xsl:value-of select="/document/item"/></xsl:when>
<xsl:when test="/document/group/node()">group_<xsl:value-of select="/document/group"/></xsl:when>
<xsl:otherwise>
<xsl:value-of select="structure/current_structure_id"/>
</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}">
<!--
Выделяем текущую страницу добавлением к <a> стиля font-weight: bold,
если это текущая страница, либо у нее есть ребенок с атрибутом id, равным текущей uheggt.
-->
<xsl:if test="$current_structure_id = @id">
<xsl:attribute name="style">font-weight: bold</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</a>
</xsl:when>
<!-- Если не показывать ссылку - выводим просто имя ссылки -->
<xsl:otherwise>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</xsl:otherwise>
</xsl:choose>
<!-- Выбираем подузлы структуры -->
<xsl:if test="count(structure[show=1]) > 0">
<ul>
<!-- Выбираем узлы структуры -->
<xsl:apply-templates select="structure[show=1]" mode="submenu"/>
</ul>
</xsl:if>
</li>
</xsl:template>
<xsl:template match="structure" mode="submenu">
<!-- Запишем в константу ID структуры, данные для которой будут выводиться пользователю -->
<xsl:variable name="current_structure_id">
<xsl:choose>
<xsl:when test="/document/item/node()">item_<xsl:value-of select="/document/item"/></xsl:when>
<xsl:when test="/document/group/node()">group_<xsl:value-of select="/document/group"/></xsl:when>
<xsl:otherwise>
<xsl:value-of select="structure/current_structure_id"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<li>
<!-- Показывать ссылку, или нет -->
<xsl:if 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}">
<!--
Выделяем текущую страницу добавлением к <a> стиля font-weight: bold,
если это текущая страница, либо у нее есть ребенок с атрибутом id, равным текущей uheggt.
-->
<xsl:if test="$current_structure_id = @id">
<xsl:attribute name="style">font-weight: bold</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</a>
</xsl:if>
<xsl:if test="count(structure[show = 1]) > 0">
<ul>
<xsl:apply-templates select="structure[show=1]" mode="submenu"/>
</ul>
</xsl:if>
<!-- Если не показывать ссылку - выводим просто имя ссылки -->
<xsl:if test="show_link=0">
<xsl:value-of disable-output-escaping="yes" select="name"/>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>
http://superweb.pro/ — сайты на HostCMS под ключ
А можно ли сделать, чтобы родительская группа выделялась не только при переходе в элементы в этой группе, но и при переходе во вложенные группы.
Вот этот код рабочий, но в подгруппах родительская группа не выделяется, как исправить?
Вывод:
Вот этот код рабочий, но в подгруппах родительская группа не выделяется, как исправить?
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:hostcms="http://www.hostcms.ru/"
exclude-result-prefixes="hostcms">
<xsl:output xmlns="http://www.w3.org/TR/xhtml1/strict" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" encoding="utf-8" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml"/>
<xsl:template match="/">
<xsl:apply-templates select="document/blocks"/>
</xsl:template>
<!-- Шаблон -->
<xsl:template match="document/blocks">
<xsl:variable name="parent_group_id" select="@current_group_id"/>
<!-- Выводим группы -->
<ul>
<xsl:apply-templates select="//group[@parent_id=0]"/>
</ul>
</xsl:template>
<!-- Шаблон для групп -->
<xsl:template match="group">
<xsl:variable name="current_group_id" select="/document/group"/>
<li>
<xsl:choose>
<xsl:when test="$current_group_id = @id or @current_group_id > 0 ">
<!-- Выделим текущий пункт -->
<xsl:choose>
<xsl:when test="$current_group_id = @id or count(.//group[@id>$current_group_id])=1 ">
<a href="{/document/blocks/url}{fullpath}">
<xsl:attribute name="class">current_m</xsl:attribute>
<xsl:value-of disable-output-escaping="yes" select="name"/></a>
</xsl:when>
<xsl:otherwise>
<a href="{/document/blocks/url}{fullpath}"><xsl:value-of disable-output-escaping="yes" select="name"/></a>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="count_all_groups > 0">
<xsl:apply-templates select="group"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<a href="{/document/blocks/url}{fullpath}"><xsl:value-of disable-output-escaping="yes" select="name"/></a>
</xsl:otherwise>
</xsl:choose>
</li>
</xsl:template>
</xsl:stylesheet>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:hostcms="http://www.hostcms.ru/"
exclude-result-prefixes="hostcms">
<xsl:output xmlns="http://www.w3.org/TR/xhtml1/strict" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" encoding="utf-8" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml"/>
<xsl:template match="/">
<xsl:apply-templates select="document/blocks"/>
</xsl:template>
<!-- Шаблон -->
<xsl:template match="document/blocks">
<xsl:variable name="parent_group_id" select="@current_group_id"/>
<!-- Выводим группы -->
<ul>
<xsl:apply-templates select="//group[@parent_id=0]"/>
</ul>
</xsl:template>
<!-- Шаблон для групп -->
<xsl:template match="group">
<xsl:variable name="current_group_id" select="/document/group"/>
<li>
<xsl:choose>
<xsl:when test="$current_group_id = @id or @current_group_id > 0 ">
<!-- Выделим текущий пункт -->
<xsl:choose>
<xsl:when test="$current_group_id = @id or count(.//group[@id>$current_group_id])=1 ">
<a href="{/document/blocks/url}{fullpath}">
<xsl:attribute name="class">current_m</xsl:attribute>
<xsl:value-of disable-output-escaping="yes" select="name"/></a>
</xsl:when>
<xsl:otherwise>
<a href="{/document/blocks/url}{fullpath}"><xsl:value-of disable-output-escaping="yes" select="name"/></a>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="count_all_groups > 0">
<xsl:apply-templates select="group"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<a href="{/document/blocks/url}{fullpath}"><xsl:value-of disable-output-escaping="yes" select="name"/></a>
</xsl:otherwise>
</xsl:choose>
</li>
</xsl:template>
</xsl:stylesheet>
Вывод:
$InformationSystem = new InformationSystem;
$InformationSystemId = 42;
$result = array();
$result = $InformationSystem->GetInformationFromPath($InformationSystemId);
$external_propertys = array();
$external_propertys['group'] = $result['group'];
$param = array('current_group_id' => 0, 'items_on_page' => 10);
$param['xml_show_group_type'] = 'tree';
$xsl_catalog = 'МенюИС';
$InformationSystem->ShowInformationSystem($InformationSystemId, 0, $xsl_catalog, 10, 0,$external_propertys, $param);
$InformationSystemId = 42;
$result = array();
$result = $InformationSystem->GetInformationFromPath($InformationSystemId);
$external_propertys = array();
$external_propertys['group'] = $result['group'];
$param = array('current_group_id' => 0, 'items_on_page' => 10);
$param['xml_show_group_type'] = 'tree';
$xsl_catalog = 'МенюИС';
$InformationSystem->ShowInformationSystem($InformationSystemId, 0, $xsl_catalog, 10, 0,$external_propertys, $param);
Авторизация