Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <xsl:stylesheet
- version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="html"/>
- <xsl:template match="/">
- <xsl:variable name="timestamp" select="1507387355"/>
- <p>
- <xsl:call-template name="epochToJST">
- <xsl:with-param name="epoch" select="$timestamp"/>
- </xsl:call-template>
- </p>
- </xsl:template>
- <xsl:template name="epochToJST">
- <xsl:param name="epoch"/>
- <!-- 9 h = JST time shift -->
- <xsl:variable name="e2" select="$epoch + 9 * 60 * 60"/>
- <xsl:variable name="days" select="floor($e2 div (24 * 60 * 60))"/>
- <xsl:variable name="secs" select="$e2 mod (24 * 60 * 60)"/>
- <xsl:variable name="years" select="floor($days div 365)"/>
- <xsl:variable name="year" select="1970 + $years"/>
- <xsl:variable name="one">
- <xsl:choose>
- <xsl:when test="$year mod 4 = 0">
- <xsl:value-of select="1"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="0"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <!-- 1 = first day, (years + 2) / 4 = leap days, one = still not leap day -->
- <xsl:variable name="remainDays" select="1 + $days - $years * 365 - floor(($years + 2) div 4) + $one"/>
- <xsl:variable name="month">
- <xsl:choose>
- <xsl:when test="$remainDays > 334 + $one">
- <xsl:value-of select="12"/>
- </xsl:when>
- <xsl:when test="$remainDays > 304 + $one">
- <xsl:value-of select="11"/>
- </xsl:when>
- <xsl:when test="$remainDays > 273 + $one">
- <xsl:value-of select="10"/>
- </xsl:when>
- <xsl:when test="$remainDays > 243 + $one">
- <xsl:value-of select="9"/>
- </xsl:when>
- <xsl:when test="$remainDays > 212 + $one">
- <xsl:value-of select="8"/>
- </xsl:when>
- <xsl:when test="$remainDays > 181 + $one">
- <xsl:value-of select="7"/>
- </xsl:when>
- <xsl:when test="$remainDays > 151 + $one">
- <xsl:value-of select="6"/>
- </xsl:when>
- <xsl:when test="$remainDays > 120 + $one">
- <xsl:value-of select="5"/>
- </xsl:when>
- <xsl:when test="$remainDays > 90 + $one">
- <xsl:value-of select="4"/>
- </xsl:when>
- <xsl:when test="$remainDays > 59 + $one">
- <xsl:value-of select="3"/>
- </xsl:when>
- <xsl:when test="$remainDays > 31">
- <xsl:value-of select="2"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="1"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="day">
- <xsl:choose>
- <xsl:when test="$remainDays > 334 + $one">
- <xsl:value-of select="$remainDays - 334 - $one"/>
- </xsl:when>
- <xsl:when test="$remainDays > 304 + $one">
- <xsl:value-of select="$remainDays - 304 - $one"/>
- </xsl:when>
- <xsl:when test="$remainDays > 273 + $one">
- <xsl:value-of select="$remainDays - 273 - $one"/>
- </xsl:when>
- <xsl:when test="$remainDays > 243 + $one">
- <xsl:value-of select="$remainDays - 243 - $one"/>
- </xsl:when>
- <xsl:when test="$remainDays > 212 + $one">
- <xsl:value-of select="$remainDays - 212 - $one"/>
- </xsl:when>
- <xsl:when test="$remainDays > 181 + $one">
- <xsl:value-of select="$remainDays - 181 - $one"/>
- </xsl:when>
- <xsl:when test="$remainDays > 151 + $one">
- <xsl:value-of select="$remainDays - 151 - $one"/>
- </xsl:when>
- <xsl:when test="$remainDays > 120 + $one">
- <xsl:value-of select="$remainDays - 120 - $one"/>
- </xsl:when>
- <xsl:when test="$remainDays > 90 + $one">
- <xsl:value-of select="$remainDays - 90 - $one"/>
- </xsl:when>
- <xsl:when test="$remainDays > 59 + $one">
- <xsl:value-of select="$remainDays - 59 - $one"/>
- </xsl:when>
- <xsl:when test="$remainDays > 31">
- <xsl:value-of select="$remainDays - 31"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of name="day" select="$remainDays"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="hour" select="floor($secs div (60 * 60))"/>
- <xsl:variable name="remainSecs" select="$secs mod (60 * 60)"/>
- <xsl:variable name="minute" select="floor($remainSecs div 60)"/>
- <xsl:variable name="sec" select="$remainSecs mod 60"/>
- <xsl:value-of select="$year"/><xsl:text>-</xsl:text>
- <xsl:value-of select="format-number($month, '00')"/><xsl:text>-</xsl:text>
- <xsl:value-of select="format-number($day, '00')"/><xsl:text>T</xsl:text>
- <xsl:value-of select="format-number($hour, '00')"/><xsl:text>:</xsl:text>
- <xsl:value-of select="format-number($minute, '00')"/><xsl:text>:</xsl:text>
- <xsl:value-of select="format-number($sec, '00')"/><xsl:text>+09:00</xsl:text>
- </xsl:template>
- </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement