<?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="/informationsystem">
<!-- <ul>
<xsl:for-each select="informationsystem_item">
<li>
<xsl:value-of select="name" disable-output-escaping="yes"/>
<text> - </text>
<xsl:call-template name="calculate-day-of-the-week">
<xsl:with-param name="value" select="date" />
</xsl:call-template>
</xsl:for-each>
</ul> -->
<xsl:call-template name="calculate-day-of-the-week">
<xsl:with-param name="value">01.10.2015</xsl:with-param>
</xsl:call-template>
<br/>
<xsl:call-template name="calculate-day-of-the-week">
<xsl:with-param name="value">01.10.2015 03:12:13</xsl:with-param>
</xsl:call-template>
<br/>
<xsl:call-template name="calculate-day-of-the-week">
<xsl:with-param name="value">2015-10-01 03:12:13</xsl:with-param>
</xsl:call-template>
<br/>
</xsl:template>
<xsl:template name="calculate-day-of-the-week">
<xsl:param name="value"/>
<!-- Примеры входных значений:
<date>01.10.2015</date>
<datetime>01.10.2015 09:56:53</datetime>
<start_datetime>0000-00-00 00:00:00</start_datetime>
<end_datetime>0000-00-00 00:00:00</end_datetime>
-->
<!-- Приводим входное значение к формату ГГГГММДД -->
<xsl:variable name="date">
<xsl:choose>
<!-- start_datetime или end_datetime -->
<xsl:when test="contains($value,'-')">
<!-- очищаем от разделителей '-' -->
<xsl:value-of select="translate($value,'-','')"/>
</xsl:when>
<!-- date или datetime -->
<xsl:otherwise>
<!-- выделяем дату и очищаем от разделителей '.' -->
<xsl:variable name="date-reverse" select="translate($value,'.','')"/>
<!-- т.к. в данном случае дата имеет обратный порядок (ДД.ММ.ГГГГ), то "перевернем" ее -->
<xsl:value-of select="concat(substring($date-reverse,5,4), concat(substring($date-reverse,3,2), substring($date-reverse,1,2)))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="year" select="substring($date,1,4)"/>
<xsl:variable name="month" select="substring($date,5,2)"/>
<xsl:variable name="day" select="substring($date,7,2)"/>
<xsl:variable name="a" select="floor((14 - $month) div 12)"/>
<xsl:variable name="y" select="$year - $a"/>
<xsl:variable name="m" select="$month + 12 * $a - 2"/>
<xsl:variable name="day-of-week" select="($day + $y + floor($y div 4) - floor($y div 100)
+ floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>
<!-- Нумерация дней недели начинается с воскресенья -->
<xsl:choose>
<xsl:when test="$day-of-week = 0">Воскресенье</xsl:when>
<xsl:when test="$day-of-week = 1">Понедельник</xsl:when>
<xsl:when test="$day-of-week = 2">Вторник</xsl:when>
<xsl:when test="$day-of-week = 3">Среда</xsl:when>
<xsl:when test="$day-of-week = 4">Четверг</xsl:when>
<xsl:when test="$day-of-week = 5">Пятница</xsl:when>
<xsl:otherwise>Суббота</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>