Доработка корзины
как в xsl правильно сделать переменную, которая правильно выводит окончание в зависимости от количества заказанных товаров (1 единиц-а, 2,3,4 единиц-ы, 5 (и тд) единиц?)
то есть как взять последнюю цифру в totalquantity, и в зависимости от нее вывести окончание
проблема с составлением условий в xsl)
то есть как взять последнюю цифру в totalquantity, и в зависимости от нее вывести окончание
проблема с составлением условий в xsl)
<xsl:variable name="word"><xsl:choose>
<xsl:when test="..">единица</xsl:when>
<xsl:when test="..">единицы</xsl:when>
<xsl:when test="..">единиц</xsl:when>
</xsl:choose></xsl:variable>
<xsl:when test="..">единица</xsl:when>
<xsl:when test="..">единицы</xsl:when>
<xsl:when test="..">единиц</xsl:when>
</xsl:choose></xsl:variable>
h4mpy,
пример новой краткой корзины:
пример новой краткой корзины:
<?xml version="1.0" encoding="windows-1251"?>
<!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="Windows-1251" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml" />
<xsl:template match="/cart">
<div id="little_cart">
<xsl:choose>
<!-- Магазин не найден -->
<xsl:when test="error_not_isset_shop/node()">
<p>
<b>Ошибка! Магазин с указанным идентификатором не найден!</b>
<br/>
Укажите правильный код магазина!
</p>
</xsl:when>
<!-- Магазин найден -->
<xsl:otherwise>
<xsl:choose>
<!-- В корзине нет ни одного элемента -->
<xsl:when test="totalquantity = 0">
<h2>Корзина пуста</h2>
<xsl:choose>
<xsl:when test="site_users_class_exists = 1 and user_id = 0">
<p>Если Вы зарегистрированный пользователь, данные Вашей корзины станут видны после авторизации.</p>
</xsl:when>
<xsl:otherwise>
Перейдите в каталог, выберите требуемый товар и добавьте его в корзину.
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<h2>Моя корзина</h2>
<!-- Вывод общих количества, веса и стоимости товаров -->
<p>
В корзине <b><xsl:value-of select="totalquantity"/></b> <xsl:call-template
name="declension">
<xsl:with-param name="number" select="totalquantity" />
</xsl:call-template>
<br />
на сумму <b><xsl:value-of select="totalsum"/> <xsl:value-of disable-output-escaping="yes" select="shop/shop_currency/shop_currency_name"/></b>
</p>
<xsl:if test="totalweight > 0">
<p>
Общий вес заказа <b><xsl:value-of select="totalweight"/> <xsl:value-of select="shop/shop_mesures_name"/></b>
</p>
</xsl:if>
<p><a href="{/cart/shop/path}cart/">Перейти в корзину</a></p>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
<!-- Склонение после числительных -->
<xsl:template name="declension">
<xsl:param name="number" select="number" />
<!-- Именительный падеж -->
<xsl:variable name="nominative">
<xsl:text>товар</xsl:text>
</xsl:variable>
<!-- Родительный падеж, единственное число -->
<xsl:variable name="genitive_singular">
<xsl:text>товара</xsl:text>
</xsl:variable>
<xsl:variable name="genitive_plural">
<xsl:text>товаров</xsl:text>
</xsl:variable>
<xsl:variable name="last_digit">
<xsl:value-of select="$number mod 10"/>
</xsl:variable>
<xsl:variable name="last_two_digits">
<xsl:value-of select="$number mod 100"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$last_digit = 1 and $last_two_digits != 11">
<xsl:value-of select="$nominative"/>
</xsl:when>
<xsl:when test="$last_digit = 2 and $last_two_digits != 12
or
$last_digit = 3 and $last_two_digits != 13
or
$last_digit = 4 and $last_two_digits != 14">
<xsl:value-of select="$genitive_singular"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$genitive_plural"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<!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="Windows-1251" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml" />
<xsl:template match="/cart">
<div id="little_cart">
<xsl:choose>
<!-- Магазин не найден -->
<xsl:when test="error_not_isset_shop/node()">
<p>
<b>Ошибка! Магазин с указанным идентификатором не найден!</b>
<br/>
Укажите правильный код магазина!
</p>
</xsl:when>
<!-- Магазин найден -->
<xsl:otherwise>
<xsl:choose>
<!-- В корзине нет ни одного элемента -->
<xsl:when test="totalquantity = 0">
<h2>Корзина пуста</h2>
<xsl:choose>
<xsl:when test="site_users_class_exists = 1 and user_id = 0">
<p>Если Вы зарегистрированный пользователь, данные Вашей корзины станут видны после авторизации.</p>
</xsl:when>
<xsl:otherwise>
Перейдите в каталог, выберите требуемый товар и добавьте его в корзину.
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<h2>Моя корзина</h2>
<!-- Вывод общих количества, веса и стоимости товаров -->
<p>
В корзине <b><xsl:value-of select="totalquantity"/></b> <xsl:call-template
name="declension">
<xsl:with-param name="number" select="totalquantity" />
</xsl:call-template>
<br />
на сумму <b><xsl:value-of select="totalsum"/> <xsl:value-of disable-output-escaping="yes" select="shop/shop_currency/shop_currency_name"/></b>
</p>
<xsl:if test="totalweight > 0">
<p>
Общий вес заказа <b><xsl:value-of select="totalweight"/> <xsl:value-of select="shop/shop_mesures_name"/></b>
</p>
</xsl:if>
<p><a href="{/cart/shop/path}cart/">Перейти в корзину</a></p>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
<!-- Склонение после числительных -->
<xsl:template name="declension">
<xsl:param name="number" select="number" />
<!-- Именительный падеж -->
<xsl:variable name="nominative">
<xsl:text>товар</xsl:text>
</xsl:variable>
<!-- Родительный падеж, единственное число -->
<xsl:variable name="genitive_singular">
<xsl:text>товара</xsl:text>
</xsl:variable>
<xsl:variable name="genitive_plural">
<xsl:text>товаров</xsl:text>
</xsl:variable>
<xsl:variable name="last_digit">
<xsl:value-of select="$number mod 10"/>
</xsl:variable>
<xsl:variable name="last_two_digits">
<xsl:value-of select="$number mod 100"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$last_digit = 1 and $last_two_digits != 11">
<xsl:value-of select="$nominative"/>
</xsl:when>
<xsl:when test="$last_digit = 2 and $last_two_digits != 12
or
$last_digit = 3 and $last_two_digits != 13
or
$last_digit = 4 and $last_two_digits != 14">
<xsl:value-of select="$genitive_singular"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$genitive_plural"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Авторизация