Пример:
1.Создаю доп свойства для товара и включаю для Подгруппы1, в это свойства записывается значение по умолчанию.
2.Потом я решаю, что для Подгруппы1 это свойство больше не нужно и отключаю его.
3. Но как оказалось в базе запись не удаляется и у всех товаров есть это доп свойство.
4. Все бы ничего, но в стандартном шаблоне сравнение товаров выводятся все свойства даже отключенные.
Вопрос! Как в XSL выводить только активные свойства, а еще лучше удалить записи с базы?
шаблон:
<?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">
<h1 class="item_title">Сравнение товаров</h1>
<div class="table-responsive">
<table class="table">
<tr>
<th class="success">Название</th>
<xsl:apply-templates select="comparing/shop_item" mode="name"/>
</tr>
<tr>
<!-- <th>Фото</th> -->
<th></th>
<xsl:apply-templates select="comparing/shop_item" mode="image"/>
</tr>
<tr>
<th class="danger">Цена</th>
<xsl:apply-templates select="comparing/shop_item" mode="price"/>
</tr>
<tr>
<th>Вес</th>
<xsl:apply-templates select="comparing/shop_item" mode="weight"/>
</tr>
<tr>
<th>Производитель</th>
<xsl:apply-templates select="comparing/shop_item" mode="shop_producer"/>
</tr>
<tr>
<th>Описание</th>
<xsl:apply-templates select="comparing/shop_item" mode="text"/>
</tr>
<xsl:apply-templates select="shop_item_properties//property"/>
<tr>
<th>
<!-- Сравнить -->
</th>
<xsl:apply-templates select="comparing/shop_item" mode="comparing"/>
</tr>
</table>
</div>
</xsl:template>
<!-- Шаблон, формирующий свойства -->
<xsl:template match="property">
<!-- Есть хотя бы одно значение свойства -->
<xsl:variable name="property_id" select="@id" />
<xsl:if test="count(/shop/comparing/shop_item/property_value[property_id=$property_id][not(file/node()) and value != '' or file != ''])">
<tr>
<th>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</th>
<xsl:apply-templates select="/shop/comparing/shop_item" mode="property">
<!-- Передаем через параметр ID свойства -->
<xsl:with-param name="property_id" select="@id"/>
</xsl:apply-templates>
</tr>
</xsl:if>
</xsl:template>
<!-- Шаблон, формирующий значения свойств -->
<xsl:template match="shop_item" mode="property">
<!-- Принимаем параметр - ID свойства -->
<xsl:param name="property_id"/>
<td class="compare{@id}">
<xsl:choose>
<xsl:when test="count(property_value[property_id=$property_id])">
<xsl:apply-templates select="property_value[property_id=$property_id]" />
</xsl:when>
<xsl:otherwise>—</xsl:otherwise>
</xsl:choose>
</td>
</xsl:template>
<!-- Шаблон вывода значений свойств -->
<xsl:template match="property_value">
<xsl:choose>
<xsl:when test="not(file)">
<xsl:value-of disable-output-escaping="yes" select="value"/>
</xsl:when>
<xsl:when test="file/node()">
<a target="_blank" href="{../dir}{file}"><img src="{../dir}{file}" alt="{name}" style="width: 100px;" /><!--<xsl:value-of disable-output-escaping="yes" select="file_name"/>--></a>
</xsl:when>
</xsl:choose>
<xsl:if test="position() != last()">, </xsl:if>
</xsl:template>
<!-- Шаблон, формирующий названия товаров -->
<xsl:template match="comparing/shop_item" mode="name">
<td class="compare{@id} success">
<a href="{url}" title="{name}">
<xsl:value-of disable-output-escaping="yes" select="name"/>
</a>
</td>
</xsl:template>
<!-- Шаблон, формирующий изображения товаров -->
<xsl:template match="comparing/shop_item" mode="image">
<td class="compare{@id}">
<!-- Изображение для товара, если есть -->
<xsl:choose>
<xsl:when test="image_small != ''">
<img src="{dir}{image_small}" alt="{name}" title="{name}"/>
</xsl:when>
<xsl:otherwise>
<img src="/images/no-image.png" alt="{name}" title="{name}"/>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:template>
<!-- Шаблон, формирующий цены товаров -->
<xsl:template match="comparing/shop_item" mode="price">
<th class="compare{@id} danger">
<xsl:value-of select="price"/><xsl:text> </xsl:text><xsl:value-of select="currency" disable-output-escaping="yes" />
</th>
</xsl:template>
<!-- Шаблон, формирующий вес товаров -->
<xsl:template match="comparing/shop_item" mode="weight">
<td class="compare{@id}">
<xsl:if test="weight > 0">
<xsl:value-of select="weight"/><xsl:text> </xsl:text><xsl:value-of select="/shop/shop_measure/name"/>
</xsl:if>
</td>
</xsl:template>
<!-- Шаблон, формирующий производителей товаров -->
<xsl:template match="comparing/shop_item" mode="shop_producer">
<td class="compare{@id}">
<xsl:value-of select="shop_producer/name" disable-output-escaping="yes"/>
</td>
</xsl:template>
<!-- Шаблон, формирующий подробную информацию о товаре -->
<xsl:template match="comparing/shop_item" mode="text">
<td class="compare{@id}">
<xsl:value-of select="description" disable-output-escaping="yes" />
</td>
</xsl:template>
<!-- Шаблон, отображающий ссылки на удаление из списка сравнения -->
<xsl:template match="comparing/shop_item" mode="comparing">
<td class="compare{@id}">
<button class="btn btn-effect btn-primary" type="button" onclick="$('.compare{@id}').hide('slow'); return $.addCompare('{/shop/url}', {@id}, this);">Удалить</button>
</td>
</xsl:template>
</xsl:stylesheet>