|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
| 3 | + |
| 4 | +<xsl:template name="next-day-date"> |
| 5 | + <xsl:param name="date"/> <!-- format is YYYY-MM-DD --> |
| 6 | + |
| 7 | + <xsl:param name="old_year" select="number(substring($date, 1, 4))"/> |
| 8 | + <xsl:param name="old_month" select="number(substring($date, 6, 2))"/> |
| 9 | + <xsl:param name="old_day" select="number(substring($date, 9, 2))"/> |
| 10 | + |
| 11 | + <xsl:variable name="days-of-month"> |
| 12 | + <xsl:call-template name="days-of-month"> |
| 13 | + <xsl:with-param name="date" select="$date"/> |
| 14 | + </xsl:call-template> |
| 15 | + </xsl:variable> |
| 16 | + |
| 17 | + <xsl:variable name="year"> |
| 18 | + <xsl:choose> |
| 19 | + <xsl:when test="$old_month=12 and $old_day=$days-of-month"> |
| 20 | + <xsl:value-of select="$old_year+1"/> |
| 21 | + </xsl:when> |
| 22 | + <xsl:otherwise> |
| 23 | + <xsl:value-of select="$old_year"/> |
| 24 | + </xsl:otherwise> |
| 25 | + </xsl:choose> |
| 26 | + </xsl:variable> |
| 27 | + |
| 28 | + <xsl:variable name="tmp_month"> |
| 29 | + <xsl:choose> |
| 30 | + <xsl:when test="$year!=$old_year"> |
| 31 | + <xsl:text>1</xsl:text> |
| 32 | + </xsl:when> |
| 33 | + <xsl:when test="$old_day=$days-of-month"> |
| 34 | + <xsl:value-of select="$old_month+1"/> |
| 35 | + </xsl:when> |
| 36 | + <xsl:otherwise> |
| 37 | + <xsl:value-of select="$old_month"/> |
| 38 | + </xsl:otherwise> |
| 39 | + </xsl:choose> |
| 40 | + </xsl:variable> |
| 41 | + |
| 42 | + <xsl:variable name="tmp_day"> |
| 43 | + <xsl:choose> |
| 44 | + <xsl:when test="$tmp_month!=$old_month"> |
| 45 | + <xsl:text>1</xsl:text> |
| 46 | + </xsl:when> |
| 47 | + <xsl:otherwise> |
| 48 | + <xsl:value-of select="$old_day+1"/> |
| 49 | + </xsl:otherwise> |
| 50 | + </xsl:choose> |
| 51 | + </xsl:variable> |
| 52 | + |
| 53 | + <xsl:variable name="month"> |
| 54 | + <xsl:if test="$tmp_month < 10"> |
| 55 | + <xsl:text>0</xsl:text> |
| 56 | + </xsl:if> |
| 57 | + <xsl:value-of select="$tmp_month"/> |
| 58 | + </xsl:variable> |
| 59 | + |
| 60 | + <xsl:variable name="day"> |
| 61 | + <xsl:if test="$tmp_day < 10"> |
| 62 | + <xsl:text>0</xsl:text> |
| 63 | + </xsl:if> |
| 64 | + <xsl:value-of select="$tmp_day"/> |
| 65 | + </xsl:variable> |
| 66 | + |
| 67 | + <xsl:value-of select="$year"/> |
| 68 | + <xsl:text>-</xsl:text> |
| 69 | + <xsl:value-of select="$month"/> |
| 70 | + <xsl:text>-</xsl:text> |
| 71 | + <xsl:value-of select="$day"/> |
| 72 | + |
| 73 | +</xsl:template> |
| 74 | + |
| 75 | + |
| 76 | +<xsl:template name="days-of-month"> |
| 77 | + <xsl:param name="date"/> |
| 78 | + <xsl:param name="month" select="number(substring($date, 6, 2))"/> |
| 79 | + |
| 80 | + <xsl:variable name="is-leap-year"> |
| 81 | + <xsl:call-template name="is-leap-year"> |
| 82 | + <xsl:with-param name="date" select="$date"/> |
| 83 | + </xsl:call-template> |
| 84 | + </xsl:variable> |
| 85 | + |
| 86 | + <xsl:choose> |
| 87 | + <xsl:when test="$month=4 or $month=6 or $month=9 or $month=11"> |
| 88 | + <xsl:text>30</xsl:text> |
| 89 | + </xsl:when> |
| 90 | + <xsl:when test="$month=2 and $is-leap-year"> |
| 91 | + <xsl:text>29</xsl:text> |
| 92 | + </xsl:when> |
| 93 | + <xsl:when test="$month=2"> |
| 94 | + <xsl:text>28</xsl:text> |
| 95 | + </xsl:when> |
| 96 | + <xsl:otherwise> |
| 97 | + <xsl:text>31</xsl:text> |
| 98 | + </xsl:otherwise> |
| 99 | + </xsl:choose> |
| 100 | + |
| 101 | +</xsl:template> |
| 102 | + |
| 103 | +<xsl:template name="is-leap-year"> |
| 104 | + <xsl:param name="date"/> |
| 105 | + <xsl:param name="year" select="substring($date, 1, 4)"/> |
| 106 | + |
| 107 | + <xsl:value-of select="($year mod 4 = 0 and $year mod 100 != 0) or $year mod 400 = 0"/> |
| 108 | + |
| 109 | +</xsl:template> |
| 110 | + |
| 111 | +</xsl:stylesheet> |
0 commit comments