使用XSLT将时间戳转换为日期

使用XSLT将时间戳转换为日期,xslt,date,timestamp,Xslt,Date,Timestamp,我有这样的节点: <item id="37" publish_time="1293829200"> 如何将@publish\u time转换为dd.mm.yyyy这样的日期 我正在使用libxslt,这里是我编写的一个模板,用于将秒转换为更可读的格式。您可以扩展它以满足您的需要: <xsl:template name="convertSecsToTimeStamp"> <xsl:param name="seconds"/>

我有这样的节点:

<item id="37" publish_time="1293829200">
如何将@publish\u time转换为dd.mm.yyyy这样的日期


我正在使用libxslt,这里是我编写的一个模板,用于将秒转换为更可读的格式。您可以扩展它以满足您的需要:

<xsl:template name="convertSecsToTimeStamp">
            <xsl:param name="seconds"/> 
            <xsl:variable name="hours" select="floor($seconds div (60 * 60))"/>
            <xsl:variable name="divisor_for_minutes" select="$seconds mod (60 * 60)"/>
            <xsl:variable name="minutes" select="floor($divisor_for_minutes div 60)"/>
            <xsl:variable name="divisor_for_seconds" select="$divisor_for_minutes mod 60"/>
            <xsl:variable name="secs" select="ceiling($divisor_for_seconds)"/>
            <xsl:choose>
                <xsl:when test="$hours &lt; 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$hours"/><xsl:text>hh</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$hours"/><xsl:text>hh</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
                <xsl:when test="$minutes &lt; 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$minutes"/><xsl:text>mm</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$minutes"/><xsl:text>mm</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
                <xsl:when test="$secs &lt; 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$secs"/><xsl:text>ss</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$secs"/><xsl:text>ss</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>

下面是我编写的一个模板,用于将秒转换为更可读的格式。您可以扩展它以满足您的需要:

<xsl:template name="convertSecsToTimeStamp">
            <xsl:param name="seconds"/> 
            <xsl:variable name="hours" select="floor($seconds div (60 * 60))"/>
            <xsl:variable name="divisor_for_minutes" select="$seconds mod (60 * 60)"/>
            <xsl:variable name="minutes" select="floor($divisor_for_minutes div 60)"/>
            <xsl:variable name="divisor_for_seconds" select="$divisor_for_minutes mod 60"/>
            <xsl:variable name="secs" select="ceiling($divisor_for_seconds)"/>
            <xsl:choose>
                <xsl:when test="$hours &lt; 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$hours"/><xsl:text>hh</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$hours"/><xsl:text>hh</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
                <xsl:when test="$minutes &lt; 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$minutes"/><xsl:text>mm</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$minutes"/><xsl:text>mm</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
                <xsl:when test="$secs &lt; 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$secs"/><xsl:text>ss</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$secs"/><xsl:text>ss</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
可能的重复可能的重复