Приветствую.
Хочу для каждого уровня списка выводить равное номеру уровня количество неразрывных пробелов. Поиск в сети выдал некий шаблон "dup", который я довольно бездумно добавил в свой код:
<?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="/shop"/>
</xsl:template>
<!-- Шаблон для магазина -->
<xsl:template match="/shop">
<h4>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</h4>
<ul id="catalog_menu">
<xsl:apply-templates select="shop_group"/>
</ul>
</xsl:template>
<!-- Шаблон для групп товара -->
<xsl:template match="shop_group">
<xsl:variable name="current_group_id" select="/shop/current_group_id"/>
<xsl:variable name="parent_id" select="parent_id"/>
<xsl:variable name="level" select="count(ancestor::shop_group)"/>
<xsl:if test="$parent_id = 0">
<div class="dots" />
</xsl:if>
<li>
<xsl:choose>
<xsl:when test="$current_group_id = @id">
<xsl:call-template name="dup">
<xsl:with-param name="input">_</xsl:with-param>
<xsl:with-param name="count">$level</xsl:with-param>
</xsl:call-template>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="dup">
<xsl:with-param name="input"> </xsl:with-param>
<xsl:with-param name="count">$level</xsl:with-param>
</xsl:call-template>
<a href="{url}" hostcms:id="{@id}" hostcms:field="name" hostcms:entity="shop_group">
<xsl:value-of disable-output-escaping="yes" select="name"/>
</a>
</xsl:otherwise>
</xsl:choose>
<!-- Если есть подгруппы -->
<xsl:if test="shop_group">
<ul id="{@id}">
<xsl:apply-templates select="shop_group"/>
</ul>
</xsl:if>
</li>
</xsl:template>
<xsl:template name="dup">
<xsl:param name="input"/>
<xsl:param name="count" select="2"/>
<xsl:choose>
<xsl:when test="not($count) or not($input)"/>
<xsl:when test="$count = 1">
<xsl:value-of select="$input"/>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$count mod 2">
<xsl:value-of select="$input"/>
</xsl:if>
<xsl:call-template name="dup">
<xsl:with-param name="input"
select="concat($input,$input)"/>
<xsl:with-param name="count"
select="floor($count div 2)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Таки оно не работает. Может быть кто-то подскажет, как надо?